Using wild card as a return type in JavaIs Java “pass-by-reference” or “pass-by-value”?Fastest way to determine if an integer's square root is an integerHow do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I break out of nested loops in Java?How do I check if a file exists in Java?How to mock void methods with MockitoHow do I convert a String to an int in Java?Creating a memory leak with Java
What quests do you need to stop at before you make an enemy of a faction for each faction?
What drugs were used in England during the High Middle Ages?
Sinning and G-d's will, what's wrong with this logic?
How to calculate the power level of a Commander deck?
Are there mathematical concepts that exist in the fourth dimension, but not in the third dimension?
Was Rosie the Riveter sourced from a Michelangelo painting?
Could this estimate of the size and mass of the Chicxulub Impactor be accurate?
How do I write a vertically-stacked definition of a sequence?
What are some countries where you can be imprisoned for reading or owning a Bible?
Why would image resources loaded from different origins triggering HTTP authentication dialogs be harmful?
Why does 8 bit truecolor use only 2 bits for blue?
What are the solutions of this Diophantine equation?
Why did Boris Johnson call for new elections?
extract specific cheracters from each line
Is Sanskrit really the mother of all languages?
French equivalent of "my cup of tea"
"syntax error near unexpected token" after editing .bashrc
Temporarily simulate being offline programmatically
What can we do about our 9 month old putting fingers down his throat?
Remaining in the US beyond VWP admission period
How could a planet have one hemisphere way warmer than the other without the planet being tidally locked?
Pronounceable encrypted text
Looking for a big fantasy novel about scholarly monks that sort of worship math?
Why does the seven segment display have decimal point at the right?
Using wild card as a return type in Java
Is Java “pass-by-reference” or “pass-by-value”?Fastest way to determine if an integer's square root is an integerHow do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I break out of nested loops in Java?How do I check if a file exists in Java?How to mock void methods with MockitoHow do I convert a String to an int in Java?Creating a memory leak with Java
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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.
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 mockito
|
show 5 more comments
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.
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 mockito
2
I don't understand your question. Either you want to return true when that method gets called, or you want to return false. What would you expect Mockito to do, as a result of you specifying the wildcard?
– Dawood ibn Kareem
Mar 28 at 5:04
I'm new to Mocking, but I don't get it. What do you expect to do with this? You're telling Mockito to return...what? --- ha! @DawoodibnKareem had the same idea, so I guess even newbie Mockito guy me kinda gets it. Coolio.
– Steve
Mar 28 at 5:05
...this begs the question though...is there any way to tell Mockito to return something used or obtained elsewhere in the definition of your mock?
– Steve
Mar 28 at 5:07
what do you mean by 'wildcard'? Can you show an example?
– Pavel Smirnov
Mar 28 at 5:43
I want to write a expression valid for both true and false. Some wildcard which can use for either true or false
– Nishara Kavindi
Mar 28 at 5:53
|
show 5 more comments
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.
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 mockito
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.
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 mockito
java mockito
edited Aug 26 at 6:49
Nishara Kavindi
asked Mar 28 at 4:58
Nishara KavindiNishara Kavindi
328 bronze badges
328 bronze badges
2
I don't understand your question. Either you want to return true when that method gets called, or you want to return false. What would you expect Mockito to do, as a result of you specifying the wildcard?
– Dawood ibn Kareem
Mar 28 at 5:04
I'm new to Mocking, but I don't get it. What do you expect to do with this? You're telling Mockito to return...what? --- ha! @DawoodibnKareem had the same idea, so I guess even newbie Mockito guy me kinda gets it. Coolio.
– Steve
Mar 28 at 5:05
...this begs the question though...is there any way to tell Mockito to return something used or obtained elsewhere in the definition of your mock?
– Steve
Mar 28 at 5:07
what do you mean by 'wildcard'? Can you show an example?
– Pavel Smirnov
Mar 28 at 5:43
I want to write a expression valid for both true and false. Some wildcard which can use for either true or false
– Nishara Kavindi
Mar 28 at 5:53
|
show 5 more comments
2
I don't understand your question. Either you want to return true when that method gets called, or you want to return false. What would you expect Mockito to do, as a result of you specifying the wildcard?
– Dawood ibn Kareem
Mar 28 at 5:04
I'm new to Mocking, but I don't get it. What do you expect to do with this? You're telling Mockito to return...what? --- ha! @DawoodibnKareem had the same idea, so I guess even newbie Mockito guy me kinda gets it. Coolio.
– Steve
Mar 28 at 5:05
...this begs the question though...is there any way to tell Mockito to return something used or obtained elsewhere in the definition of your mock?
– Steve
Mar 28 at 5:07
what do you mean by 'wildcard'? Can you show an example?
– Pavel Smirnov
Mar 28 at 5:43
I want to write a expression valid for both true and false. Some wildcard which can use for either true or false
– Nishara Kavindi
Mar 28 at 5:53
2
2
I don't understand your question. Either you want to return true when that method gets called, or you want to return false. What would you expect Mockito to do, as a result of you specifying the wildcard?
– Dawood ibn Kareem
Mar 28 at 5:04
I don't understand your question. Either you want to return true when that method gets called, or you want to return false. What would you expect Mockito to do, as a result of you specifying the wildcard?
– Dawood ibn Kareem
Mar 28 at 5:04
I'm new to Mocking, but I don't get it. What do you expect to do with this? You're telling Mockito to return...what? --- ha! @DawoodibnKareem had the same idea, so I guess even newbie Mockito guy me kinda gets it. Coolio.
– Steve
Mar 28 at 5:05
I'm new to Mocking, but I don't get it. What do you expect to do with this? You're telling Mockito to return...what? --- ha! @DawoodibnKareem had the same idea, so I guess even newbie Mockito guy me kinda gets it. Coolio.
– Steve
Mar 28 at 5:05
...this begs the question though...is there any way to tell Mockito to return something used or obtained elsewhere in the definition of your mock?
– Steve
Mar 28 at 5:07
...this begs the question though...is there any way to tell Mockito to return something used or obtained elsewhere in the definition of your mock?
– Steve
Mar 28 at 5:07
what do you mean by 'wildcard'? Can you show an example?
– Pavel Smirnov
Mar 28 at 5:43
what do you mean by 'wildcard'? Can you show an example?
– Pavel Smirnov
Mar 28 at 5:43
I want to write a expression valid for both true and false. Some wildcard which can use for either true or false
– Nishara Kavindi
Mar 28 at 5:53
I want to write a expression valid for both true and false. Some wildcard which can use for either true or false
– Nishara Kavindi
Mar 28 at 5:53
|
show 5 more comments
2 Answers
2
active
oldest
votes
try this
String wildcard="";
if(true)
wildcard = //wildcard for true
else
wildcard = //wildcard for false
add a comment |
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
."
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. false.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390452%2fusing-wild-card-as-a-return-type-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
try this
String wildcard="";
if(true)
wildcard = //wildcard for true
else
wildcard = //wildcard for false
add a comment |
try this
String wildcard="";
if(true)
wildcard = //wildcard for true
else
wildcard = //wildcard for false
add a comment |
try this
String wildcard="";
if(true)
wildcard = //wildcard for true
else
wildcard = //wildcard for false
try this
String wildcard="";
if(true)
wildcard = //wildcard for true
else
wildcard = //wildcard for false
answered Mar 28 at 5:59
Rajeev RanjanRajeev Ranjan
1902 silver badges13 bronze badges
1902 silver badges13 bronze badges
add a comment |
add a comment |
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
."
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. false.
add a comment |
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
."
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. false.
add a comment |
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
."
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. 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
."
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. false.
edited Aug 26 at 6:55
Dino
2,5293 gold badges16 silver badges39 bronze badges
2,5293 gold badges16 silver badges39 bronze badges
answered Mar 28 at 6:16
RidcullyRidcully
19.4k7 gold badges56 silver badges73 bronze badges
19.4k7 gold badges56 silver badges73 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390452%2fusing-wild-card-as-a-return-type-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
I don't understand your question. Either you want to return true when that method gets called, or you want to return false. What would you expect Mockito to do, as a result of you specifying the wildcard?
– Dawood ibn Kareem
Mar 28 at 5:04
I'm new to Mocking, but I don't get it. What do you expect to do with this? You're telling Mockito to return...what? --- ha! @DawoodibnKareem had the same idea, so I guess even newbie Mockito guy me kinda gets it. Coolio.
– Steve
Mar 28 at 5:05
...this begs the question though...is there any way to tell Mockito to return something used or obtained elsewhere in the definition of your mock?
– Steve
Mar 28 at 5:07
what do you mean by 'wildcard'? Can you show an example?
– Pavel Smirnov
Mar 28 at 5:43
I want to write a expression valid for both true and false. Some wildcard which can use for either true or false
– Nishara Kavindi
Mar 28 at 5:53