gpt4 book ai didi

java - 将 mockito 与通配符参数一起使用

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:48:27 25 4
gpt4 key购买 nike

我正在尝试将通配符传递给 mockito any() 方法。这是方法

selectGatewayInfoConfig(Operation<?> o)

我想做的是:

when(gatewayConfigSelector.selectGatewayInfoConfig( any(**!!!!!! HERE I NEED THIS WILDCARD !!!!**));
.thenReturn(...something...);

提前致谢。

最佳答案

怎么样?

when(gatewayConfigSelector.selectGatewayInfoConfig( any(Operation.class));
.thenReturn(...something...);

例子:

@Test
public void test() {
Tester mock = Mockito.mock(Tester.class);
Mockito.when(mock.selectGatewayInfoConfig(Mockito.any(Operation.class))).thenReturn("blah");

System.out.println(mock.selectGatewayInfoConfig(null));
}


class Operation<T> {

}

class Tester {

public String selectGatewayInfoConfig(Operation<?> o) {
return "hi";
}
}

关于java - 将 mockito 与通配符参数一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27018486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com