public class FlipFlop<T> extends Object implements org.mockito.stubbing.Answer<T>
Although this class is public, that is really so that more advanced consumers may override
isFlipped() to rely on some condition other than an explicit call to flip()
to change the state. Most test authors should be able to stick with the factory method
MoreAnswers.flipFlop(Answer, Answer).
| Modifier | Constructor and Description |
|---|---|
protected |
FlipFlop(org.mockito.stubbing.Answer<?> answer0,
org.mockito.stubbing.Answer<?> answer1)
Creates a flip-flop that will switch back and forth between
answer0 and answer1. |
| Modifier and Type | Method and Description |
|---|---|
T |
answer(org.mockito.invocation.InvocationOnMock invocation) |
boolean |
flip()
Flips between
answer0 and answer1. |
boolean |
isFlipped()
Returns
true if currently flipped (using answer1); false if still using answer0. |
String |
toString() |
protected FlipFlop(org.mockito.stubbing.Answer<?> answer0,
org.mockito.stubbing.Answer<?> answer1)
answer0 and answer1.answer0 - the initial answer to giveanswer1 - the answer to switch to when flippedpublic boolean isFlipped()
true if currently flipped (using answer1); false if still using answer0.
If you wish to use something other than explicit calls to flip() to control the switching behaviour,
then you can override this method to check whatever that is.
true if (using answer1; false if using answer0.public boolean flip()
answer0 and answer1.
Calling this again will switch back. Of course, if you override isFlipped() to check something else
instead, then this method probably won't do anything useful for you anymore.
isFlipped() (reporting the new state)Copyright © 2017 Atlassian. All rights reserved.