0
我運行我的測試時沒有@RunWith
和initMocks()
。它不應該不工作?Mockito Mock如何在我的測試中工作沒有註釋
public class MultiFilesIteratorInMemoryTest {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void getNextLine() throws Exception {
}
@Test
public void timeFrameIsSplitIntoTwoFilesReturnAllRelevantRecords() throws Exception {
IRandomAccess randomAccessFile1 = mock(RandomAccessFileWrapper.class);
IRandomAccess randomAccessFile2 = mock(RandomAccessFileWrapper.class);
IFileUtils fileUtils = mock(FileUtils.class);
when(randomAccessFile1.readLine()).thenReturn("first file content").thenReturn(null);
when(randomAccessFile2.readLine()).thenReturn("second file content").thenReturn(null);
when(fileUtils.getCountOfSimilarNamedFilesFromDir(anyString())).thenReturn(2);
IMultiFilesMerger multiFilesMerger = new MultiFilesIteratorInMemory(fileUtils, ImmutableList.of(randomAccessFile1, randomAccessFile2));
String nextLine = multiFilesMerger.getNextLine();
assertThat(nextLine, equalTo("first file content"));
nextLine = multiFilesMerger.getNextLine();
assertThat(nextLine, equalTo("second file content"));
}
}