diff --git a/README.md b/README.md index 5a2122e..06ded10 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,190 @@ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=valentin-osadchii_java-project-71&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=valentin-osadchii_java-project-71) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=valentin-osadchii_java-project-71&metric=coverage)](https://sonarcloud.io/summary/new_code?id=valentin-osadchii_java-project-71) +## Пример использования + +### Справка + +```bash +$ ./app -h + +Usage: gendiff [-hV] [-f=] +Compares two configuration files and shows a difference. + path to first file + path to second file + -f, --format= output format [default: stylish] + -h, --help Show this help message and exit. + -V, --version Print version information and exit. +``` + +### Сравнение json, вывод в формате по-умолчанию + +```bash +$ ./build/install/app/bin/app examples/file1nested.json examples/file2nested.json + +Reading file 1: examples/file1nested.json +Reading file 2: examples/file2nested.json +Using format: stylish + +File 1 content: +{ + "setting1": "Some value", + "setting2": 200, + "setting3": true, + "key1": "value1", + "numbers1": [1, 2, 3, 4], + "numbers2": [2, 3, 4, 5], + "id": 45, + "default": null, + "checked": false, + "numbers3": [3, 4, 5], + "chars1": ["a", "b", "c"], + "chars2": ["d", "e", "f"] +} +File 2 content: +{ + "setting1": "Another value", + "setting2": 300, + "setting3": "none", + "key2": "value2", + "numbers1": [1, 2, 3, 4], + "numbers2": [22, 33, 44, 55], + "id": null, + "default": ["value1", "value2"], + "checked": true, + "numbers4": [4, 5, 6], + "chars1": ["a", "b", "c"], + "chars2": false, + "obj1": { + "nestedKey": "value", + "isNested": true + } +} +{ + chars1: [a, b, c] + - chars2: [d, e, f] + + chars2: false + - checked: false + + checked: true + - default: null + + default: [value1, value2] + - id: 45 + + id: null + - key1: value1 + + key2: value2 + numbers1: [1, 2, 3, 4] + - numbers2: [2, 3, 4, 5] + + numbers2: [22, 33, 44, 55] + - numbers3: [3, 4, 5] + + numbers4: [4, 5, 6] + + obj1: {nestedKey=value, isNested=true} + - setting1: Some value + + setting1: Another value + - setting2: 200 + + setting2: 300 + - setting3: true + + setting3: none +} + +``` + +### Сравнение yaml, вывод в plain-формате + +```bash +$ ./build/install/app/bin/app -f plain examples/file1nested.yaml examples/file2nested.yaml + +Reading file 1: examples/file1nested.yaml +Reading file 2: examples/file2nested.yaml +Using format: plain + +File 1 content: +setting1: Some value +setting2: 200 +setting3: true +key1: value1 +numbers1: +- 1 +- 2 +- 3 +- 4 + numbers2: +- 2 +- 3 +- 4 +- 5 + id: 45 + default: null + checked: false + numbers3: +- 3 +- 4 +- 5 + chars1: +- a +- b +- c + chars2: +- d +- e +- f + +File 2 content: +setting1: Another value +setting2: 300 +setting3: none +key2: value2 +numbers1: +- 1 +- 2 +- 3 +- 4 + numbers2: +- 22 +- 33 +- 44 +- 55 + id: null + default: +- value1 +- value2 + checked: true + numbers4: +- 4 +- 5 +- 6 + chars1: +- a +- b +- c + chars2: false + obj1: + nestedKey: value + isNested: true + +Property 'chars2' was updated. From [complex value] to false +Property 'checked' was updated. From false to true +Property 'default' was updated. From null to [complex value] +Property 'id' was updated. From 45 to null +Property 'key1' was removed +Property 'key2' was added with value: 'value2' +Property 'numbers2' was updated. From [complex value] to [complex value] +Property 'numbers3' was removed +Property 'numbers4' was added with value: [complex value] +Property 'obj1' was added with value: [complex value] +Property 'setting1' was updated. From 'Some value' to 'Another value' +Property 'setting2' was updated. From 200 to 300 +Property 'setting3' was updated. From true to 'none' +``` + + +### Сравнение yaml, вывод в json-формате + +```bash +$ ./build/install/app/bin/app -f json examples/file1nested.yaml examples/file2nested.yaml + + +[{"key":"chars1","status":"UNCHANGED","oldValue":["a","b","c"],"newValue":["a","b","c"]},{"key":"chars2","status":"CHANGED","oldValue":["d","e","f"],"newValue":false},{"key":"checked","status":"CHANGED","oldValue":false,"newValue":true},{"key":"default","status":"CHANGED","oldValue":null,"newValue":["value1 +","value2"]},{"key":"id","status":"CHANGED","oldValue":45,"newValue":null},{"key":"key1","status":"REMOVED","oldValue":"value1","newValue":null},{"key":"key2","status":"ADDED","oldValue":null,"newValue":"value2"},{"key":"numbers1","status":"UNCHANGED","oldValue":[1,2,3,4],"newValue":[1,2,3,4]},{"key":"numbe +rs2","status":"CHANGED","oldValue":[2,3,4,5],"newValue":[22,33,44,55]},{"key":"numbers3","status":"REMOVED","oldValue":[3,4,5],"newValue":null},{"key":"numbers4","status":"ADDED","oldValue":null,"newValue":[4,5,6]},{"key":"obj1","status":"ADDED","oldValue":null,"newValue":{"nestedKey":"value","isNested":true}},{"key":"setting1","status":"CHANGED","oldValue":"Some value","newValue":"Another value"},{"key":"setting2","status":"CHANGED","oldValue":200,"newValue":300},{"key":"setting3","status":"CHANGED","oldValue":true,"newValue":"none"}] + +``` \ No newline at end of file diff --git a/app/README.md b/app/README.md deleted file mode 100644 index 4deca50..0000000 --- a/app/README.md +++ /dev/null @@ -1,13 +0,0 @@ -## Пример использования - -```bash -$ gendiff file1.json file2.json - -{ - - follow: false - host: hexlet.io - - proxy: 123.234.53.22 - - timeout: 50 - + timeout: 20 - + verbose: true -} \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1eb2fd7..cb60c5d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,7 +1,6 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask plugins { - id("java") id("com.github.ben-manes.versions") version "0.51.0" // Актуальная версия на май 2025 id("application") id("checkstyle") diff --git a/app/src/main/java/hexlet/code/App.java b/app/src/main/java/hexlet/code/App.java index bc83f73..b9a3e31 100644 --- a/app/src/main/java/hexlet/code/App.java +++ b/app/src/main/java/hexlet/code/App.java @@ -5,14 +5,6 @@ import picocli.CommandLine.Command; import picocli.CommandLine.Parameters; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import java.util.List; -import java.util.Map; import java.util.concurrent.Callable; @Command( @@ -22,7 +14,7 @@ version = "gendiff 1.0" // Версия для опции --version ) -public class App implements Callable { +public final class App implements Callable { @Parameters(index = "0", description = "path to first file") private String filepath1; @@ -45,26 +37,8 @@ public static void main(String[] args) { @Override public Integer call() throws Exception { try { - // Добавляем проверку на одинаковое расширение файлов - validateFileExtensions(); - - System.out.println("Reading file 1: " + filepath1); - String file1Content = readFileContent(filepath1); - System.out.println("Reading file 2: " + filepath2); - String file2Content = readFileContent(filepath2); - - System.out.println("Using format: " + format); - System.out.println("\nFile 1 content:\n" + file1Content); - System.out.println("File 2 content:\n" + file2Content); - - // Парсинг происходит внутри try-блока - Map data1 = Parser.parseFileToMap(file1Content, filepath1); - Map data2 = Parser.parseFileToMap(file2Content, filepath2); - - String diff = generateDiff(data1, data2, format); - System.out.println(diff); + Differ.generate(this.filepath1, this.filepath2, this.format); return 0; // Успешное завершение - } catch (Exception e) { System.err.println("Error: " + e.getMessage()); return 1; // Код ошибки @@ -72,71 +46,5 @@ public Integer call() throws Exception { } - /** - * Проверяет, что оба файла имеют одинаковое расширение. - */ - private void validateFileExtensions() throws IOException { - String ext1 = getFileExtension(filepath1); - String ext2 = getFileExtension(filepath2); - - if (!ext1.equals(ext2)) { - throw new IOException("Files must have the same extension. " - + "First file has ." + ext1 + " extension, " - + "second file has ." + ext2 + " extension"); - } - - // Дополнительная проверка на поддерживаемые форматы - if (!ext1.equals("json") && !ext1.equals("yaml") && !ext1.equals("yml")) { - throw new IOException("Unsupported file format: ." + ext1 - + ". Supported formats are: json, yaml, yml"); - } - } - - /** - * @param filePath Путь к файлу. - * @return Расширение файла в нижнем регистре. - */ - private String getFileExtension(String filePath) { - Path path = Paths.get(filePath); - String fileName = path.getFileName().toString(); - - int dotIndex = fileName.lastIndexOf('.'); - if (dotIndex > 0 && dotIndex < fileName.length() - 1) { - return fileName.substring(dotIndex + 1).toLowerCase(); - } - return ""; - } - - - public static String generateDiff(Map data1, Map data2) { - return generateDiff(data1, data2, "stylish"); - } - - public static String generateDiff(Map data1, Map data2, String formatType) { - DiffBuilder diffBuilder = new DiffBuilder(); - List diffEntries = diffBuilder.buildDiff(data1, data2); - - Formatter formatter = FormatterFactory.create(formatType); - return formatter.format(diffEntries); - } - - - private String readFileContent(String filePath) throws IOException { - // Преобразуем путь в абсолютный и нормализуем (разрешаем .. и .) - Path path = Paths.get(filePath).toAbsolutePath().normalize(); - - // Проверка существования файла - if (!Files.exists(path)) { - throw new IOException("File not found: " + filePath); - } - - // Проверка, что это файл, а не директория - if (!Files.isRegularFile(path)) { - throw new IOException("Path is not a file: " + filePath); - } - - // Чтение содержимого с явным указанием кодировки - return new String(Files.readAllBytes(path), StandardCharsets.UTF_8); - } } diff --git a/app/src/main/java/hexlet/code/DiffBuilder.java b/app/src/main/java/hexlet/code/DiffBuilder.java index 80bc4ea..17c0ef4 100644 --- a/app/src/main/java/hexlet/code/DiffBuilder.java +++ b/app/src/main/java/hexlet/code/DiffBuilder.java @@ -8,7 +8,7 @@ import java.util.ArrayList; import java.util.Objects; -public class DiffBuilder { +public final class DiffBuilder { public List buildDiff(Map data1, Map data2) { Set uniqueKeys = new TreeSet<>(data1.keySet()); uniqueKeys.addAll(data2.keySet()); diff --git a/app/src/main/java/hexlet/code/DiffEntry.java b/app/src/main/java/hexlet/code/DiffEntry.java index e84130a..8a38699 100644 --- a/app/src/main/java/hexlet/code/DiffEntry.java +++ b/app/src/main/java/hexlet/code/DiffEntry.java @@ -2,7 +2,7 @@ import java.util.Objects; -public class DiffEntry { +public final class DiffEntry { private final String key; private final DiffStatus status; private final Object oldValue; diff --git a/app/src/main/java/hexlet/code/Differ.java b/app/src/main/java/hexlet/code/Differ.java new file mode 100644 index 0000000..4070d1f --- /dev/null +++ b/app/src/main/java/hexlet/code/Differ.java @@ -0,0 +1,112 @@ +package hexlet.code; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Map; + +public class Differ { + /** + * Проверяет, что оба файла имеют одинаковое расширение. + * @param filepath1 + * @param filepath2 + */ + static void validateFileExtensions(String filepath1, String filepath2) throws IOException { + String ext1 = getFileExtension(filepath1); + String ext2 = getFileExtension(filepath2); + + if (!ext1.equals(ext2)) { + throw new IOException("Files must have the same extension. " + + "First file has ." + ext1 + " extension, " + + "second file has ." + ext2 + " extension"); + } + + isSupportedFormat(ext1); + } + + private static void isSupportedFormat(String ext1) throws IOException { + // Дополнительная проверка на поддерживаемые форматы + if (!ext1.equals("json") && !ext1.equals("yaml") && !ext1.equals("yml")) { + throw new IOException("Unsupported file format: ." + ext1 + + ". Supported formats are: json, yaml, yml"); + } + } + + /** + * @param filePath Путь к файлу. + * @return Расширение файла в нижнем регистре. + */ + private static String getFileExtension(String filePath) { + Path path = Paths.get(filePath); + String fileName = path.getFileName().toString(); + + int dotIndex = fileName.lastIndexOf('.'); + if (dotIndex > 0 && dotIndex < fileName.length() - 1) { + return fileName.substring(dotIndex + 1).toLowerCase(); + } + return ""; + } + + public static String generateDiff(Map data1, Map data2) { + return generateDiff(data1, data2, "stylish"); + } + + public static String generateDiff(Map data1, Map data2, String formatType) { + DiffBuilder diffBuilder = new DiffBuilder(); + List diffEntries = diffBuilder.buildDiff(data1, data2); + + Formatter formatter = FormatterFactory.create(formatType); + return formatter.format(diffEntries); + } + + static String readFileContent(String filePath) throws IOException { + // Преобразуем путь в абсолютный и нормализуем (разрешаем .. и .) + Path path = Paths.get(filePath).toAbsolutePath().normalize(); + + // Проверка существования файла + if (!Files.exists(path)) { + throw new IOException("File not found: " + filePath); + } + + // Проверка, что это файл, а не директория + if (!Files.isRegularFile(path)) { + throw new IOException("Path is not a file: " + filePath); + } + + // Чтение содержимого с явным указанием кодировки + return new String(Files.readAllBytes(path), StandardCharsets.UTF_8); + } + + public static String generate(String filepath1, String filepath2) throws IOException { + return generate(filepath1, filepath2, "stylish"); + } + public static String generate(String filepath1, String filepath2, String format) throws IOException { + validateFileExtensions(filepath1, filepath2); + + String file1Content = readFileContent(filepath1); + String file1Format = getFormat(filepath1); + + String file2Content = readFileContent(filepath2); + String file2Format = getFormat(filepath1); + + Map data1 = Parser.toMap(file1Content, file1Format); + Map data2 = Parser.toMap(file2Content, file2Format); + + String diff = generateDiff(data1, data2, format); + System.out.println(diff); + return (diff); + } + + private static String getFormat(String filePath) { + String fileName = Paths.get(filePath).getFileName().toString(); + int dotIndex = fileName.lastIndexOf('.'); + if (dotIndex > 0) { + return fileName.substring(dotIndex + 1); + } + throw new IllegalArgumentException("Cannot determine format: " + filePath); + } + +} diff --git a/app/src/main/java/hexlet/code/Parser.java b/app/src/main/java/hexlet/code/Parser.java index 5885171..0dff729 100644 --- a/app/src/main/java/hexlet/code/Parser.java +++ b/app/src/main/java/hexlet/code/Parser.java @@ -5,42 +5,26 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import java.io.IOException; import java.util.Map; public class Parser { - static Map parseFileToMap(String content, String filePath) throws IOException { - if (filePath.endsWith(".json")) { - return parseJsonToMap(content, filePath); - } else if (filePath.endsWith(".yaml") || filePath.endsWith(".yml")) { - return parseYamlToMap(content, filePath); - } else { - throw new IOException("Unsupported file format: " + filePath); - } + // Unified method to parse content based on format string + public static Map toMap(String content, String dataFormat) throws JsonProcessingException { + return switch (dataFormat) { + case "json" -> parseJson(content); + case "yaml", "yml" -> parseYaml(content); + default -> throw new IllegalArgumentException("Unsupported format: " + dataFormat); + }; } - private static Map parseYamlToMap(String yamlContent, String fileName) throws IOException { + private static Map parseYaml(String yamlContent) throws JsonProcessingException { ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory()); - try { - return yamlMapper.readValue( - yamlContent, - new TypeReference>() { } - ); - } catch (JsonProcessingException e) { - throw new IOException("Error parsing YAML in " + fileName + ": " + e.getMessage(), e); - } + return yamlMapper.readValue(yamlContent, new TypeReference<>() { }); } - private static Map parseJsonToMap(String jsonContent, String fileName) throws IOException { + private static Map parseJson(String jsonContent) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); - try { - return objectMapper.readValue( - jsonContent, - new TypeReference>() { } - ); - } catch (JsonProcessingException e) { - throw new IOException("Error parsing JSON in " + fileName + ": " + e.getMessage(), e); - } + return objectMapper.readValue(jsonContent, new TypeReference<>() { }); } } diff --git a/app/src/main/java/hexlet/code/formatters/JsonFormatter.java b/app/src/main/java/hexlet/code/formatters/JsonFormatter.java index 439d0d3..ee3f29a 100644 --- a/app/src/main/java/hexlet/code/formatters/JsonFormatter.java +++ b/app/src/main/java/hexlet/code/formatters/JsonFormatter.java @@ -1,98 +1,19 @@ package hexlet.code.formatters; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.core.util.DefaultIndenter; -import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import hexlet.code.DiffEntry; import hexlet.code.Formatter; -import java.lang.reflect.Field; import java.util.List; - -public class JsonFormatter implements Formatter { +public final class JsonFormatter implements Formatter { private static final ObjectMapper MAPPER = new ObjectMapper(); @Override public String format(List diffEntries) { - ArrayNode root = MAPPER.createArrayNode(); - - for (DiffEntry entry : diffEntries) { - ObjectNode node = MAPPER.createObjectNode(); - node.put("key", entry.getKey()); - node.put("status", entry.getStatus().name().toLowerCase()); - - switch (entry.getStatus()) { - case UNCHANGED: - node.set("value", convertValue(entry.getNewValue())); - break; - case CHANGED: - node.set("oldValue", convertValue(entry.getOldValue())); - node.set("newValue", convertValue(entry.getNewValue())); - break; - case ADDED: - node.set("value", convertValue(entry.getNewValue())); - break; - case REMOVED: - node.set("value", convertValue(entry.getOldValue())); - break; - default: - break; - } - - root.add(node); - } - - try { - // Создаем кастомный PrettyPrinter - DefaultPrettyPrinter printer = new DefaultPrettyPrinter(); - - // Убираем пробел после двоеточия с помощью рефлексии - try { - Field field = DefaultPrettyPrinter.class.getDeclaredField("spacesInObjectEntries"); - field.setAccessible(true); - field.setBoolean(printer, false); - } catch (Exception e) { - // Если не получилось, пытаемся использовать метод withoutSpacesInObjectEntries - try { - java.lang.reflect.Method method; - method = DefaultPrettyPrinter.class.getMethod("withoutSpacesInObjectEntries"); - printer = (DefaultPrettyPrinter) method.invoke(printer); - } catch (Exception ex) { - // Если все методы не сработали, оставляем как есть - } - } - - // Настройка отступов - DefaultIndenter indenter = new DefaultIndenter(" ", "\n"); - printer.indentArraysWith(indenter); - printer.indentObjectsWith(indenter); - - return MAPPER.writer(printer).writeValueAsString(root); - } catch (Exception e) { - throw new RuntimeException("Failed to format JSON", e); - } - } - - private com.fasterxml.jackson.databind.JsonNode convertValue(Object value) { - if (value == null) { - return MAPPER.nullNode(); - } - - // Для простых типов используем стандартное преобразование - if (value instanceof String - || value instanceof Boolean - || value instanceof Number) { - return MAPPER.valueToTree(value); - } - - // Для коллекций и других объектов пытаемся преобразовать в JSON try { - return MAPPER.valueToTree(value); + return MAPPER.writeValueAsString(diffEntries); } catch (Exception e) { - // Если не удалось преобразовать, используем toString() - return MAPPER.createObjectNode().put("value", value.toString()); + throw new RuntimeException("Failed to generate JSON", e); } } } diff --git a/app/src/main/java/hexlet/code/formatters/PlainFormatter.java b/app/src/main/java/hexlet/code/formatters/PlainFormatter.java index dfc181a..7c8ed45 100644 --- a/app/src/main/java/hexlet/code/formatters/PlainFormatter.java +++ b/app/src/main/java/hexlet/code/formatters/PlainFormatter.java @@ -4,7 +4,7 @@ import hexlet.code.Formatter; import java.util.List; -public class PlainFormatter implements Formatter { +public final class PlainFormatter implements Formatter { @Override public String format(List diffEntries) { StringBuilder result = new StringBuilder(); diff --git a/app/src/main/java/hexlet/code/formatters/StylishFormatter.java b/app/src/main/java/hexlet/code/formatters/StylishFormatter.java index 26134e3..28675ce 100644 --- a/app/src/main/java/hexlet/code/formatters/StylishFormatter.java +++ b/app/src/main/java/hexlet/code/formatters/StylishFormatter.java @@ -5,7 +5,7 @@ import java.util.List; -public class StylishFormatter implements Formatter { +public final class StylishFormatter implements Formatter { @Override public String format(List diffEntries) { StringBuilder result = new StringBuilder("{\n"); diff --git a/app/src/test/java/hexlet/code/DifferTest.java b/app/src/test/java/hexlet/code/DifferTest.java new file mode 100644 index 0000000..c79e6d4 --- /dev/null +++ b/app/src/test/java/hexlet/code/DifferTest.java @@ -0,0 +1,126 @@ +package hexlet.code; + +import org.junit.jupiter.api.Test; + +import java.nio.file.Files; +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DifferTest { + @Test + void testJsonStylishFormat() throws Exception { + String filepath1 = "src/test/resources/file1.json"; + String filepath2 = "src/test/resources/file2.json"; + + String actual = Differ.generate(filepath1, filepath2, "stylish"); + + String expected = Files.readString( + Path.of("src/test/resources/expectedDiffStylishFormat.txt") + ).trim(); + + assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); + } + + @Test + void testJsonJsonFormat() throws Exception { + String filepath1 = "src/test/resources/file1.json"; + String filepath2 = "src/test/resources/file2.json"; + + String actual = Differ.generate(filepath1, filepath2, "json"); + + String expected = Files.readString( + Path.of("src/test/resources/expectedDiffJsonFormat.txt") + ).trim(); + + assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); + } + + @Test + void testJsonPlainFormat() throws Exception { + String filepath1 = "src/test/resources/file1.json"; + String filepath2 = "src/test/resources/file2.json"; + + String actual = Differ.generate(filepath1, filepath2, "plain"); + + String expected = Files.readString( + Path.of("src/test/resources/expectedDiffPlainFormat.txt") + ).trim(); + + assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); + } + + @Test + void testJsonDefaultFormat() throws Exception { + String filepath1 = "src/test/resources/file1.json"; + String filepath2 = "src/test/resources/file2.json"; + + String actual = Differ.generate(filepath1, filepath2, "stylish"); + + String expected = Files.readString( + Path.of("src/test/resources/expectedDiffStylishFormat.txt") + ).trim(); + + assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); + } + + @Test + void testYamlStylishFormat() throws Exception { + String filepath1 = "src/test/resources/file1.yaml"; + String filepath2 = "src/test/resources/file2.yaml"; + + String actual = Differ.generate(filepath1, filepath2, "stylish"); + + String expected = Files.readString( + Path.of("src/test/resources/expectedDiffStylishFormat.txt") + ).trim(); + + assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); + } + + @Test + void testYamlJsonFormat() throws Exception { + String filepath1 = "src/test/resources/file1.yaml"; + String filepath2 = "src/test/resources/file2.yaml"; + + String actual = Differ.generate(filepath1, filepath2, "json"); + + String expected = Files.readString( + Path.of("src/test/resources/expectedDiffJsonFormat.txt") + ).trim(); + + assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); + } + + @Test + void testYamlPlainFormat() throws Exception { + String filepath1 = "src/test/resources/file1.yaml"; + String filepath2 = "src/test/resources/file2.yaml"; + + String actual = Differ.generate(filepath1, filepath2, "plain"); + + String expected = Files.readString( + Path.of("src/test/resources/expectedDiffPlainFormat.txt") + ).trim(); + + assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); + } + + @Test + void testYamlDefaultFormat() throws Exception { + String filepath1 = "src/test/resources/file1.yaml"; + String filepath2 = "src/test/resources/file2.yaml"; + + String actual = Differ.generate(filepath1, filepath2, "stylish"); + + String expected = Files.readString( + Path.of("src/test/resources/expectedDiffStylishFormat.txt") + ).trim(); + + assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); + } + + private String normalizeSpaces(String input) { + return input.replaceAll("\\s+", " ").trim(); + } +} diff --git a/app/src/test/java/hexlet/code/JsonDiffTest.java b/app/src/test/java/hexlet/code/JsonDiffTest.java deleted file mode 100644 index 0505916..0000000 --- a/app/src/test/java/hexlet/code/JsonDiffTest.java +++ /dev/null @@ -1,163 +0,0 @@ -package hexlet.code; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Map; -import static org.junit.jupiter.api.Assertions.assertEquals; - -class JsonDiffTest { - - private final ObjectMapper objectMapper = new ObjectMapper(); - - @Test - void testJsonFlatFilesDiff() throws Exception { - // Загружаем тестовые данные - String beforeJson = Files.readString( - Path.of("src/test/resources/file1nested.json") - ); - String afterJson = Files.readString( - Path.of("src/test/resources/file2nested.json") - ); - - // Парсим JSON в Map - Map before = objectMapper.readValue(beforeJson, - new com.fasterxml.jackson.core.type.TypeReference>() { }); - Map after = objectMapper.readValue(afterJson, - new com.fasterxml.jackson.core.type.TypeReference>() { }); - - // Ожидаемый результат с правильными отступами и форматированием - String expected = """ - { - chars1: [a, b, c] - - chars2: [d, e, f] - + chars2: false - - checked: false - + checked: true - - default: null - + default: [value1, value2] - - id: 45 - + id: null - - key1: value1 - + key2: value2 - numbers1: [1, 2, 3, 4] - - numbers2: [2, 3, 4, 5] - + numbers2: [22, 33, 44, 55] - - numbers3: [3, 4, 5] - + numbers4: [4, 5, 6] - + obj1: {nestedKey=value, isNested=true} - - setting1: Some value - + setting1: Another value - - setting2: 200 - + setting2: 300 - - setting3: true - + setting3: none - }"""; - - // Получаем реальный результат - String actual = App.generateDiff(before, after); - - // Сравниваем с нормализацией пробелов - assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); - } - - // Тест для одинаковых файлов - @Test - void testIdenticalFiles() { - Map data1 = Map.of( - "host", "hexlet.io", - "port", 8080 - ); - - Map data2 = Map.of( - "host", "hexlet.io", - "port", 8080 - ); - - String expected = """ - { - host: hexlet.io - port: 8080 - }"""; - - assertEquals(normalizeSpaces(expected), - normalizeSpaces(App.generateDiff(data1, data2))); - } - - // Тест для файлов с разным порядком ключей - @Test - void testDifferentOrder() { - Map data1 = Map.of( - "c", 3, - "a", 1, - "b", 2 - ); - - Map data2 = Map.of( - "b", 2, - "c", 3, - "a", 1 - ); - - String expected = """ - { - a: 1 - b: 2 - c: 3 - }"""; - - assertEquals(normalizeSpaces(expected), - normalizeSpaces(App.generateDiff(data1, data2))); - } - - // Тест для файлов с разными типами данных - @Test - void testDifferentDataTypes() { - Map data1 = Map.of( - "number", 42, - "string", "text", - "boolean", true - ); - - Map data2 = Map.of( - "number", "42", - "string", "text", - "boolean", false - ); - - String expected = """ - { - - boolean: true - + boolean: false - - number: 42 - + number: 42 - string: text - }"""; - - assertEquals(normalizeSpaces(expected), - normalizeSpaces(App.generateDiff(data1, data2))); - } - - // Тест для одного пустого файла - @Test - void testEmptyFile() { - Map data1 = Map.of(); - Map data2 = Map.of( - "key", "value" - ); - - String expected = """ - { - + key: value - }"""; - - assertEquals(normalizeSpaces(expected), - normalizeSpaces(App.generateDiff(data1, data2))); - } - - - private String normalizeSpaces(String input) { - return input.replaceAll("\\s+", " ").trim(); - } -} diff --git a/app/src/test/java/hexlet/code/JsonFormatterTest.java b/app/src/test/java/hexlet/code/JsonFormatterTest.java deleted file mode 100644 index e355139..0000000 --- a/app/src/test/java/hexlet/code/JsonFormatterTest.java +++ /dev/null @@ -1,163 +0,0 @@ -package hexlet.code.formatters; - -import hexlet.code.DiffEntry; -import hexlet.code.DiffStatus; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Collections; -import java.util.LinkedHashMap; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class JsonFormatterTest { - - @Test - void testFormatWithAllStatuses() - throws IOException, URISyntaxException { - // Создаем тестовые данные с разными статусами - - Map obj1Map = new LinkedHashMap<>(); - obj1Map.put("nestedKey", "value"); - obj1Map.put("isNested", true); - - List diffEntries = Arrays.asList( - new DiffEntry("chars1", - DiffStatus.UNCHANGED, - Arrays.asList("a", "b", "c"), - Arrays.asList("a", "b", "c")), - new DiffEntry("chars2", DiffStatus.CHANGED, Arrays.asList("d", "e", "f"), false), - new DiffEntry("checked", DiffStatus.CHANGED, false, true), - new DiffEntry("default", DiffStatus.CHANGED, null, Arrays.asList("value1", "value2")), - new DiffEntry("id", DiffStatus.CHANGED, 45, null), - new DiffEntry("key1", DiffStatus.REMOVED, "value1", null), - new DiffEntry("key2", DiffStatus.ADDED, null, "value2"), - new DiffEntry("numbers1", DiffStatus.UNCHANGED, Arrays.asList(1, 2, 3, 4), Arrays.asList(1, 2, 3, 4)), - new DiffEntry("numbers2", DiffStatus.CHANGED, Arrays.asList(2, 3, 4, 5), Arrays.asList(22, 33, 44, 55)), - new DiffEntry("numbers3", DiffStatus.REMOVED, Arrays.asList(3, 4, 5), null), - new DiffEntry("numbers4", DiffStatus.ADDED, null, Arrays.asList(4, 5, 6)), - new DiffEntry("obj1", DiffStatus.ADDED, null, obj1Map), - new DiffEntry("setting1", DiffStatus.CHANGED, "Some value", "Another value"), - new DiffEntry("setting2", DiffStatus.CHANGED, 200, 300), - new DiffEntry("setting3", DiffStatus.CHANGED, true, "none") - ); - - // Загружаем ожидаемый результат из файла ресурсов - Path expectedFilePath = Paths.get( - Objects.requireNonNull(getClass().getClassLoader().getResource("expectedJsonDiff.json")).toURI() - ); - String expected = Files.readString(expectedFilePath); - - - JsonFormatter formatter = new JsonFormatter(); - String actual = formatter.format(diffEntries); - - // Сравниваем результаты, удаляя все пробелы и переносы строк - assertEquals(expected.replaceAll("\\s", ""), actual.replaceAll("\\s", "")); - } - - - @Test - void testFormatEmptyDiff() { - List diffEntries = Collections.emptyList(); - String expected = "[]"; - - JsonFormatter formatter = new JsonFormatter(); - String actual = formatter.format(diffEntries); - - assertEquals(expected.replaceAll("\\s", ""), actual.replaceAll("\\s", "")); - } - - @Test - void testFormatUnchangedStatus() { - List diffEntries = Collections.singletonList( - new DiffEntry("unchangedKey", DiffStatus.UNCHANGED, "value", "value") - ); - - String expected = """ - [ - { - "key":"unchangedKey", - "status":"unchanged", - "value":"value" - } - ]"""; - - JsonFormatter formatter = new JsonFormatter(); - String actual = formatter.format(diffEntries); - - assertEquals(expected.replaceAll("\\s", ""), actual.replaceAll("\\s", "")); - } - - @Test - void testFormatAddedStatus() { - List diffEntries = Collections.singletonList( - new DiffEntry("addedKey", DiffStatus.ADDED, null, "newValue") - ); - - String expected = """ - [ - { - "key":"addedKey", - "status":"added", - "value":"newValue" - } - ]"""; - - JsonFormatter formatter = new JsonFormatter(); - String actual = formatter.format(diffEntries); - - assertEquals(expected.replaceAll("\\s", ""), actual.replaceAll("\\s", "")); - } - - @Test - void testFormatRemovedStatus() { - List diffEntries = Collections.singletonList( - new DiffEntry("removedKey", DiffStatus.REMOVED, "oldValue", null) - ); - - String expected = """ - [ - { - "key":"removedKey", - "status":"removed", - "value":"oldValue" - } - ]"""; - - JsonFormatter formatter = new JsonFormatter(); - String actual = formatter.format(diffEntries); - - assertEquals(expected.replaceAll("\\s", ""), actual.replaceAll("\\s", "")); - } - - @Test - void testFormatChangedStatus() { - List diffEntries = Collections.singletonList( - new DiffEntry("changedKey", DiffStatus.CHANGED, "oldValue", "newValue") - ); - - String expected = """ - [ - { - "key":"changedKey", - "status":"changed", - "oldValue":"oldValue", - "newValue":"newValue" - } - ]"""; - - JsonFormatter formatter = new JsonFormatter(); - String actual = formatter.format(diffEntries); - - assertEquals(expected.replaceAll("\\s", ""), actual.replaceAll("\\s", "")); - } -} diff --git a/app/src/test/java/hexlet/code/PlainFormatterTest.java b/app/src/test/java/hexlet/code/PlainFormatterTest.java deleted file mode 100644 index 3a1c58f..0000000 --- a/app/src/test/java/hexlet/code/PlainFormatterTest.java +++ /dev/null @@ -1,154 +0,0 @@ -package hexlet.code; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Map; -import static org.junit.jupiter.api.Assertions.assertEquals; - -class PlainFormatterTest { - - private final ObjectMapper objectMapper = new ObjectMapper(); - - @Test - void testJsonFlatFilesDiff() throws Exception { - // Загружаем тестовые данные - String beforeJson = Files.readString( - Path.of("src/test/resources/file1nested.json") - ); - String afterJson = Files.readString( - Path.of("src/test/resources/file2nested.json") - ); - - // Парсим JSON в Map - Map before = objectMapper.readValue(beforeJson, - new com.fasterxml.jackson.core.type.TypeReference>() { }); - Map after = objectMapper.readValue(afterJson, - new com.fasterxml.jackson.core.type.TypeReference>() { }); - - // Ожидаемый результат в формате PlainTextFormatter - String expected = """ - Property 'chars2' was updated. From [complex value] to false - Property 'checked' was updated. From false to true - Property 'default' was updated. From null to [complex value] - Property 'id' was updated. From 45 to null - Property 'key1' was removed - Property 'key2' was added with value: 'value2' - Property 'numbers2' was updated. From [complex value] to [complex value] - Property 'numbers3' was removed - Property 'numbers4' was added with value: [complex value] - Property 'obj1' was added with value: [complex value] - Property 'setting1' was updated. From 'Some value' to 'Another value' - Property 'setting2' was updated. From 200 to 300 - Property 'setting3' was updated. From true to 'none'"""; - - // Получаем реальный результат, указывая тип форматтера "plain-text" - String actual = App.generateDiff(before, after, "plain"); - - // Сравниваем результаты - assertEquals(expected, actual); - } - - // Тест для одинаковых файлов (ничего не должно выводиться) - @Test - void testIdenticalFiles() { - Map data1 = Map.of( - "host", "hexlet.io", - "port", 8080 - ); - - Map data2 = Map.of( - "host", "hexlet.io", - "port", 8080 - ); - - String expected = ""; - String actual = App.generateDiff(data1, data2, "plain"); - assertEquals(expected, actual); - } - - // Тест для файлов с разным порядком ключей (но одинаковыми данными) - @Test - void testDifferentOrder() { - Map data1 = Map.of( - "c", 3, - "a", 1, - "b", 2 - ); - - Map data2 = Map.of( - "b", 2, - "c", 3, - "a", 1 - ); - - String expected = ""; - String actual = App.generateDiff(data1, data2, "plain"); - assertEquals(expected, actual); - } - - // Тест для файлов с разными типами данных - @Test - void testDifferentDataTypes() { - Map data1 = Map.of( - "number", 42, - "string", "text", - "boolean", true - ); - - Map data2 = Map.of( - "number", "42", - "string", "text", - "boolean", false - ); - - String expected = """ - Property 'boolean' was updated. From true to false - Property 'number' was updated. From 42 to '42'"""; - - String actual = App.generateDiff(data1, data2, "plain"); - assertEquals(expected, actual); - } - - // Тест для одного пустого файла - @Test - void testEmptyFile() { - Map data1 = Map.of(); - Map data2 = Map.of( - "key", "value" - ); - - String expected = "Property 'key' was added with value: 'value'"; - String actual = App.generateDiff(data1, data2, "plain"); - assertEquals(expected, actual); - } - - // Тест для сложных значений (объектов и массивов) - @Test - void testComplexValues() { - Map data1 = Map.of( - "simple", "value", - "array", List.of(1, 2, 3), - "object", Map.of("key", "value") - ); - - Map data2 = Map.of( - "simple", "new_value", - "array", List.of(4, 5, 6), - "object", Map.of("key", "new_value"), - "new_key", "new_value" - ); - - String expected = """ - Property 'array' was updated. From [complex value] to [complex value] - Property 'new_key' was added with value: 'new_value' - Property 'object' was updated. From [complex value] to [complex value] - Property 'simple' was updated. From 'value' to 'new_value'"""; - - String actual = App.generateDiff(data1, data2, "plain"); - assertEquals(expected, actual); - } - -} diff --git a/app/src/test/java/hexlet/code/YamlDiffTest.java b/app/src/test/java/hexlet/code/YamlDiffTest.java deleted file mode 100644 index f2f9263..0000000 --- a/app/src/test/java/hexlet/code/YamlDiffTest.java +++ /dev/null @@ -1,195 +0,0 @@ -package hexlet.code; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class YamlDiffTest { - private final ObjectMapper yamlObjectMapper = new ObjectMapper( - new com.fasterxml.jackson.dataformat.yaml.YAMLFactory() - ); - // Базовый тест для YAML файлов из задания - @Test - void testYamlFilesDiff() throws Exception { - // Загружаем тестовые данные - String beforeYaml = Files.readString( - Path.of("src/test/resources/file1nested.yaml") - ); - String afterYaml = Files.readString( - Path.of("src/test/resources/file2nested.yaml") - ); - - // Парсим JSON в Map - Map before = yamlObjectMapper.readValue(beforeYaml, - new com.fasterxml.jackson.core.type.TypeReference>() { }); - Map after = yamlObjectMapper.readValue(afterYaml, - new com.fasterxml.jackson.core.type.TypeReference>() { }); - - // Ожидаемый результат с правильными отступами и форматированием - String expected = """ - { - chars1: [a, b, c] - - chars2: [d, e, f] - + chars2: false - - checked: false - + checked: true - - default: null - + default: [value1, value2] - - id: 45 - + id: null - - key1: value1 - + key2: value2 - numbers1: [1, 2, 3, 4] - - numbers2: [2, 3, 4, 5] - + numbers2: [22, 33, 44, 55] - - numbers3: [3, 4, 5] - + numbers4: [4, 5, 6] - + obj1: {nestedKey=value, isNested=true} - - setting1: Some value - + setting1: Another value - - setting2: 200 - + setting2: 300 - - setting3: true - + setting3: none - }"""; - - // Получаем реальный результат - String actual = App.generateDiff(before, after); - - assertEquals(normalizeSpaces(expected), normalizeSpaces(actual)); - } - - // Тест для одинаковых YAML файлов - @Test - void testIdenticalYamlFiles() { - Map data1 = Map.of( - "server", "localhost", - "port", 8080, - "enabled", true - ); - - Map data2 = Map.of( - "server", "localhost", - "port", 8080, - "enabled", true - ); - - String expected = """ - { - enabled: true - port: 8080 - server: localhost - }"""; - - assertEquals(normalizeSpaces(expected), - normalizeSpaces(App.generateDiff(data1, data2))); - } - - // Тест для YAML файлов с разным порядком ключей - @Test - void testYamlDifferentOrder() { - Map data1 = Map.of( - "z", "last", - "a", "first", - "m", "middle" - ); - - Map data2 = Map.of( - "m", "middle", - "z", "last", - "a", "first" - ); - - String expected = """ - { - a: first - m: middle - z: last - }"""; - - assertEquals(normalizeSpaces(expected), - normalizeSpaces(App.generateDiff(data1, data2))); - } - - // Тест для YAML файлов с разными типами данных - @Test - void testYamlDifferentDataTypes() { - Map data1 = Map.of( - "count", 10, - "active", true, - "name", "test" - ); - - Map data2 = Map.of( - "count", "ten", - "active", false, - "name", "test" - ); - - String expected = """ - { - - active: true - + active: false - - count: 10 - + count: ten - name: test - }"""; - - assertEquals(normalizeSpaces(expected), - normalizeSpaces(App.generateDiff(data1, data2))); - } - - // Тест для одного пустого YAML файла - @Test - void testEmptyYamlFile() { - Map data1 = Map.of(); - Map data2 = Map.of( - "config", "value", - "debug", true - ); - - String expected = """ - { - + config: value - + debug: true - }"""; - - assertEquals(normalizeSpaces(expected), - normalizeSpaces(App.generateDiff(data1, data2))); - } - - // Тест для YAML с вложенными структурами (плоские файлы, но проверка обработки простых структур) - @Test - void testYamlSimpleStructures() { - Map data1 = Map.of( - "user", Map.of("name", "John", "age", 30), - "active", true - ); - - Map data2 = Map.of( - "user", Map.of("name", "John", "age", 31), - "active", true - ); - - String actual = normalizeSpaces(App.generateDiff(data1, data2)); - - // Проверяем основные компоненты, не завися от порядка - assertTrue(actual.contains("- user: {")); - assertTrue(actual.contains("+ user: {")); - assertTrue(actual.contains("name=John")); - assertTrue(actual.contains("age=30")); - assertTrue(actual.contains("age=31")); - assertTrue(actual.contains("active: true")); - } - - // Вспомогательный метод для нормализации пробелов - private String normalizeSpaces(String input) { - return input.replaceAll("\\s+", " ").trim(); - } -} diff --git a/app/src/test/resources/expectedDiffJsonFormat.txt b/app/src/test/resources/expectedDiffJsonFormat.txt new file mode 100644 index 0000000..6c86d4f --- /dev/null +++ b/app/src/test/resources/expectedDiffJsonFormat.txt @@ -0,0 +1 @@ +[{"key":"chars1","status":"UNCHANGED","oldValue":["a","b","c"],"newValue":["a","b","c"]},{"key":"chars2","status":"CHANGED","oldValue":["d","e","f"],"newValue":false},{"key":"checked","status":"CHANGED","oldValue":false,"newValue":true},{"key":"default","status":"CHANGED","oldValue":null,"newValue":["value1","value2"]},{"key":"id","status":"CHANGED","oldValue":45,"newValue":null},{"key":"key1","status":"REMOVED","oldValue":"value1","newValue":null},{"key":"key2","status":"ADDED","oldValue":null,"newValue":"value2"},{"key":"numbers1","status":"UNCHANGED","oldValue":[1,2,3,4],"newValue":[1,2,3,4]},{"key":"numbers2","status":"CHANGED","oldValue":[2,3,4,5],"newValue":[22,33,44,55]},{"key":"numbers3","status":"REMOVED","oldValue":[3,4,5],"newValue":null},{"key":"numbers4","status":"ADDED","oldValue":null,"newValue":[4,5,6]},{"key":"obj1","status":"ADDED","oldValue":null,"newValue":{"nestedKey":"value","isNested":true}},{"key":"setting1","status":"CHANGED","oldValue":"Some value","newValue":"Another value"},{"key":"setting2","status":"CHANGED","oldValue":200,"newValue":300},{"key":"setting3","status":"CHANGED","oldValue":true,"newValue":"none"}] diff --git a/app/src/test/resources/expectedDiffPlainFormat.txt b/app/src/test/resources/expectedDiffPlainFormat.txt new file mode 100644 index 0000000..05837c7 --- /dev/null +++ b/app/src/test/resources/expectedDiffPlainFormat.txt @@ -0,0 +1,13 @@ +Property 'chars2' was updated. From [complex value] to false +Property 'checked' was updated. From false to true +Property 'default' was updated. From null to [complex value] +Property 'id' was updated. From 45 to null +Property 'key1' was removed +Property 'key2' was added with value: 'value2' +Property 'numbers2' was updated. From [complex value] to [complex value] +Property 'numbers3' was removed +Property 'numbers4' was added with value: [complex value] +Property 'obj1' was added with value: [complex value] +Property 'setting1' was updated. From 'Some value' to 'Another value' +Property 'setting2' was updated. From 200 to 300 +Property 'setting3' was updated. From true to 'none' diff --git a/app/src/test/resources/expectedDiffStylishFormat.txt b/app/src/test/resources/expectedDiffStylishFormat.txt new file mode 100644 index 0000000..d999b67 --- /dev/null +++ b/app/src/test/resources/expectedDiffStylishFormat.txt @@ -0,0 +1,25 @@ +{ + chars1: [a, b, c] + - chars2: [d, e, f] + + chars2: false + - checked: false + + checked: true + - default: null + + default: [value1, value2] + - id: 45 + + id: null + - key1: value1 + + key2: value2 + numbers1: [1, 2, 3, 4] + - numbers2: [2, 3, 4, 5] + + numbers2: [22, 33, 44, 55] + - numbers3: [3, 4, 5] + + numbers4: [4, 5, 6] + + obj1: {nestedKey=value, isNested=true} + - setting1: Some value + + setting1: Another value + - setting2: 200 + + setting2: 300 + - setting3: true + + setting3: none +} \ No newline at end of file diff --git a/app/src/test/resources/expectedJsonDiff.json b/app/src/test/resources/expectedJsonDiff.json deleted file mode 100644 index a1a89e4..0000000 --- a/app/src/test/resources/expectedJsonDiff.json +++ /dev/null @@ -1,122 +0,0 @@ -[ - { - "key":"chars1", - "status":"unchanged", - "value":[ - "a", - "b", - "c" - ] - }, - { - "key":"chars2", - "status":"changed", - "oldValue":[ - "d", - "e", - "f" - ], - "newValue":false - }, - { - "key":"checked", - "status":"changed", - "oldValue":false, - "newValue":true - }, - { - "key":"default", - "status":"changed", - "oldValue":null, - "newValue":[ - "value1", - "value2" - ] - }, - { - "key":"id", - "status":"changed", - "oldValue":45, - "newValue":null - }, - { - "key":"key1", - "status":"removed", - "value":"value1" - }, - { - "key":"key2", - "status":"added", - "value":"value2" - }, - { - "key":"numbers1", - "status":"unchanged", - "value":[ - 1, - 2, - 3, - 4 - ] - }, - { - "key":"numbers2", - "status":"changed", - "oldValue":[ - 2, - 3, - 4, - 5 - ], - "newValue":[ - 22, - 33, - 44, - 55 - ] - }, - { - "key":"numbers3", - "status":"removed", - "value":[ - 3, - 4, - 5 - ] - }, - { - "key":"numbers4", - "status":"added", - "value":[ - 4, - 5, - 6 - ] - }, - { - "key":"obj1", - "status":"added", - "value":{ - "nestedKey":"value", - "isNested":true - } - }, - { - "key":"setting1", - "status":"changed", - "oldValue":"Some value", - "newValue":"Another value" - }, - { - "key":"setting2", - "status":"changed", - "oldValue":200, - "newValue":300 - }, - { - "key":"setting3", - "status":"changed", - "oldValue":true, - "newValue":"none" - } -] \ No newline at end of file diff --git a/app/src/test/resources/file1.json b/app/src/test/resources/file1.json index 6212a97..ff478df 100644 --- a/app/src/test/resources/file1.json +++ b/app/src/test/resources/file1.json @@ -1,6 +1,14 @@ { - "host": "hexlet.io", - "timeout": 50, - "proxy": "123.234.53.22", - "follow": false + "setting1": "Some value", + "setting2": 200, + "setting3": true, + "key1": "value1", + "numbers1": [1, 2, 3, 4], + "numbers2": [2, 3, 4, 5], + "id": 45, + "default": null, + "checked": false, + "numbers3": [3, 4, 5], + "chars1": ["a", "b", "c"], + "chars2": ["d", "e", "f"] } \ No newline at end of file diff --git a/app/src/test/resources/file1.yaml b/app/src/test/resources/file1.yaml index e86729d..1a87624 100644 --- a/app/src/test/resources/file1.yaml +++ b/app/src/test/resources/file1.yaml @@ -1,4 +1,29 @@ -host: hexlet.io -timeout: 50 -proxy: 123.234.53.22 -follow: false +setting1: Some value +setting2: 200 +setting3: true +key1: value1 +numbers1: + - 1 + - 2 + - 3 + - 4 +numbers2: + - 2 + - 3 + - 4 + - 5 +id: 45 +default: null +checked: false +numbers3: + - 3 + - 4 + - 5 +chars1: + - a + - b + - c +chars2: + - d + - e + - f diff --git a/app/src/test/resources/file1nested.json b/app/src/test/resources/file1nested.json deleted file mode 100644 index ff478df..0000000 --- a/app/src/test/resources/file1nested.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "setting1": "Some value", - "setting2": 200, - "setting3": true, - "key1": "value1", - "numbers1": [1, 2, 3, 4], - "numbers2": [2, 3, 4, 5], - "id": 45, - "default": null, - "checked": false, - "numbers3": [3, 4, 5], - "chars1": ["a", "b", "c"], - "chars2": ["d", "e", "f"] -} \ No newline at end of file diff --git a/app/src/test/resources/file1nested.yaml b/app/src/test/resources/file1nested.yaml deleted file mode 100644 index 1a87624..0000000 --- a/app/src/test/resources/file1nested.yaml +++ /dev/null @@ -1,29 +0,0 @@ -setting1: Some value -setting2: 200 -setting3: true -key1: value1 -numbers1: - - 1 - - 2 - - 3 - - 4 -numbers2: - - 2 - - 3 - - 4 - - 5 -id: 45 -default: null -checked: false -numbers3: - - 3 - - 4 - - 5 -chars1: - - a - - b - - c -chars2: - - d - - e - - f diff --git a/app/src/test/resources/file2.json b/app/src/test/resources/file2.json index c97f279..91fa8fd 100644 --- a/app/src/test/resources/file2.json +++ b/app/src/test/resources/file2.json @@ -1,5 +1,18 @@ { - "timeout": 20, - "verbose": true, - "host": "hexlet.io" + "setting1": "Another value", + "setting2": 300, + "setting3": "none", + "key2": "value2", + "numbers1": [1, 2, 3, 4], + "numbers2": [22, 33, 44, 55], + "id": null, + "default": ["value1", "value2"], + "checked": true, + "numbers4": [4, 5, 6], + "chars1": ["a", "b", "c"], + "chars2": false, + "obj1": { + "nestedKey": "value", + "isNested": true + } } \ No newline at end of file diff --git a/app/src/test/resources/file2.yaml b/app/src/test/resources/file2.yaml index 37e50c1..99db3de 100644 --- a/app/src/test/resources/file2.yaml +++ b/app/src/test/resources/file2.yaml @@ -1,3 +1,31 @@ -timeout: 20 -verbose: true -host: hexlet.io +setting1: Another value +setting2: 300 +setting3: none +key2: value2 +numbers1: + - 1 + - 2 + - 3 + - 4 +numbers2: + - 22 + - 33 + - 44 + - 55 +id: null +default: + - value1 + - value2 +checked: true +numbers4: + - 4 + - 5 + - 6 +chars1: + - a + - b + - c +chars2: false +obj1: + nestedKey: value + isNested: true diff --git a/app/src/test/resources/file2nested.json b/app/src/test/resources/file2nested.json deleted file mode 100644 index 91fa8fd..0000000 --- a/app/src/test/resources/file2nested.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "setting1": "Another value", - "setting2": 300, - "setting3": "none", - "key2": "value2", - "numbers1": [1, 2, 3, 4], - "numbers2": [22, 33, 44, 55], - "id": null, - "default": ["value1", "value2"], - "checked": true, - "numbers4": [4, 5, 6], - "chars1": ["a", "b", "c"], - "chars2": false, - "obj1": { - "nestedKey": "value", - "isNested": true - } -} \ No newline at end of file diff --git a/app/src/test/resources/file2nested.yaml b/app/src/test/resources/file2nested.yaml deleted file mode 100644 index 99db3de..0000000 --- a/app/src/test/resources/file2nested.yaml +++ /dev/null @@ -1,31 +0,0 @@ -setting1: Another value -setting2: 300 -setting3: none -key2: value2 -numbers1: - - 1 - - 2 - - 3 - - 4 -numbers2: - - 22 - - 33 - - 44 - - 55 -id: null -default: - - value1 - - value2 -checked: true -numbers4: - - 4 - - 5 - - 6 -chars1: - - a - - b - - c -chars2: false -obj1: - nestedKey: value - isNested: true