From b30bd3d27b6fdbcdb01b65ebdb0ea348b93ad480 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sat, 15 Nov 2014 11:26:24 +0200 Subject: [PATCH 1/4] small mockito fixes --- .../java/org/baeldung/mockito/MockitoSpyTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mockito/src/test/java/org/baeldung/mockito/MockitoSpyTest.java b/mockito/src/test/java/org/baeldung/mockito/MockitoSpyTest.java index 9200a95b69..adfd3ed1ae 100644 --- a/mockito/src/test/java/org/baeldung/mockito/MockitoSpyTest.java +++ b/mockito/src/test/java/org/baeldung/mockito/MockitoSpyTest.java @@ -14,8 +14,11 @@ import org.mockito.runners.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class MockitoSpyTest { + @Spy + private List aSpyList = new ArrayList(); + @Test - public void whenSpyOnList_thenCorrect() { + public void whenSpyingOnList_thenCorrect() { final List list = new ArrayList(); final List spyList = Mockito.spy(list); @@ -28,11 +31,8 @@ public class MockitoSpyTest { assertEquals(2, spyList.size()); } - @Spy - List aSpyList = new ArrayList(); - @Test - public void whenUseSpyAnnotation_thenCorrect() { + public void whenUsingTheSpyAnnotation_thenObjectIsSpied() { aSpyList.add("one"); aSpyList.add("two"); @@ -55,7 +55,7 @@ public class MockitoSpyTest { @Test public void whenCreateMock_thenCreated() { - final List mockedList = Mockito.mock(List.class); + final List mockedList = Mockito.mock(ArrayList.class); mockedList.add("one"); Mockito.verify(mockedList).add("one"); @@ -65,7 +65,7 @@ public class MockitoSpyTest { @Test public void whenCreateSpy_thenCreate() { - final List spyList = Mockito.spy(new ArrayList()); + final List spyList = Mockito.spy(new ArrayList()); spyList.add("one"); Mockito.verify(spyList).add("one"); From 7327cdebda2398a43995c52c52dcdc19e20a6e87 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sat, 15 Nov 2014 12:19:31 +0200 Subject: [PATCH 2/4] small changes for test naming --- .../mockito/MockitoAnnotationTest.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mockito/src/test/java/org/baeldung/mockito/MockitoAnnotationTest.java b/mockito/src/test/java/org/baeldung/mockito/MockitoAnnotationTest.java index 8ea46ea0f7..3acc2c937b 100644 --- a/mockito/src/test/java/org/baeldung/mockito/MockitoAnnotationTest.java +++ b/mockito/src/test/java/org/baeldung/mockito/MockitoAnnotationTest.java @@ -19,14 +19,22 @@ import org.mockito.Spy; //@RunWith(MockitoJUnitRunner.class) public class MockitoAnnotationTest { + @Mock + private List mockedList; + + @Spy + List spiedList = new ArrayList(); + @Before public void init() { MockitoAnnotations.initMocks(this); } + // tests + @Test public void whenNotUseMockAnnotation_thenCorrect() { - final List mockList = Mockito.mock(List.class); + final List mockList = Mockito.mock(List.class); mockList.add("one"); Mockito.verify(mockList).add("one"); assertEquals(0, mockList.size()); @@ -35,11 +43,8 @@ public class MockitoAnnotationTest { assertEquals(100, mockList.size()); } - @Mock - List mockedList; - @Test - public void whenUseMockAnnotation_thenTheSame() { + public void whenUseMockAnnotation_thenMockIsInjected() { mockedList.add("one"); Mockito.verify(mockedList).add("one"); assertEquals(0, mockedList.size()); @@ -63,11 +68,8 @@ public class MockitoAnnotationTest { assertEquals(100, spyList.size()); } - @Spy - List spiedList = new ArrayList(); - @Test - public void whenUseSpyAnnotation_thenTheSame() { + public void whenUseSpyAnnotation_thenSpyIsInjectedCorrectly() { spiedList.add("one"); spiedList.add("two"); @@ -82,7 +84,7 @@ public class MockitoAnnotationTest { @Test public void whenNotUseCaptorAnnotation_thenCorrect() { - final List mockList = Mockito.mock(List.class); + final List mockList = Mockito.mock(List.class); final ArgumentCaptor arg = ArgumentCaptor.forClass(String.class); mockList.add("one"); Mockito.verify(mockList).add(arg.capture()); From d5f3c84444f973f47d562f7ad3012b34effb02b7 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sat, 15 Nov 2014 15:39:28 +0200 Subject: [PATCH 3/4] minor formatting cleanup --- .../test/java/org/baeldung/java/io/JavaReadFromFileTest.java | 1 - mockito/src/test/java/org/baeldung/mockito/MyDictionary.java | 2 -- 2 files changed, 3 deletions(-) diff --git a/core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileTest.java b/core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileTest.java index 0363602316..e679b82d3f 100644 --- a/core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileTest.java +++ b/core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileTest.java @@ -23,7 +23,6 @@ import java.util.Scanner; import org.junit.Test; - public class JavaReadFromFileTest { @Test diff --git a/mockito/src/test/java/org/baeldung/mockito/MyDictionary.java b/mockito/src/test/java/org/baeldung/mockito/MyDictionary.java index 1d18c88372..3fb2c30646 100644 --- a/mockito/src/test/java/org/baeldung/mockito/MyDictionary.java +++ b/mockito/src/test/java/org/baeldung/mockito/MyDictionary.java @@ -3,7 +3,6 @@ package org.baeldung.mockito; import java.util.HashMap; import java.util.Map; - public class MyDictionary { Map wordMap; @@ -19,4 +18,3 @@ public class MyDictionary { return wordMap.get(word); } } - From 92def6eeae2c728d57ac75998952b14044c3ab02 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 16 Nov 2014 01:07:30 +0200 Subject: [PATCH 4/4] minor naming change --- .../src/test/java/org/baeldung/java/io/JavaScannerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java/src/test/java/org/baeldung/java/io/JavaScannerTest.java b/core-java/src/test/java/org/baeldung/java/io/JavaScannerTest.java index 697ea912ec..61f0f52316 100644 --- a/core-java/src/test/java/org/baeldung/java/io/JavaScannerTest.java +++ b/core-java/src/test/java/org/baeldung/java/io/JavaScannerTest.java @@ -73,7 +73,7 @@ public class JavaScannerTest { } @Test - public void whenReadInputFromConsole_thenCorrect() { + public void whenReadingInputFromConsole_thenCorrect() { final String input = "Hello"; final InputStream stdin = System.in; System.setIn(new ByteArrayInputStream(input.getBytes()));