Skip to content

Commit 527b811

Browse files
committed
Change README to explain extractArgs utils
1 parent 450dabf commit 527b811

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ Add to your pom.xml dependencies section:
3939
package com.example;
4040

4141
import static io.github.jsonSnapshot.SnapshotMatcher.*;
42+
import static io.github.jsonSnapshot.SnapshotUtils.*;
4243

4344
public class ExampleTest {
45+
46+
@Mock
47+
private FakeObject fakeObject;
48+
49+
4450
@BeforeClass
4551
public static void beforeAll() {
4652
start();
@@ -51,10 +57,32 @@ public class ExampleTest {
5157
validateSnapshots();
5258
}
5359

54-
@Test
60+
@Test // Snapshot any object
5561
public void shouldShowSnapshotExample() {
5662
expect("<any type of object>").toMatchSnapshot();
5763
}
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+
}
5886
}
5987
```
6088

@@ -63,6 +91,29 @@ When the test runs for the first time, the framework will create a snapshot file
6391
com.example.ExampleTest.shouldShowSnapshotExample=[
6492
"<any type of object>"
6593
]
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+
]
66117
```
67118

68119
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.

src/test/java/io/github/jsonSnapshot/SnapshotUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void afterAll() {
3333

3434

3535
@Test
36-
public void shouldExtractArgsFromMethod() throws NoSuchMethodException {
36+
public void shouldExtractArgsFromMethod() {
3737

3838
fakeObject.fakeMethod("test1", 1L, Arrays.asList("listTest1"));
3939
fakeObject.fakeMethod("test2", 2L, Arrays.asList("listTest1", "listTest2"));

0 commit comments

Comments
 (0)