|
|
@@ -15,6 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
public class DirConverterStateTest {
|
|
|
private static final String TEST_DIR = "target/test-classes/";
|
|
|
private static final String FILE_EXTENSION = ".txt";
|
|
|
+ private DirConverter dirConverter;
|
|
|
|
|
|
@BeforeEach
|
|
|
void setUp() throws IOException {
|
|
|
@@ -32,6 +33,9 @@ public class DirConverterStateTest {
|
|
|
Files.write(Paths.get(TEST_DIR, "file1.txt"), "hello world".getBytes());
|
|
|
Files.write(Paths.get(TEST_DIR, "file2.txt"), "hello world 2".getBytes());
|
|
|
Files.write(Paths.get(TEST_DIR, "file3.txt"), "hello world 3".getBytes());
|
|
|
+
|
|
|
+ FileConverter fileConverter = new FileConverter();
|
|
|
+ dirConverter = new DirConverter(fileConverter);
|
|
|
}
|
|
|
|
|
|
private void assertFileContent(Path filePath, String expectedContent) throws IOException {
|
|
|
@@ -42,8 +46,7 @@ public class DirConverterStateTest {
|
|
|
|
|
|
@Test
|
|
|
void testConvertDir() throws IOException {
|
|
|
- DirConverter converter = new DirConverter();
|
|
|
- converter.convertDir(TEST_DIR, FILE_EXTENSION);
|
|
|
+ dirConverter.convertDir(TEST_DIR, FILE_EXTENSION);
|
|
|
|
|
|
assertFileContent(Paths.get(TEST_DIR, "file1.txt"), "HELLO WORLD");
|
|
|
assertFileContent(Paths.get(TEST_DIR, "file2.txt"), "HELLO WORLD 2");
|
|
|
@@ -55,18 +58,15 @@ public class DirConverterStateTest {
|
|
|
Path emptyFilePath = Paths.get(TEST_DIR, "empty.txt");
|
|
|
Files.write(emptyFilePath, new byte[0]);
|
|
|
|
|
|
- DirConverter converter = new DirConverter();
|
|
|
- converter.convertDir(TEST_DIR, FILE_EXTENSION);
|
|
|
+ dirConverter.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);
|
|
|
+ dirConverter.convertDir("non/existent/directory", FILE_EXTENSION);
|
|
|
});
|
|
|
|
|
|
String expectedMessage = "non/existent/directory".replace("/", File.separator);
|
|
|
@@ -79,14 +79,11 @@ public class DirConverterStateTest {
|
|
|
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);
|
|
|
+ dirConverter.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");
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|