diff --git a/app/src/main/java/hexlet/code/Differ.java b/app/src/main/java/hexlet/code/Differ.java index 44859f2..9bfd5d8 100644 --- a/app/src/main/java/hexlet/code/Differ.java +++ b/app/src/main/java/hexlet/code/Differ.java @@ -92,7 +92,7 @@ public static String generate(String filepath1, String filepath2, String format) return (diff); } - private static String getFormat(String filePath) { + static String getFormat(String filePath) { String fileName = Paths.get(filePath).getFileName().toString(); int dotIndex = fileName.lastIndexOf('.'); if (dotIndex > 0) { @@ -101,4 +101,6 @@ private static String getFormat(String filePath) { throw new IllegalArgumentException("Cannot determine format: " + filePath); } + + } diff --git a/app/src/test/java/hexlet/code/DifferTest.java b/app/src/test/java/hexlet/code/DifferTest.java index 019941c..98d4c20 100644 --- a/app/src/test/java/hexlet/code/DifferTest.java +++ b/app/src/test/java/hexlet/code/DifferTest.java @@ -156,6 +156,21 @@ public void testInvalidJson() throws IOException { ); } + @Test + void testGetFormatMultipleDots() { + String filePath = "config.dev.json"; + String expected = "json"; + String actual = Differ.getFormat(filePath); + assertEquals(expected, actual, "Format should be extracted from last extension"); + } + + @Test + void testGetFormatNoExtension() { + String filePath = "config"; + assertThrows(IllegalArgumentException.class, () -> { + Differ.getFormat(filePath); + }, "Should throw IllegalArgumentException for file without extension"); + } private String normalizeSpaces(String input) { return input.replaceAll("\\s+", " ").trim();