Browse Source

poprawiona klasa oraz testy

Adam Matuszewski 1 năm trước cách đây
mục cha
commit
758dc94c85

+ 5 - 0
KonwersjaLiter2/src/main/java/pl/dmcs/DirConverter.java

@@ -0,0 +1,5 @@
+package pl.dmcs;
+
+public class DirConverter {
+
+}

+ 1 - 1
KonwersjaLiter2/src/main/java/pl/dmcs/FileConverter.java

@@ -13,7 +13,7 @@ public class FileConverter {
 
     public void convertToUpperCase(String filePath) throws IOException {
         Path originalPath = Paths.get(filePath);
-        Path tempFilePath = Paths.get(filePath + ".tmp");
+        Path tempFilePath = Paths.get("target/test-classes/file.tmp");
 
         try (BufferedReader reader = new BufferedReader(new FileReader(originalPath.toFile()));
              BufferedWriter writer = new BufferedWriter(new FileWriter(tempFilePath.toFile()))) {

+ 20 - 28
KonwersjaLiter2/src/test/java/pl/dmcs/FileConverterTest.java

@@ -6,8 +6,6 @@ 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 {
 
@@ -37,45 +35,28 @@ public class FileConverterTest {
         deleteFile(filePath);
     }
 
-    @Test
-    void testConvertToUpperCase() throws IOException {
-        convertFileAndAssert(
-                Paths.get("src/main/resources/oneFile.txt"),
-                "test\nprzykladowy tekst malymi literami\n12345\nabcdef\n",
-                "TEST\nPRZYKLADOWY TEKST MALYMI LITERAMI\n12345\nABCDEF\n"
-        );
-    }
-
     @Test
     void testConvertEmpty() throws IOException {
         convertFileAndAssert(
-                Paths.get("src/main/resources/empty.txt"),
+                Paths.get("target/test-classes/empty.txt"),
                 "",
                 ""
         );
     }
 
     @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")
+    void testConvertSimpleFileToUpperCase() throws IOException {
+        convertFileAndAssert(
+                Paths.get("target/test-classes/testFile1.txt"),
+                "to jest test\n",
+                "TO JEST TEST\n"
         );
-
-        for (Path filePath : testFiles) {
-            convertFileAndAssert(
-                    filePath,
-                    "To plik testowy",
-                    "TO PLIK TESTOWY\n"
-            );
-        }
     }
 
     @Test
     void testConvertDigitsOnly() throws IOException {
         convertFileAndAssert(
-                Paths.get("src/main/resources/digits.txt"),
+                Paths.get("target/test-classes/digits.txt"),
                 "1234567890\n0987654321\n",
                 "1234567890\n0987654321\n"
         );
@@ -84,15 +65,26 @@ public class FileConverterTest {
     @Test
     void testConvertSpecialCharacters() throws IOException {
         convertFileAndAssert(
-                Paths.get("src/main/resources/specialChars.txt"),
+                Paths.get("target/test-classes/specialChars.txt"),
                 "@#$%^&*()_+[]{}|;:',.<>/?\n-=~`\n",
                 "@#$%^&*()_+[]{}|;:',.<>/?\n-=~`\n"
         );
     }
 
+
+    @Test
+    void testConvertToUpperCase() throws IOException {
+        convertFileAndAssert(
+                Paths.get("target/test-classes/oneFile.txt"),
+                "test\nprzykladowy tekst malymi literami\n12345\nabcdef\n$@#\n",
+                "TEST\nPRZYKLADOWY TEKST MALYMI LITERAMI\n12345\nABCDEF\n$@#\n"
+        );
+    }
+
+
     @Test
     void testConvertNonExistentFile() {
-        Path nonExistentFilePath = Paths.get("src/main/resources/nonExistentFile.txt");
+        Path nonExistentFilePath = Paths.get("target/test-classes/nonExistentFile.txt");
 
         FileConverter converter = new FileConverter();