Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
1e9b741c4f
|
@ -23,7 +23,6 @@ import java.util.Scanner;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class JavaReadFromFileTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -19,14 +19,22 @@ import org.mockito.Spy;
|
|||
//@RunWith(MockitoJUnitRunner.class)
|
||||
public class MockitoAnnotationTest {
|
||||
|
||||
@Mock
|
||||
private List<String> mockedList;
|
||||
|
||||
@Spy
|
||||
List<String> spiedList = new ArrayList<String>();
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
// tests
|
||||
|
||||
@Test
|
||||
public void whenNotUseMockAnnotation_thenCorrect() {
|
||||
final List mockList = Mockito.mock(List.class);
|
||||
final List<String> 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<String> 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<String> spiedList = new ArrayList<String>();
|
||||
|
||||
@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<String> mockList = Mockito.mock(List.class);
|
||||
final ArgumentCaptor<String> arg = ArgumentCaptor.forClass(String.class);
|
||||
mockList.add("one");
|
||||
Mockito.verify(mockList).add(arg.capture());
|
||||
|
|
|
@ -14,8 +14,11 @@ import org.mockito.runners.MockitoJUnitRunner;
|
|||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MockitoSpyTest {
|
||||
|
||||
@Spy
|
||||
private List<String> aSpyList = new ArrayList<String>();
|
||||
|
||||
@Test
|
||||
public void whenSpyOnList_thenCorrect() {
|
||||
public void whenSpyingOnList_thenCorrect() {
|
||||
final List<String> list = new ArrayList<String>();
|
||||
final List<String> spyList = Mockito.spy(list);
|
||||
|
||||
|
@ -28,11 +31,8 @@ public class MockitoSpyTest {
|
|||
assertEquals(2, spyList.size());
|
||||
}
|
||||
|
||||
@Spy
|
||||
List<String> aSpyList = new ArrayList<String>();
|
||||
|
||||
@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<String> 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<String> spyList = Mockito.spy(new ArrayList<String>());
|
||||
|
||||
spyList.add("one");
|
||||
Mockito.verify(spyList).add("one");
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.baeldung.mockito;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class MyDictionary {
|
||||
Map<String, String> wordMap;
|
||||
|
||||
|
@ -19,4 +18,3 @@ public class MyDictionary {
|
|||
return wordMap.get(word);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue