From 5eefa2c295f7b19bc30efbbc4b4a8464fae43c13 Mon Sep 17 00:00:00 2001 From: VOsadchii <909404@gmail.com> Date: Sat, 27 Sep 2025 16:19:20 +0300 Subject: [PATCH 1/3] add some tests to Differ class --- app/src/test/java/hexlet/code/DifferTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/app/src/test/java/hexlet/code/DifferTest.java b/app/src/test/java/hexlet/code/DifferTest.java index fbec999..fe749c4 100644 --- a/app/src/test/java/hexlet/code/DifferTest.java +++ b/app/src/test/java/hexlet/code/DifferTest.java @@ -1,13 +1,22 @@ package hexlet.code; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class DifferTest { + + @TempDir + Path tempDir; + @Test void testJsonStylishFormat() throws Exception { String filepath1 = "src/test/resources/file1.json"; @@ -120,6 +129,50 @@ void testYamlDefaultFormat() throws Exception { assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); } + @Test + public void testDifferentExtensions() throws IOException { + String filepath1 = "src/test/resources/file1.json"; + String filepath2 = "src/test/resources/file2.yaml"; + + assertThrows(IOException.class, () -> + Differ.generate(filepath1, filepath2) + ); + } + + @Test + public void testInvalidJson() throws IOException { + File file1 = tempDir.resolve("file1.json").toFile(); + File file2 = tempDir.resolve("file2.json").toFile(); + + try (FileWriter writer = new FileWriter(file1)) { + writer.write("{ invalid json }"); + } + try (FileWriter writer = new FileWriter(file2)) { + writer.write("{}"); + } + + assertThrows(Exception.class, () -> + Differ.generate(file1.getAbsolutePath(), file2.getAbsolutePath()) + ); + } + + @Test + public void testInvalidYaml() throws IOException { + File file1 = tempDir.resolve("file1.yaml").toFile(); + File file2 = tempDir.resolve("file2.yaml").toFile(); + + try (FileWriter writer = new FileWriter(file1)) { + writer.write("invalid:\n- yaml\n syntax error"); + } + try (FileWriter writer = new FileWriter(file2)) { + writer.write("valid: yaml"); + } + + assertThrows(Exception.class, () -> + Differ.generate(file1.getAbsolutePath(), file2.getAbsolutePath()) + ); + } + private String normalizeSpaces(String input) { return input.replaceAll("\\s+", " ").trim(); } From df85623af0993c76ea5bc96e2ae7d938e5c0a213 Mon Sep 17 00:00:00 2001 From: VOsadchii <909404@gmail.com> Date: Sat, 27 Sep 2025 16:29:25 +0300 Subject: [PATCH 2/3] fix tests --- app/src/test/java/hexlet/code/DifferTest.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/app/src/test/java/hexlet/code/DifferTest.java b/app/src/test/java/hexlet/code/DifferTest.java index fe749c4..a64153c 100644 --- a/app/src/test/java/hexlet/code/DifferTest.java +++ b/app/src/test/java/hexlet/code/DifferTest.java @@ -156,22 +156,6 @@ public void testInvalidJson() throws IOException { ); } - @Test - public void testInvalidYaml() throws IOException { - File file1 = tempDir.resolve("file1.yaml").toFile(); - File file2 = tempDir.resolve("file2.yaml").toFile(); - - try (FileWriter writer = new FileWriter(file1)) { - writer.write("invalid:\n- yaml\n syntax error"); - } - try (FileWriter writer = new FileWriter(file2)) { - writer.write("valid: yaml"); - } - - assertThrows(Exception.class, () -> - Differ.generate(file1.getAbsolutePath(), file2.getAbsolutePath()) - ); - } private String normalizeSpaces(String input) { return input.replaceAll("\\s+", " ").trim(); From ac5f1a789b5c90f851c15d40172a734469a088c0 Mon Sep 17 00:00:00 2001 From: VOsadchii <909404@gmail.com> Date: Sat, 27 Sep 2025 16:34:31 +0300 Subject: [PATCH 3/3] test fix --- app/src/test/java/hexlet/code/DifferTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/java/hexlet/code/DifferTest.java b/app/src/test/java/hexlet/code/DifferTest.java index a64153c..019941c 100644 --- a/app/src/test/java/hexlet/code/DifferTest.java +++ b/app/src/test/java/hexlet/code/DifferTest.java @@ -15,7 +15,7 @@ public class DifferTest { @TempDir - Path tempDir; + private Path tempDir; @Test void testJsonStylishFormat() throws Exception {