|
|
@@ -12,7 +12,7 @@ import java.nio.file.Paths;
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
|
|
-public class DirConverterTest {
|
|
|
+public class DirConverterStateTest {
|
|
|
private static final String TEST_DIR = "target/test-classes/";
|
|
|
private static final String FILE_EXTENSION = ".txt";
|
|
|
|
|
|
@@ -50,4 +50,43 @@ public class DirConverterTest {
|
|
|
assertFileContent(Paths.get(TEST_DIR, "file3.txt"), "HELLO WORLD 3");
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void testConvertDirEmptyFile() throws IOException {
|
|
|
+ Path emptyFilePath = Paths.get(TEST_DIR, "empty.txt");
|
|
|
+ Files.write(emptyFilePath, new byte[0]);
|
|
|
+
|
|
|
+ DirConverter converter = new DirConverter();
|
|
|
+ converter.convertDir(TEST_DIR, FILE_EXTENSION);
|
|
|
+
|
|
|
+ assertFileContent(emptyFilePath, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testConvertDirNonExistentDirectory() {
|
|
|
+ DirConverter converter = new DirConverter();
|
|
|
+
|
|
|
+ Exception exception = assertThrows(IOException.class, () -> {
|
|
|
+ converter.convertDir("non/existent/directory", FILE_EXTENSION);
|
|
|
+ });
|
|
|
+
|
|
|
+ String expectedMessage = "non/existent/directory".replace("/", File.separator);
|
|
|
+ String actualMessage = exception.getMessage();
|
|
|
+
|
|
|
+ assertEquals(expectedMessage, actualMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testConvertDirNonMatchingExtension() throws IOException {
|
|
|
+ Files.write(Paths.get(TEST_DIR, "file1.md"), "markdown content".getBytes());
|
|
|
+
|
|
|
+ DirConverter converter = new DirConverter();
|
|
|
+ converter.convertDir(TEST_DIR, FILE_EXTENSION);
|
|
|
+
|
|
|
+ assertFileContent(Paths.get(TEST_DIR, "file1.txt"), "HELLO WORLD");
|
|
|
+ assertFileContent(Paths.get(TEST_DIR, "file2.txt"), "HELLO WORLD 2");
|
|
|
+ assertFileContent(Paths.get(TEST_DIR, "file3.txt"), "HELLO WORLD 3");
|
|
|
+ assertFileContent(Paths.get(TEST_DIR, "file1.md"), "markdown content");
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|