...
The Unit Test
Code Block | ||
---|---|---|
| ||
[Test] @Test public void load_all_of_file_using_delegate_with_mock() { // arrange stringString fileToLoad = "c:/tmp/KeyboardHandler.java.txt"; FileLoader cut = new FileLoader( fileToLoad ); // setup ur canned data, these will represent the lines List<string>in the file ArrayList<String> pretendFileContent = new ArrayList<>(); pretendFileContent.Addadd("Hello"); pretendFileContent.Addadd("world"); int expectedBytesRead = 10; var// Mock the interface MyFile file = Substitute.For<MyFile>(); mock(MyFile.class); // Setup the expectation when(file.readAllLines(Paths.ReadLinesget(fileToLoad), StandardCharsets.UTF_8)).ReturnsthenReturn(pretendFileContent); // act // act int bytesRead = cut.LoadFileloadFile(fileToLoad, (fname) =-> { IEnumerable<string>List<String> result = file.ReadLines(fileToLoad); readAllLines(Paths.get(fname), StandardCharsets.UTF_8); return result; }); }); // assert Assert.AreEqualassertEquals(expectedBytesRead, bytesRead); } |