简体   繁体   English

在Java中使用通配符作为返回类型

[英]Using wild card as a return type in Java

Mockito.doReturn(true).when(a)
                .isTest(Const.A,
                        Const.B);

In the above code cacheGet method returns a boolean value.(true/false) I want to use a wildcard for that instead true or false. 在上面的代码中,cacheGet方法返回一个布尔值。(true / false)我想为此使用通配符,而不是true或false。

Mockito.doReturn(?).when(a)
                .isTest(Const.A,
                        Const.B);

I want to use the wildcard in place where '?' 我想在“?”的地方使用通配符 is. 是。

How to do it in Java? 用Java怎么做?

try this 尝试这个

String wildcard=""; 字符串wildcard =“”;

if(true){ 如果属实){

wildcard = //wildcard for true wildcard = //通配符为true

} }

else { 其他{

wildcard = //wildcard for false wildcard = //通配符为false

} }

Your code 您的密码

Mockito.doReturn(true).when(cacheAdaptorCore)
                .cacheGet(OMSConst.DEFAULT_TENANCY_CODE,
                        OMSConst.APP_PARAM_DECIMAL_FORMATTER, 
CACHE_NAMES.SYS_PARAMS_CACHE_CORE);

tells Mockito, "Hey Mockito, if, during the following test, somehow the method cacheAdapterCore.cacheGet() is called with the parameters OMSConst ..., do not really call the method, but instead make the code believe that the method returns true ." 告诉Mockito:“嘿Mockito,如果在以下测试中以某种方式使用参数OMSConst调用了cacheAdapterCore.cacheGet()方法,则不要真正调用该方法,而应使代码相信该方法返回true ”。

Now try the same sentence with "... make the code believe that the method returns ???" 现在,用“ ...使代码相信该方法返回???”来尝试相同的句子。

See, it makes no sense. 瞧,这没有任何意义。

If you want to do different tests and for some you want the method to return true, and for others you want it to return false, then you have to write separate test methods and within them, tell Mockito to return true resp. 如果要进行不同的测试,并且对于某些测试,您希望方法返回true,对于其他测试,您想要编写单独的测试方法,并在其中使用,请告诉Mockito返回true。 false. 假。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM