@Test public void parseTextFileUsingBufferedReader( @Mocked final BufferedReader reader, @Mocked FileReader fileReader) throws Exception { new NonStrictExpectations() { { reader.readLine(); returns("line1", "another,line", null); } }; TextFile textFile = new TextFile("file"); List<String[]> result = textFile.parse(); assertResultFromTextFileParsing(result); new Verifications() { { reader.close(); } }; }
@Test public void parseTextFileUsingInterface(@Mocked final TextReader reader) throws Exception { new NonStrictExpectations() { { reader.readLine(); returns("line1", "another,line", null); } }; TextFile textFile = new TextFile(reader, 100); List<String[]> result = textFile.parse(); assertResultFromTextFileParsing(result); new VerificationsInOrder() { { reader.skip(100); reader.close(); } }; }