Просмотр исходного кода

stworzono test dla wielu plików jednocześnie

Adam Matuszewski 1 год назад
Родитель
Сommit
472f287c12

+ 0 - 0
KonwersjaLiter2/src/main/resources/file1


+ 29 - 2
KonwersjaLiter2/src/test/java/pl/dmcs/FileConverterTest.java

@@ -5,6 +5,8 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
 
 public class FileConverterTest {
 
@@ -34,7 +36,7 @@ public class FileConverterTest {
     @Test
     void testConvertEmpty() throws IOException{
         Path emptyFilePath = Paths.get("src/main/resources/empty.txt");
-        //Files.createFile(emptyFilePath); // twrorzy plik
+        Files.createFile(emptyFilePath); // twrorzy plik
 
         FileConverter converter = new FileConverter();
         converter.convertToUpperCase(emptyFilePath.toString());
@@ -43,13 +45,38 @@ public class FileConverterTest {
 
         assertEquals("",actualContent);
 
-        //Files.deleteIfExists(emptyFilePath); // usuwa plik
+        Files.deleteIfExists(emptyFilePath); // usuwa plik
 
     }
 
+    // Kilka plików z jednakową zawartością
+    @Test
+    void testConvertManyFilesToUpperCase() throws IOException {
+        List<Path> testFiles = Arrays.asList(
+                Paths.get("src/main/resources/testFile1.txt"),
+                Paths.get("src/main/resources/testFile2.txt"),
+                Paths.get("src/main/resources/testFile3.txt")
+        );
+
+        for (Path filePath : testFiles) {
+            Files.writeString(filePath, "To plik testowy"); //Pamietać
+        }
+
+        FileConverter converter = new FileConverter();
 
+        for (Path filePath : testFiles) {
+            converter.convertToUpperCase(filePath.toString());
 
+            String actualContent = Files.readString(filePath);
+            actualContent = actualContent.replace("\r\n", "\n");
+            String expectedContent = "TO PLIK TESTOWY\n";
 
+            assertEquals(expectedContent, actualContent);
+
+            Files.deleteIfExists(filePath);
+        }
+
+    }