Quellcode durchsuchen

Kolejny etap refaktoryzaji

Adam Matuszewski vor 1 Jahr
Ursprung
Commit
a4fad5baf9
1 geänderte Dateien mit 31 neuen und 41 gelöschten Zeilen
  1. 31 41
      KonwersjaLiter2/src/test/java/pl/dmcs/FileConverterTest.java

+ 31 - 41
KonwersjaLiter2/src/test/java/pl/dmcs/FileConverterTest.java

@@ -29,29 +29,30 @@ public class FileConverterTest {
         assertEquals(expectedContent, actualContent);
     }
 
-    @Test
-    void testConvertToUpperCase() throws IOException {
-        Path filePath = Paths.get("src/main/resources/oneFile.txt");
-        createFileWithContent(filePath, "test\nprzykladowy tekst malymi literami\n12345\nabcdef\n");
-        String expectedContent = "TEST\nPRZYKLADOWY TEKST MALYMI LITERAMI\n12345\nABCDEF\n";
-
+    private void convertFileAndAssert(Path filePath, String content, String expectedContent) throws IOException {
+        createFileWithContent(filePath, content);
         FileConverter converter = new FileConverter();
         converter.convertToUpperCase(filePath.toString());
-
         assertFileContent(filePath, expectedContent);
         deleteFile(filePath);
     }
 
     @Test
-    void testConvertEmpty() throws IOException {
-        Path emptyFilePath = Paths.get("src/main/resources/empty.txt");
-        createFileWithContent(emptyFilePath, "");
-
-        FileConverter converter = new FileConverter();
-        converter.convertToUpperCase(emptyFilePath.toString());
+    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"
+        );
+    }
 
-        assertFileContent(emptyFilePath, "");
-        deleteFile(emptyFilePath);
+    @Test
+    void testConvertEmpty() throws IOException {
+        convertFileAndAssert(
+                Paths.get("src/main/resources/empty.txt"),
+                "",
+                ""
+        );
     }
 
     @Test
@@ -63,40 +64,30 @@ public class FileConverterTest {
         );
 
         for (Path filePath : testFiles) {
-            createFileWithContent(filePath, "To plik testowy");
-        }
-
-        FileConverter converter = new FileConverter();
-
-        for (Path filePath : testFiles) {
-            converter.convertToUpperCase(filePath.toString());
-            assertFileContent(filePath, "TO PLIK TESTOWY\n");
-            deleteFile(filePath);
+            convertFileAndAssert(
+                    filePath,
+                    "To plik testowy",
+                    "TO PLIK TESTOWY\n"
+            );
         }
     }
 
     @Test
     void testConvertDigitsOnly() throws IOException {
-        Path digitsFilePath = Paths.get("src/main/resources/digits.txt");
-        createFileWithContent(digitsFilePath, "1234567890\n0987654321\n");
-
-        FileConverter converter = new FileConverter();
-        converter.convertToUpperCase(digitsFilePath.toString());
-
-        assertFileContent(digitsFilePath, "1234567890\n0987654321\n");
-        deleteFile(digitsFilePath);
+        convertFileAndAssert(
+                Paths.get("src/main/resources/digits.txt"),
+                "1234567890\n0987654321\n",
+                "1234567890\n0987654321\n"
+        );
     }
 
     @Test
     void testConvertSpecialCharacters() throws IOException {
-        Path specialCharactersFilePath = Paths.get("src/main/resources/specialChars.txt");
-        createFileWithContent(specialCharactersFilePath, "@#$%^&*()_+[]{}|;:',.<>/?\n-=~`\n");
-
-        FileConverter converter = new FileConverter();
-        converter.convertToUpperCase(specialCharactersFilePath.toString());
-
-        assertFileContent(specialCharactersFilePath, "@#$%^&*()_+[]{}|;:',.<>/?\n-=~`\n");
-        deleteFile(specialCharactersFilePath);
+        convertFileAndAssert(
+                Paths.get("src/main/resources/specialChars.txt"),
+                "@#$%^&*()_+[]{}|;:',.<>/?\n-=~`\n",
+                "@#$%^&*()_+[]{}|;:',.<>/?\n-=~`\n"
+        );
     }
 
     @Test
@@ -114,5 +105,4 @@ public class FileConverterTest {
 
         assertTrue(actualMessage.contains(expectedMessage));
     }
-
 }