|
@@ -1,26 +1,53 @@
|
|
|
package pl.dmcs;
|
|
package pl.dmcs;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Files;
|
|
|
|
|
+import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
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 DirConverterTest {
|
|
|
private static final String TEST_DIR = "target/test-classes/";
|
|
private static final String TEST_DIR = "target/test-classes/";
|
|
|
-
|
|
|
|
|
private static final String FILE_EXTENSION = ".txt";
|
|
private static final String FILE_EXTENSION = ".txt";
|
|
|
|
|
|
|
|
@BeforeEach
|
|
@BeforeEach
|
|
|
void setUp() throws IOException {
|
|
void setUp() throws IOException {
|
|
|
- Files.createDirectory(Paths.get(TEST_DIR));
|
|
|
|
|
|
|
+ Files.createDirectories(Paths.get(TEST_DIR));
|
|
|
|
|
+ Files.walk(Paths.get(TEST_DIR))
|
|
|
|
|
+ .filter(Files::isRegularFile)
|
|
|
|
|
+ .forEach(file -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Files.delete(file);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
Files.write(Paths.get(TEST_DIR, "file1.txt"), "hello world".getBytes());
|
|
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, "file2.txt"), "hello world 2".getBytes());
|
|
|
Files.write(Paths.get(TEST_DIR, "file3.txt"), "hello world 3".getBytes());
|
|
Files.write(Paths.get(TEST_DIR, "file3.txt"), "hello world 3".getBytes());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void assertFileContent(Path filePath, String expectedContent) throws IOException {
|
|
|
|
|
+ String actualContent = Files.readString(filePath).replace("\r\n", "\n").trim();
|
|
|
|
|
+ expectedContent = expectedContent.replace("\r\n", "\n").trim();
|
|
|
|
|
+ assertEquals(expectedContent, actualContent);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void testConvertDir() throws IOException {
|
|
|
|
|
+ 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");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|