/
TDD FileLoader v1.4.
TDD FileLoader v1.4.
Using mocking in the test
The Unit Test
@Test
public void load_all_of_file_using_mock()
{
// arrange
String fileToLoad = "c:/tmp/KeyboardHandler.java.txt";
FileLoader cut = new FileLoader( fileToLoad );
// setup ur canned data, these will represent the lines in the file
ArrayList<String> pretendFileContent = new ArrayList<>();
pretendFileContent.add("Hello");
pretendFileContent.add("world");
int expectedBytesRead = 10;
// Mock the interface
MyFile file = mock(MyFile.class);
// Setup the expectation
when(file.readAllLines(Paths.get(fileToLoad), StandardCharsets.UTF_8)).thenReturn(pretendFileContent);
// act
int bytesRead = cut.loadFile((fname) ->
{
List<String> result = file.readAllLines(Paths.get(fname), StandardCharsets.UTF_8);
return result;
});
// assert
assertEquals(expectedBytesRead, bytesRead);
}
, multiple selections available,
Related content
TDD FileLoader v1.2.
TDD FileLoader v1.2.
More like this
TDD FileLoader v1.3.
TDD FileLoader v1.3.
More like this
TDD FileLoader v1.0.
TDD FileLoader v1.0.
More like this
QL-4) Using TDD to design production code.
QL-4) Using TDD to design production code.
More like this
QLC-3) Writing Results to a File.
QLC-3) Writing Results to a File.
Read with this
Full complete versions of the code
Full complete versions of the code
More like this