Skip to content

Commit ca3afb5

Browse files
committed
Add test
1 parent e36855c commit ca3afb5

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

app/src/main/java/hexlet/code/Differ.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
public class Differ {
14-
14+
public final static String DEFAULT_FORMAT = "stylish";
1515

1616
public static String generate(String filePath1, String filePath2, String format) throws IOException {
1717
var normalizedPath1 = FileManager.normaolizePath(Path.of(filePath1));
@@ -28,6 +28,10 @@ public static String generate(String filePath1, String filePath2, String format)
2828

2929
var differenceMap = TreeBuilder.getTreeDifference(dataFirst, dataSecond);
3030

31-
return Formatter.getOrder(format, differenceMap);
31+
return Formatter.generateFormatString(format, differenceMap);
32+
}
33+
34+
public static String generate(String filePath1, String filePath2) throws IOException {
35+
return Differ.generate(filePath1, filePath2, DEFAULT_FORMAT);
3236
}
3337
}

app/src/main/java/hexlet/code/Formatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class Formatter {
1212

13-
public static String getOrder(String format, Map<String, List<Object>> differenceMap)
13+
public static String generateFormatString(String format, Map<String, List<Object>> differenceMap)
1414
throws IllegalArgumentException, JsonProcessingException {
1515
var normalizeFormat = format.trim().toLowerCase();
1616
var result = "";

app/src/test/java/source/TestDiffer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ public void testWrongFormat() {
108108
assertEquals("Не найден формат", thrownSecondArg.getMessage());
109109
}
110110

111+
@Test
112+
public void testGenerateWithOutFormat() throws IOException {
113+
var differenceJson = Differ.generate(firstTestJsonFilePath, secondTestJsonFilePath);
114+
assertEquals(differsStylish, differenceJson);
115+
116+
String differenceYaml = Differ.generate(firstTestYamlFilePath, secondTestYamlFilePath);
117+
assertEquals(differenceYaml, differsStylish);
118+
}
119+
111120

112121
public static String readReroptAsString(Path path) throws IOException {
113122
var normalizePath = path.normalize().toAbsolutePath();

0 commit comments

Comments
 (0)