commit
db4c926b1a
|
@ -5,4 +5,5 @@
|
|||
- [Mockito Strict Stubbing and The UnnecessaryStubbingException](https://www.baeldung.com/mockito-unnecessary-stubbing-exception)
|
||||
- [Mockito and Fluent APIs](https://www.baeldung.com/mockito-fluent-apis)
|
||||
- [Mocking the ObjectMapper readValue() Method](https://www.baeldung.com/mockito-mock-jackson-read-value)
|
||||
- [Introduction to Mockito’s AdditionalAnswers](https://www.baeldung.com/mockito-additionalanswers)
|
||||
- [Introduction to Mockito’s AdditionalAnswers](https://www.baeldung.com/mockito-additionalanswers)
|
||||
- [Mockito – Using Spies](https://www.baeldung.com/mockito-spy)
|
||||
|
|
|
@ -12,5 +12,4 @@
|
|||
- [Mocking Void Methods with Mockito](https://www.baeldung.com/mockito-void-methods)
|
||||
- [Mock Final Classes and Methods with Mockito](https://www.baeldung.com/mockito-final)
|
||||
- [Testing Callbacks with Mockito](https://www.baeldung.com/mockito-callbacks)
|
||||
- [Mockito – Using Spies](https://www.baeldung.com/mockito-spy)
|
||||
- [Quick Guide to BDDMockito](https://www.baeldung.com/bdd-mockito)
|
||||
|
|
|
@ -76,52 +76,6 @@ public class MockitoAnnotationUnitTest {
|
|||
assertEquals(100, spiedList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSpyingOnList_thenCorrect() {
|
||||
List<String> list = new ArrayList<String>();
|
||||
List<String> spyList = Mockito.spy(list);
|
||||
|
||||
spyList.add("one");
|
||||
spyList.add("two");
|
||||
|
||||
Mockito.verify(spyList).add("one");
|
||||
Mockito.verify(spyList).add("two");
|
||||
|
||||
assertEquals(2, spyList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingTheSpyAnnotation_thenObjectIsSpied() {
|
||||
spiedList.add("one");
|
||||
spiedList.add("two");
|
||||
|
||||
Mockito.verify(spiedList).add("one");
|
||||
Mockito.verify(spiedList).add("two");
|
||||
|
||||
assertEquals(2, spiedList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStubASpy_thenStubbed() {
|
||||
List<String> list = new ArrayList<String>();
|
||||
List<String> spyList = Mockito.spy(list);
|
||||
|
||||
assertEquals(0, spyList.size());
|
||||
|
||||
Mockito.doReturn(100).when(spyList).size();
|
||||
assertEquals(100, spyList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateSpy_thenCreate() {
|
||||
List<String> spyList = Mockito.spy(new ArrayList<>());
|
||||
|
||||
spyList.add("one");
|
||||
Mockito.verify(spyList).add("one");
|
||||
|
||||
assertEquals(1, spyList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotUseCaptorAnnotation_thenCorrect() {
|
||||
final List<String> mockList = Mockito.mock(List.class);
|
||||
|
|
Loading…
Reference in New Issue