Skip to content

Commit 42a303a

Browse files
committed
added files for tests
1 parent 2e1e93f commit 42a303a

File tree

11 files changed

+140
-127
lines changed

11 files changed

+140
-127
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
300 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
340 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

.gradle/file-system.probe

0 Bytes
Binary file not shown.
Lines changed: 14 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,28 @@
11
package hexlet.code;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
34
import hexlet.code.formatters.Formatter;
45
import org.junit.jupiter.api.Test;
56
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Paths;
9+
610
import static org.junit.jupiter.api.Assertions.assertEquals;
711

812
class DifferTest {
913

10-
private static final String EXPECTED_JSON_STYLISH = """
11-
{
12-
chars1: [a, b, c]
13-
- chars2: [d, e, f]
14-
+ chars2: false
15-
- checked: false
16-
+ checked: true
17-
- default: null
18-
+ default: [value1, value2]
19-
- id: 45
20-
+ id: null
21-
- key1: value1
22-
+ key2: value2
23-
numbers1: [1, 2, 3, 4]
24-
- numbers2: [2, 3, 4, 5]
25-
+ numbers2: [22, 33, 44, 55]
26-
- numbers3: [3, 4, 5]
27-
+ numbers4: [4, 5, 6]
28-
+ obj1: {nestedKey=value, isNested=true}
29-
- setting1: Some value
30-
+ setting1: Another value
31-
- setting2: 200
32-
+ setting2: 300
33-
- setting3: true
34-
+ setting3: none
35-
}
36-
""";
37-
38-
39-
private static final String EXPECTED_DIFF_PLAIN = """
40-
Property 'chars2' was updated. From [complex value] to false
41-
Property 'checked' was updated. From false to true
42-
Property 'default' was updated. From null to [complex value]
43-
Property 'id' was updated. From 45 to null
44-
Property 'key1' was removed
45-
Property 'key2' was added with value: 'value2'
46-
Property 'numbers2' was updated. From [complex value] to [complex value]
47-
Property 'numbers3' was removed
48-
Property 'numbers4' was added with value: [complex value]
49-
Property 'obj1' was added with value: [complex value]
50-
Property 'setting1' was updated. From 'Some value' to 'Another value'
51-
Property 'setting2' was updated. From 200 to 300
52-
Property 'setting3' was updated. From true to 'none'
53-
""";
54-
55-
56-
private static final String EXPECTED_JSON = """
57-
[ {
58-
"type" : "unchanged",
59-
"value" : [ "a", "b", "c" ],
60-
"key" : "chars1"
61-
}, {
62-
"newValue" : false,
63-
"oldValue" : [ "d", "e", "f" ],
64-
"type" : "updated",
65-
"key" : "chars2"
66-
}, {
67-
"newValue" : true,
68-
"oldValue" : false,
69-
"type" : "updated",
70-
"key" : "checked"
71-
}, {
72-
"newValue" : [ "value1", "value2" ],
73-
"oldValue" : null,
74-
"type" : "updated",
75-
"key" : "default"
76-
}, {
77-
"newValue" : null,
78-
"oldValue" : 45,
79-
"type" : "updated",
80-
"key" : "id"
81-
}, {
82-
"oldValue" : "value1",
83-
"type" : "removed",
84-
"key" : "key1"
85-
}, {
86-
"newValue" : "value2",
87-
"type" : "added",
88-
"key" : "key2"
89-
}, {
90-
"type" : "unchanged",
91-
"value" : [ 1, 2, 3, 4 ],
92-
"key" : "numbers1"
93-
}, {
94-
"newValue" : [ 22, 33, 44, 55 ],
95-
"oldValue" : [ 2, 3, 4, 5 ],
96-
"type" : "updated",
97-
"key" : "numbers2"
98-
}, {
99-
"oldValue" : [ 3, 4, 5 ],
100-
"type" : "removed",
101-
"key" : "numbers3"
102-
}, {
103-
"newValue" : [ 4, 5, 6 ],
104-
"type" : "added",
105-
"key" : "numbers4"
106-
}, {
107-
"newValue" : {
108-
"nestedKey" : "value",
109-
"isNested" : true
110-
},
111-
"type" : "added",
112-
"key" : "obj1"
113-
}, {
114-
"newValue" : "Another value",
115-
"oldValue" : "Some value",
116-
"type" : "updated",
117-
"key" : "setting1"
118-
}, {
119-
"newValue" : 300,
120-
"oldValue" : 200,
121-
"type" : "updated",
122-
"key" : "setting2"
123-
}, {
124-
"newValue" : "none",
125-
"oldValue" : true,
126-
"type" : "updated",
127-
"key" : "setting3"
128-
} ]
129-
""";
14+
private static String readExpected(String fileName) throws IOException {
15+
var path = Paths.get("src/test/resources/fixtures/" + fileName);
16+
return Files.readString(path).strip();
17+
}
13018

13119
@Test
13220
void testGenerateDiffForJsonStylish() throws IOException {
13321
var data1 = Parser.parseFromResources("file1.json");
13422
var data2 = Parser.parseFromResources("file2.json");
13523
var diff = Differ.calculateDiff(data1, data2);
13624
var actual = Formatter.format(diff, "stylish");
137-
System.out.println("Actual output: \n" + actual);
138-
assertEquals(EXPECTED_JSON_STYLISH.strip(), actual.strip());
25+
assertEquals(readExpected("expectedStylish.txt"), actual.strip());
13926
System.out.println("ВСЕ РАБОТАЕТ!!!");
14027
}
14128

@@ -145,20 +32,20 @@ void testGenerateDiffForJsonPlain() throws IOException {
14532
var data2 = Parser.parseFromResources("file2.yml");
14633
var diff = Differ.calculateDiff(data1, data2);
14734
var actual = Formatter.format(diff, "plain");
148-
System.out.println("Actual output: " + actual);
149-
assertEquals(EXPECTED_DIFF_PLAIN.strip(), actual.strip());
35+
assertEquals(readExpected("expectedPlain.txt"), actual.strip());
15036
System.out.println("ВСЕ РАБОТАЕТ! лала!!!");
15137
}
15238

153-
15439
@Test
15540
void testGenerateDiffForJsonJson() throws IOException {
15641
var data1 = Parser.parseFromResources("file1.json");
15742
var data2 = Parser.parseFromResources("file2.json");
15843
var diff = Differ.calculateDiff(data1, data2);
15944
var actual = Formatter.format(diff, "json");
160-
System.out.println("Actual output: " + actual);
161-
assertEquals(EXPECTED_JSON.strip(), actual.strip());
45+
ObjectMapper mapper = new ObjectMapper();
46+
var expected = mapper.readTree(readExpected("expectedJson.json"));
47+
var actualTree = mapper.readTree(actual);
48+
assertEquals(expected, actualTree);
16249
System.out.println("ВСЕ РАБОТАЕТ! дада!!!");
16350
}
16451
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[
2+
{
3+
"type": "unchanged",
4+
"value": ["a", "b", "c"],
5+
"key": "chars1"
6+
},
7+
{
8+
"newValue": false,
9+
"oldValue": ["d", "e", "f"],
10+
"type": "updated",
11+
"key": "chars2"
12+
},
13+
{
14+
"newValue": true,
15+
"oldValue": false,
16+
"type": "updated",
17+
"key": "checked"
18+
},
19+
{
20+
"newValue": ["value1", "value2"],
21+
"oldValue": null,
22+
"type": "updated",
23+
"key": "default"
24+
},
25+
{
26+
"newValue": null,
27+
"oldValue": 45,
28+
"type": "updated",
29+
"key": "id"
30+
},
31+
{
32+
"oldValue": "value1",
33+
"type": "removed",
34+
"key": "key1"
35+
},
36+
{
37+
"newValue": "value2",
38+
"type": "added",
39+
"key": "key2"
40+
},
41+
{
42+
"type": "unchanged",
43+
"value": [1, 2, 3, 4],
44+
"key": "numbers1"
45+
},
46+
{
47+
"newValue": [22, 33, 44, 55],
48+
"oldValue": [2, 3, 4, 5],
49+
"type": "updated",
50+
"key": "numbers2"
51+
},
52+
{
53+
"oldValue": [3, 4, 5],
54+
"type": "removed",
55+
"key": "numbers3"
56+
},
57+
{
58+
"newValue": [4, 5, 6],
59+
"type": "added",
60+
"key": "numbers4"
61+
},
62+
{
63+
"newValue": {
64+
"nestedKey": "value",
65+
"isNested": true
66+
},
67+
"type": "added",
68+
"key": "obj1"
69+
},
70+
{
71+
"newValue": "Another value",
72+
"oldValue": "Some value",
73+
"type": "updated",
74+
"key": "setting1"
75+
},
76+
{
77+
"newValue": 300,
78+
"oldValue": 200,
79+
"type": "updated",
80+
"key": "setting2"
81+
},
82+
{
83+
"newValue": "none",
84+
"oldValue": true,
85+
"type": "updated",
86+
"key": "setting3"
87+
}
88+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Property 'chars2' was updated. From [complex value] to false
2+
Property 'checked' was updated. From false to true
3+
Property 'default' was updated. From null to [complex value]
4+
Property 'id' was updated. From 45 to null
5+
Property 'key1' was removed
6+
Property 'key2' was added with value: 'value2'
7+
Property 'numbers2' was updated. From [complex value] to [complex value]
8+
Property 'numbers3' was removed
9+
Property 'numbers4' was added with value: [complex value]
10+
Property 'obj1' was added with value: [complex value]
11+
Property 'setting1' was updated. From 'Some value' to 'Another value'
12+
Property 'setting2' was updated. From 200 to 300
13+
Property 'setting3' was updated. From true to 'none'

0 commit comments

Comments
 (0)