@@ -39,8 +39,14 @@ Add to your pom.xml dependencies section:
39
39
package com.example ;
40
40
41
41
import static io.github.jsonSnapshot.SnapshotMatcher.* ;
42
+ import static io.github.jsonSnapshot.SnapshotUtils.* ;
42
43
43
44
public class ExampleTest {
45
+
46
+ @Mock
47
+ private FakeObject fakeObject;
48
+
49
+
44
50
@BeforeClass
45
51
public static void beforeAll () {
46
52
start();
@@ -51,10 +57,32 @@ public class ExampleTest {
51
57
validateSnapshots();
52
58
}
53
59
54
- @Test
60
+ @Test // Snapshot any object
55
61
public void shouldShowSnapshotExample () {
56
62
expect(" <any type of object>" ). toMatchSnapshot();
57
63
}
64
+
65
+ @Test // Snapshot arguments passed to mocked object
66
+ public void shouldExtractArgsFromMethod () {
67
+
68
+ fakeObject. fakeMethod(" test1" , 1L , Arrays . asList(" listTest1" ));
69
+ fakeObject. fakeMethod(" test2" , 2L , Arrays . asList(" listTest1" , " listTest2" ));
70
+
71
+ expect(extractArgs(fakeObject, " fakeMethod" , String . class, Long . class, List . class)). toMatchSnapshot();
72
+
73
+ }
74
+
75
+ class FakeObject {
76
+ private String id;
77
+
78
+ private Integer value;
79
+
80
+ private String name;
81
+
82
+ void fakeMethod (String fakeName , Long fakeNumber , List<String > fakeList ) {
83
+
84
+ }
85
+ }
58
86
}
59
87
```
60
88
@@ -63,6 +91,29 @@ When the test runs for the first time, the framework will create a snapshot file
63
91
com.example.ExampleTest.shouldShowSnapshotExample=[
64
92
"<any type of object>"
65
93
]
94
+
95
+
96
+ com.example.ExampleTest.shouldExtractArgsFromMethod=[
97
+ {
98
+ "FakeObject.fakeMethod": [
99
+ {
100
+ "arg0": "test1",
101
+ "arg1": 1,
102
+ "arg2": [
103
+ "listTest1"
104
+ ]
105
+ },
106
+ {
107
+ "arg0": "test2",
108
+ "arg1": 2,
109
+ "arg2": [
110
+ "listTest1",
111
+ "listTest2"
112
+ ]
113
+ }
114
+ ]
115
+ }
116
+ ]
66
117
```
67
118
68
119
Whenever it runs again, the ` expect ` method argument will be automatically validated with the ` .snap ` file. That is why you should commit every ` .snap ` file created.
0 commit comments