3 回答
TA贡献1820条经验 获得超10个赞
您可以Mockito.doAnswer( answer )更好地控制创建的String
所以像:
List<String> blacklist = Arrays.asList("aaaa","bbbb");
Mockito.doAnswer((i)-> {
String x=RandomStringUtils.random(4);
while(blacklist.contains(x)){
x=RandomStringUtils.random(4);
}
return x;
}).when(helperObject).obtainAsString();
TA贡献1847条经验 获得超11个赞
虽然我不知道如何做“除某些字符串外的任何字符串”,但这解决了我的问题:
@Test
public void testMethod_notThisString(){
whenever(helperObject.obtainAString()).thenReturn(HelperObject.CONSTANT1, HelperObject.CONSTANT2, HelperObject.CONSTANT3);
instantiatedClass.method()
verify(someOtherObjectWithAMethod).thisMethod("differentarg");
}
这遵循Overriding Stubbing的逻辑。
添加回答
举报