|
this.sut.voidMethod();
verify(this.doc).voidMethod();
|
|
this.sut.voidMethodWithParemeters(1, new Other(0));
this.sut.voidMethod();
verify(this.doc).voidMethod();
|
|
this.sut.voidMethodWithParemeters(1, new Other(0));
this.sut.voidMethod();
verify(this.doc).voidMethod();
verify(this.doc).voidMethodWithParemeters(1, new Other(0));
|
|
this.sut.voidMethodWithParemeters(1, new Other(0));
this.sut.voidMethod();
this.sut.voidMethodWithParemeters(0, null);
this.sut.voidMethod();
verify(this.doc).voidMethodWithParemeters(0, null);
verify(this.doc, times(2)).voidMethod();
verify(this.doc).voidMethodWithParemeters(1, new Other(0));
|
|
this.sut.voidMethod();
verify(this.doc, times(1)).voidMethod();
verify(this.doc, atLeastOnce()).voidMethod();
verify(this.doc, atLeast(1)).voidMethod();
verify(this.doc, atMost(1)).voidMethod();
verify(this.doc, never()).voidMethodWithParemeters(0, null);
|
|
verifyZeroInteractions(this.doc);
|
this.sut.voidMethod();
verify(this.doc).voidMethod();
verifyNoMoreInteractions(this.doc);
|
-
Se permiten matchers de Hamfcrest: anyInt(n), anyBoolean(b), …, any(o), any(), …anyList(), …
|
this.sut.voidMethodWithParemeters(0, null);
this.sut.voidMethodWithParemeters(1, new Other(0));
verify(this.doc).voidMethodWithParemeters(1, new Other(0));
verify(this.doc)
.voidMethodWithParemeters(anyInt(), eq(new Other(0)));
verify(this.doc)
.voidMethodWithParemeters(anyInt(), isA(Other.class));
verify(this.doc)
.voidMethodWithParemeters(anyInt(), (Other) isNull());
verify(this.doc)
.voidMethodWithParemeters(eq(0), (Other) isNull());
verify(this.doc)
.voidMethodWithParemeters(intThat(greaterThan(-1)), (Other) isNull());
|
|
this.sut.voidMethodWithParemeters(0, new Other(1));
verify(this.doc)
.voidMethodWithParemeters(anyInt(), argThat(new isValidOther()));
|
class isValidOther implements ArgumentMatcher<Other> {
public boolean matches(Other other) {
return 0 <= other.attribute && other.attribute <= 2;
}
public String toString() {
return "[isValidOther]";
}
}
|
|
ArgumentCaptor<Integer> value = ArgumentCaptor.forClass(Integer.class);
ArgumentCaptor<Other> other = ArgumentCaptor.forClass(Other.class);
this.sut.voidMethod();
this.sut.voidMethodWithParemeters(1, new Other(-1));
verify(this.doc).voidMethod();
verify(this.doc).voidMethodWithParemeters(value.capture(), other.capture());
assertThat(value.getValue(), is(1));
assertThat(other.getValue().attribute, is(-1));
|
|
Other other = new Other(0);
this.sut.voidMethodWithParemeters(1, other);
this.sut.voidMethodWithParemeters(2, other);
this.sut.voidMethodWithParemeters(3, other);
InOrder inOrder = inOrder(this.doc);
inOrder.verify(this.doc).voidMethodWithParemeters(1, other);
inOrder.verify(this.doc).voidMethodWithParemeters(2, other);
inOrder.verify(this.doc).voidMethodWithParemeters(3, other);
|
|
Other other = new Other(0);
DOC doc = spy(DOC.class);
SUT sut = new SUT(doc);
this.sut.voidMethodWithParemeters(1, other);
sut.voidMethodWithParemeters(1, other);
this.sut.voidMethodWithParemeters(2, other);
sut.voidMethodWithParemeters(2, other);
InOrder inOrder = inOrder(this.doc, doc);
inOrder.verify(this.doc).voidMethodWithParemeters(1, other);
inOrder.verify(doc).voidMethodWithParemeters(1, other);
inOrder.verify(this.doc).voidMethodWithParemeters(2, other);
inOrder.verify(doc).voidMethodWithParemeters(2, other);
|
|
this.sut.voidMethod();
verify(this.doc, times(1)
.description("Mensaje")).voidMethod();
verify(this.doc, atLeastOnce()
.description("Mensaje")).voidMethod();
verify(this.doc, atLeast(1)
.description("Mensaje")).voidMethod();
verify(this.doc, atMost(1)
.description("Mensaje")).voidMethod();
verify(this.doc, never()
.description("Mensaje")).voidMethodWithParemeters(0, null);
|
|
this.sut.slowMethod();
verify(this.doc, timeout(1)).slowMethod();
|