|
@@ -0,0 +1,56 @@
|
|
|
|
|
+import org.junit.jupiter.api.AfterEach;
|
|
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
+import pl.weeia.DirConverter;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
|
+
|
|
|
|
|
+public class DirConverterTest {
|
|
|
|
|
+ private final DirConverter dirConverter = new DirConverter();
|
|
|
|
|
+ private Path tempDir;
|
|
|
|
|
+
|
|
|
|
|
+ @BeforeEach
|
|
|
|
|
+ public void setUp() throws IOException {
|
|
|
|
|
+ tempDir = Files.createTempDirectory("testDir");
|
|
|
|
|
+ Files.writeString(Files.createFile(tempDir.resolve("file1.txt")), "abc123");
|
|
|
|
|
+ Files.writeString(Files.createFile(tempDir.resolve("file2.txt")), "xyz789");
|
|
|
|
|
+ Files.createFile(tempDir.resolve("file3.log")); // Plik innego rozszerzenia
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @AfterEach
|
|
|
|
|
+ public void tearDown() throws IOException {
|
|
|
|
|
+ Files.walk(tempDir)
|
|
|
|
|
+ .sorted((a, b) -> b.compareTo(a)) // Usuwanie w odwrotnej kolejności
|
|
|
|
|
+ .forEach(path -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Files.deleteIfExists(path);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ System.err.println("Błąd usuwania pliku: " + path);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void testConvertFilesInDirectoryToUpperCase() throws IOException {
|
|
|
|
|
+ dirConverter.convertFilesInDirectoryToUpperCase(tempDir.toString(), ".txt");
|
|
|
|
|
+
|
|
|
|
|
+ String content1 = Files.readString(tempDir.resolve("file1.txt"));
|
|
|
|
|
+ String content2 = Files.readString(tempDir.resolve("file2.txt"));
|
|
|
|
|
+ String content3 = Files.readString(tempDir.resolve("file3.log"));
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("ABC123", content1);
|
|
|
|
|
+ assertEquals("XYZ789", content2);
|
|
|
|
|
+ assertEquals("file3.log", tempDir.resolve("file3.log").getFileName().toString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void testConvertFilesInNonExistentDirectory() {
|
|
|
|
|
+ assertThrows(IllegalArgumentException.class, () ->
|
|
|
|
|
+ dirConverter.convertFilesInDirectoryToUpperCase("non_existent_dir", ".txt"));
|
|
|
|
|
+ }
|
|
|
|
|
+}
|