|
|
@@ -15,16 +15,54 @@ public class FileConverterTest {
|
|
|
assertEquals(basic,content);
|
|
|
return content;
|
|
|
}
|
|
|
+ private void checkUpperCase (String content) throws IOException {
|
|
|
+ String basic = "ABCDFG";
|
|
|
+ assertEquals(basic,FileConverter.toUpperCase(content));
|
|
|
+ }
|
|
|
+ private void checkIfFileIsUpperCase(String path) throws IOException {
|
|
|
+ File file = new File(path);
|
|
|
+ FileReader fileReader = new FileReader(file);
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(fileReader);
|
|
|
+ int charRead = 0;
|
|
|
+ while ((charRead = bufferedReader.read()) != -1) {
|
|
|
+ char character = (char) charRead;
|
|
|
+ if (Character.isLetter(character))
|
|
|
+ assertTrue(Character.isUpperCase(character));
|
|
|
+ }
|
|
|
+ }
|
|
|
@Test
|
|
|
void testOnlyCharacters() throws IOException {
|
|
|
String content = basicTest("file.txt");
|
|
|
checkUpperCase(content);
|
|
|
}
|
|
|
-
|
|
|
- private void checkUpperCase (String content) throws IOException {
|
|
|
+ @Test
|
|
|
+ void testReadAndConvert() throws IOException {
|
|
|
String basic = "ABCDFG";
|
|
|
- assertEquals(basic,FileConverter.toUpperCase(content));
|
|
|
- }
|
|
|
-
|
|
|
+ String file_name = "file.txt";
|
|
|
+ String path = path_to_test_files + file_name;
|
|
|
+ assertEquals(basic,FileConverter.toUpperCase(FileConverter.readFile(path)));
|
|
|
|
|
|
+ basic = "34A$21B37&#!MALEZNAKI";
|
|
|
+ file_name = "file_special_characters.txt";
|
|
|
+ path = path_to_test_files + file_name;
|
|
|
+ assertEquals(basic,FileConverter.toUpperCase(FileConverter.readFile(path)));
|
|
|
+ }
|
|
|
+ @Test
|
|
|
+ void testFileConverter() throws IOException {
|
|
|
+ String file_name = "file.txt";
|
|
|
+ String path = path_to_test_files + file_name;
|
|
|
+ FileConverter.convertFileToUpperCase(path);
|
|
|
+ checkIfFileIsUpperCase(path);
|
|
|
+ }
|
|
|
+ private static void writeToFile(String filePath, String content) throws IOException {
|
|
|
+ FileWriter writerObj = new FileWriter(filePath, false);
|
|
|
+ writerObj.write(content);
|
|
|
+ writerObj.close();
|
|
|
+ }
|
|
|
+ @AfterAll
|
|
|
+ static void resetTestFiles() throws IOException {
|
|
|
+ writeToFile(path_to_test_files + "file.txt", "abcdfg");
|
|
|
+ writeToFile(path_to_test_files + "file_special_characters.txt", "34a$21b37&#!maleznaki");
|
|
|
+ writeToFile(path_to_test_files + "file_to_write.txt", "");
|
|
|
+ }
|
|
|
}
|