Skip to content

Commit 894d7a2

Browse files
committed
added other tests
1 parent 42a303a commit 894d7a2

File tree

7 files changed

+62
-23
lines changed

7 files changed

+62
-23
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
238 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package hexlet.code;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4-
import hexlet.code.formatters.Formatter;
54
import org.junit.jupiter.api.Test;
65
import java.io.IOException;
76
import java.nio.file.Files;
@@ -16,36 +15,76 @@ private static String readExpected(String fileName) throws IOException {
1615
return Files.readString(path).strip();
1716
}
1817

18+
private static String getFixturePath(String fileName) {
19+
return Paths.get("src/test/resources/fixtures/" + fileName).toString();
20+
}
21+
22+
23+
@Test
24+
void testGenerateJsonStylish() throws IOException {
25+
String expected = readExpected("expectedStylish.txt");
26+
String actual = Differ.generate(getFixturePath("file1.json"), getFixturePath("file2.json"), "stylish");
27+
assertEquals(expected.strip(), actual.strip());
28+
System.out.println("1 ВСЕ РАБОТАЕТ");
29+
}
30+
31+
@Test
32+
void testGenerateJsonPlain() throws IOException {
33+
String expected = readExpected("expectedPlain.txt");
34+
String actual = Differ.generate(getFixturePath("file1.json"), getFixturePath("file2.json"), "plain");
35+
assertEquals(expected.strip(), actual.strip());
36+
System.out.println("2 ВСЕ РАБОТАЕТ");
37+
}
38+
39+
@Test
40+
void testGenerateJsonJson() throws IOException {
41+
ObjectMapper mapper = new ObjectMapper();
42+
var expected = mapper.readTree(readExpected("expectedJson.json"));
43+
var actual = mapper.readTree(Differ.generate(getFixturePath("file1.json"), getFixturePath("file2.json"), "json"));
44+
assertEquals(expected, actual);
45+
System.out.println("3 ВСЕ РАБОТАЕТ");
46+
}
47+
48+
1949
@Test
20-
void testGenerateDiffForJsonStylish() throws IOException {
21-
var data1 = Parser.parseFromResources("file1.json");
22-
var data2 = Parser.parseFromResources("file2.json");
23-
var diff = Differ.calculateDiff(data1, data2);
24-
var actual = Formatter.format(diff, "stylish");
25-
assertEquals(readExpected("expectedStylish.txt"), actual.strip());
26-
System.out.println("ВСЕ РАБОТАЕТ!!!");
50+
void testGenerateYamlStylish() throws IOException {
51+
String expected = readExpected("expectedStylish.txt");
52+
String actual = Differ.generate(getFixturePath("file1.yml"), getFixturePath("file2.yml"), "stylish");
53+
assertEquals(expected.strip(), actual.strip());
54+
System.out.println("4 ВСЕ РАБОТАЕТ");
2755
}
2856

2957
@Test
30-
void testGenerateDiffForJsonPlain() throws IOException {
31-
var data1 = Parser.parseFromResources("file1.yml");
32-
var data2 = Parser.parseFromResources("file2.yml");
33-
var diff = Differ.calculateDiff(data1, data2);
34-
var actual = Formatter.format(diff, "plain");
35-
assertEquals(readExpected("expectedPlain.txt"), actual.strip());
36-
System.out.println("ВСЕ РАБОТАЕТ! лала!!!");
58+
void testGenerateYamlPlain() throws IOException {
59+
String expected = readExpected("expectedPlain.txt");
60+
String actual = Differ.generate(getFixturePath("file1.yml"), getFixturePath("file2.yml"), "plain");
61+
assertEquals(expected.strip(), actual.strip());
62+
System.out.println("5 ВСЕ РАБОТАЕТ");
3763
}
3864

3965
@Test
40-
void testGenerateDiffForJsonJson() throws IOException {
41-
var data1 = Parser.parseFromResources("file1.json");
42-
var data2 = Parser.parseFromResources("file2.json");
43-
var diff = Differ.calculateDiff(data1, data2);
44-
var actual = Formatter.format(diff, "json");
66+
void testGenerateYamlJson() throws IOException {
4567
ObjectMapper mapper = new ObjectMapper();
4668
var expected = mapper.readTree(readExpected("expectedJson.json"));
47-
var actualTree = mapper.readTree(actual);
48-
assertEquals(expected, actualTree);
49-
System.out.println("ВСЕ РАБОТАЕТ! дада!!!");
69+
var actual = mapper.readTree(Differ.generate(getFixturePath("file1.yml"), getFixturePath("file2.yml"), "json"));
70+
assertEquals(expected, actual);
71+
System.out.println("6 ВСЕ РАБОТАЕТ");
72+
}
73+
74+
@Test
75+
void testGenerateJsonDefault() throws IOException {
76+
String expected = readExpected("expectedStylish.txt");
77+
String actual = Differ.generate(getFixturePath("file1.json"), getFixturePath("file2.json"));
78+
assertEquals(expected.strip(), actual.strip());
79+
System.out.println("7 ВСЕ РАБОТАЕТ");
80+
}
81+
82+
83+
@Test
84+
void testGenerateYamlDefault() throws IOException {
85+
String expected = readExpected("expectedStylish.txt");
86+
String actual = Differ.generate(getFixturePath("file1.yml"), getFixturePath("file2.yml"));
87+
assertEquals(expected.strip(), actual.strip());
88+
System.out.println("8 ВСЕ РАБОТАЕТ");
5089
}
5190
}

0 commit comments

Comments
 (0)