17
17
18
18
import static com .diffplug .spotless .json .gson .GsonStep .DEFAULT_VERSION ;
19
19
20
- import java .io .File ;
21
-
22
- import org .assertj .core .api .Assertions ;
23
20
import org .junit .jupiter .api .Test ;
24
21
25
22
import com .diffplug .spotless .FormatterStep ;
@@ -42,12 +39,32 @@ void handlesObjectWithNull() {
42
39
43
40
@ Test
44
41
void handlesInvalidJson () {
45
- getStepHarness ().testResourceExceptionMsg ("json/invalidJsonBefore.json" ).isEqualTo ("End of input at line 3 column 1 path $.a" );
42
+ getStepHarness ().expectLintsOfResource ("json/invalidJsonBefore.json" ).toBe ("L3 gson(com.google.gson.JsonSyntaxException) java.io.EOFException: End of input at line 3 column 1 path $.a" ,
43
+ "\t at com.google.gson.Gson.fromJson(Gson.java:1370)" ,
44
+ "\t at com.google.gson.Gson.fromJson(Gson.java:1262)" ,
45
+ "\t at com.google.gson.Gson.fromJson(Gson.java:1171)" ,
46
+ "\t at com.google.gson.Gson.fromJson(Gson.java:1107)" ,
47
+ "\t at com.diffplug.spotless.glue.gson.GsonFormatterFunc.apply(GsonFormatterFunc.java:57)" ,
48
+ "\t at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)" ,
49
+ "\t at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)" ,
50
+ "\t at com.diffplug.spotless.LintState.of(LintState.java:141)" ,
51
+ "\t at com.diffplug.spotless.StepHarness.expectLintsOf(StepHarness.java:96)" ,
52
+ "(... and more)" );
46
53
}
47
54
48
55
@ Test
49
56
void handlesNotJson () {
50
- getStepHarness ().testResourceExceptionMsg ("json/notJsonBefore.json" ).isEqualTo ("Unable to format JSON" );
57
+ getStepHarness ().expectLintsOfResource ("json/notJsonBefore.json" ).toBe ("LINE_UNDEFINED gson(java.lang.IllegalArgumentException) Unable to parse JSON" ,
58
+ "\t at com.diffplug.spotless.glue.gson.GsonFormatterFunc.apply(GsonFormatterFunc.java:59)" ,
59
+ "\t at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)" ,
60
+ "\t at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)" ,
61
+ "\t at com.diffplug.spotless.LintState.of(LintState.java:141)" ,
62
+ "\t at com.diffplug.spotless.StepHarness.expectLintsOf(StepHarness.java:96)" ,
63
+ "\t at com.diffplug.spotless.StepHarness.expectLintsOfResource(StepHarness.java:92)" ,
64
+ "\t at com.diffplug.spotless.json.gson.GsonStepTest.handlesNotJson(GsonStepTest.java:57)" ,
65
+ "\t at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)" ,
66
+ "\t at java.base/java.lang.reflect.Method.invoke(Method.java:580)" ,
67
+ "(... and more)" );
51
68
}
52
69
53
70
@ Test
@@ -79,10 +96,18 @@ void writesRawHtmlWhenHtmlEscapeDisabled() {
79
96
80
97
@ Test
81
98
void handlesVersionIncompatibility () {
82
- FormatterStep step = GsonStep .create (new GsonConfig (false , false , INDENT , "1.7" ), TestProvisioner .mavenCentral ());
83
- Assertions .assertThatThrownBy (() -> step .format ("" , new File ("" )))
84
- .isInstanceOf (IllegalStateException .class )
85
- .hasMessage ("There was a problem interacting with Gson; maybe you set an incompatible version?" );
99
+ StepHarness .forStep (GsonStep .create (new GsonConfig (false , false , INDENT , "1.7" ), TestProvisioner .mavenCentral ()))
100
+ .expectLintsOf ("" ).toBe ("LINE_UNDEFINED gson(java.lang.IllegalStateException) There was a problem interacting with Gson; maybe you set an incompatible version?" ,
101
+ "\t at com.diffplug.spotless.json.gson.GsonStep$State.toFormatter(GsonStep.java:73)" ,
102
+ "\t at com.diffplug.spotless.FormatterStepSerializationRoundtrip.stateToFormatter(FormatterStepSerializationRoundtrip.java:64)" ,
103
+ "\t at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:47)" ,
104
+ "\t at com.diffplug.spotless.LintState.of(LintState.java:141)" ,
105
+ "\t at com.diffplug.spotless.StepHarness.expectLintsOf(StepHarness.java:96)" ,
106
+ "\t at com.diffplug.spotless.json.gson.GsonStepTest.handlesVersionIncompatibility(GsonStepTest.java:100)" ,
107
+ "\t at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)" ,
108
+ "\t at java.base/java.lang.reflect.Method.invoke(Method.java:580)" ,
109
+ "\t at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:766)" ,
110
+ "(... and more)" );
86
111
}
87
112
88
113
@ Override
0 commit comments