| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import org.junit.jupiter.api.Test;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import static org.junit.jupiter.api.Assertions.*;
- import static org.mockito.Mockito.*;
- public class DirConverterTest {
- public static final String path_to_test_files = "H:\\Lucja\\itaz\\8\\konwersja-liter\\";
- private DirConverter dirConverter;
- private FileConverter fileConverter;
- DirConverterTest(){
- fileConverter = mock(FileConverter.class);
- dirConverter = new DirConverter(fileConverter);
- }
- private void basicTest(String dir, String extension, int numOfInvocations) throws IOException {
- dirConverter.convertSpecifiedFiles(path_to_test_files + dir + "\\", extension);
- verify(fileConverter, times(numOfInvocations)).convertFileToUpperCase(anyString());
- reset(fileConverter);
- }
- @Test
- void testFindingFiles() {
- File dirPath = new File("H:\\Lucja\\itaz\\8\\konwersja-liter\\dir\\");
- ArrayList<String> filenames = new ArrayList<>(Arrays.asList("file.txt", "file_special_characters.txt", "file_to_write.txt"));
- assertEquals(filenames, dirConverter.listFileForFolder(dirPath, ".txt"));
- }
- @Test
- void testEmptyDir() throws IOException {
- basicTest("dir_empty", ".txt", 0);
- basicTest("dir_empty", ".java", 0);
- basicTest("dir_empty", ".json", 0);
- }
- @Test
- void testOneJsonFile() throws IOException {
- basicTest("dir", ".json", 1);
- }
- @Test
- void testThreeJavaFiles() throws IOException {
- basicTest("dir", ".java", 2);
- }
- @Test
- void testThreeTxtFiles() throws IOException {
- basicTest("dir", ".txt", 3);
- }
- }
|