File tree Expand file tree Collapse file tree 4 files changed +45
-12
lines changed
main/java/io/github/jsonSnapshot
test/java/io/github/jsonSnapshot Expand file tree Collapse file tree 4 files changed +45
-12
lines changed Original file line number Diff line number Diff line change 5
5
<modelVersion >4.0.0</modelVersion >
6
6
<groupId >io.github.json-snapshot</groupId >
7
7
<artifactId >json-snapshot</artifactId >
8
- <version >1.0.4 </version >
8
+ <version >1.0.5 </version >
9
9
<packaging >jar</packaging >
10
10
11
11
<name >json-snapshot</name >
66
66
<artifactId >commons-lang3</artifactId >
67
67
<version >3.7</version >
68
68
</dependency >
69
+ <dependency >
70
+ <groupId >junit</groupId >
71
+ <artifactId >junit</artifactId >
72
+ <version >4.12</version >
73
+ </dependency >
69
74
<dependency >
70
75
<groupId >org.assertj</groupId >
71
76
<artifactId >assertj-core</artifactId >
81
86
<artifactId >slf4j-api</artifactId >
82
87
<version >1.7.25</version >
83
88
</dependency >
84
-
85
-
86
- <!-- Test -->
87
- <dependency >
88
- <groupId >junit</groupId >
89
- <artifactId >junit</artifactId >
90
- <version >4.12</version >
91
- <scope >test</scope >
92
- </dependency >
93
-
94
89
</dependencies >
95
90
96
91
<build >
Original file line number Diff line number Diff line change 3
3
import org .apache .commons .lang3 .ArrayUtils ;
4
4
import org .apache .commons .lang3 .StringUtils ;
5
5
import org .assertj .core .util .Arrays ;
6
+ import org .junit .BeforeClass ;
7
+ import org .junit .Test ;
6
8
import org .mockito .ArgumentCaptor ;
7
9
import org .mockito .verification .VerificationMode ;
8
10
import org .slf4j .Logger ;
@@ -100,10 +102,27 @@ private static StackTraceElement findStackElement() throws ClassNotFoundExceptio
100
102
101
103
int i = 1 ; // Start after stackTrace
102
104
while (i < stackTraceElements .length &&
103
- SnapshotMatcher .class .equals (Class .forName (stackTraceElements [i ].getClassName ()))) {
105
+ SnapshotMatcher .class .equals (Class .forName (stackTraceElements [i ].getClassName ()))) { //TODO
104
106
i ++;
105
107
}
106
108
109
+ for (int j = i ; j < stackTraceElements .length ; j ++) {
110
+
111
+ try {
112
+ Class clazz = Class .forName (stackTraceElements [j ].getClassName ());
113
+ Method method = clazz .getMethod (stackTraceElements [j ].getMethodName ());
114
+
115
+ // Navigate into stack until Test class/method level
116
+ if (method .isAnnotationPresent (Test .class ) || method .isAnnotationPresent (BeforeClass .class )) {
117
+ i = j ;
118
+ break ;
119
+ }
120
+ }
121
+ catch (NoSuchMethodException ignored ) {
122
+
123
+ }
124
+ }
125
+
107
126
return stackTraceElements [i ];
108
127
}
109
128
Original file line number Diff line number Diff line change @@ -47,6 +47,15 @@ public void shouldMatchSnapshotFour() {
47
47
expect (FakeObject .builder ().id ("anyId4" ).value (4 ).name ("any\n \n \n Name4" ).build ()).toMatchSnapshot ();
48
48
}
49
49
50
+ @ Test
51
+ public void shouldMatchSnapshotInsidePrivateMethod () {
52
+ matchInsidePrivate ();
53
+ }
54
+
55
+ private void matchInsidePrivate () {
56
+ expect (FakeObject .builder ().id ("anyPrivate" ).value (5 ).name ("anyPrivate" ).build ()).toMatchSnapshot ();
57
+ }
58
+
50
59
@ Test
51
60
public void shouldThrowSnapshotMatchException () {
52
61
expectedException .expect (SnapshotMatchException .class );
Original file line number Diff line number Diff line change @@ -40,4 +40,14 @@ io.github.jsonSnapshot.SnapshotIntegrationTest.shouldMatchSnapshotTwo=[
40
40
" value" : 2 ,
41
41
" name" : " anyName2"
42
42
}
43
+ ]
44
+
45
+
46
+
47
+ io .github .jsonSnapshot .SnapshotIntegrationTest .shouldMatchSnapshotInsidePrivateMethod = [
48
+ {
49
+ " id" : " anyPrivate" ,
50
+ " value" : 5 ,
51
+ " name" : " anyPrivate"
52
+ }
43
53
]
You can’t perform that action at this time.
0 commit comments