Merge pull request #9773 from eugenp/BAEL-16668-v2

Bael 16668 v2
This commit is contained in:
Loredana Crusoveanu 2020-08-13 17:13:32 +03:00 committed by GitHub
commit db4c926b1a
3 changed files with 2 additions and 48 deletions

View File

@ -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 Mockitos AdditionalAnswers](https://www.baeldung.com/mockito-additionalanswers)
- [Introduction to Mockitos AdditionalAnswers](https://www.baeldung.com/mockito-additionalanswers)
- [Mockito Using Spies](https://www.baeldung.com/mockito-spy)

View File

@ -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)

View File

@ -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);