package pl.dmcs; import org.testng.annotations.Test; import static org.junit.jupiter.api.Assertions.*; 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 { @Test void testConvertToUpperCase() throws IOException { Path filePath = Paths.get("src/main/resources/test.txt"); String originalContent = Files.readString(filePath); String expectedContent ="TEST\n" + "PRZYKLADOWY TEKST MALYMI LITERAMI\n" + "12345\n" + "ABCDEF\n"; FileConverter converter = new FileConverter(); converter.convertToUpperCase(filePath.toString()); String actualContent = Files.readString(filePath); expectedContent = expectedContent.replace("\r\n", "\n"); actualContent = actualContent.replace("\r\n", "\n"); assertEquals(expectedContent, actualContent); // Files.writeString(filePath, originalContent); } // test na pusty plik @Test void testConvertEmpty() throws IOException{ Path emptyFilePath = Paths.get("src/main/resources/empty.txt"); Files.createFile(emptyFilePath); // twrorzy plik FileConverter converter = new FileConverter(); converter.convertToUpperCase(emptyFilePath.toString()); String actualContent = Files.readString(emptyFilePath); assertEquals("",actualContent); Files.deleteIfExists(emptyFilePath); // usuwa plik } // Kilka plików z jednakową zawartością @Test void testConvertManyFilesToUpperCase() throws IOException { List 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); } } }