@@ -47,6 +47,22 @@ class JsonFormatTest {
4747
4848 private final ObjectMapper mapper = new ObjectMapper ();
4949
50+ @ ParameterizedTest
51+ @ MethodSource ("jsonContentTypes" )
52+ void isJsonContentType (String contentType ) {
53+ boolean json = JsonFormat .dataIsJsonContentType (contentType );
54+
55+ assertThat (json ).isTrue ();
56+ }
57+
58+ @ ParameterizedTest
59+ @ MethodSource ("wrongJsonContentTypes" )
60+ void isNotJsonContentType (String contentType ) {
61+ boolean json = JsonFormat .dataIsJsonContentType (contentType );
62+
63+ assertThat (json ).isFalse ();
64+ }
65+
5066 @ ParameterizedTest
5167 @ MethodSource ("serializeTestArgumentsDefault" )
5268 void serialize (CloudEvent input , String outputFile ) throws IOException {
@@ -151,6 +167,39 @@ void verifyDeserializeError(String inputFile){
151167
152168 }
153169
170+ static Stream <Arguments > jsonContentTypes () {
171+ return Stream .of (
172+ Arguments .of ("application/json" ),
173+ Arguments .of ("application/json;charset=utf-8" ),
174+ Arguments .of ("application/json;\t charset = \" utf-8\" " ),
175+ Arguments .of ("application/cloudevents+json;charset=UTF-8" ),
176+ Arguments .of ("text/json" ),
177+ Arguments .of ("text/json;charset=utf-8" ),
178+ Arguments .of ("text/cloudevents+json;charset=UTF-8" ),
179+ Arguments .of ("text/json;\t whatever" ),
180+ Arguments .of ("text/json; boundary=something" ),
181+ Arguments .of ("text/json;foo=\" bar\" " ),
182+ Arguments .of ("text/json; charset = \" us-ascii\" " ),
183+ Arguments .of ("text/json; \t " ),
184+ Arguments .of ("text/json;" ),
185+ //https://www.rfc-editor.org/rfc/rfc2045#section-5.1
186+ // any us-ascii char can be part of parameters (except CTRLs and tspecials)
187+ Arguments .of ("text/json; char-set = $!#$%&'*+.^_`|" ),
188+ Arguments .of ((Object ) null )
189+ );
190+ }
191+
192+ static Stream <Arguments > wrongJsonContentTypes () {
193+ return Stream .of (
194+ Arguments .of ("applications/json" ),
195+ Arguments .of ("application/jsom" ),
196+ Arguments .of ("application/jsonwrong" ),
197+ Arguments .of ("text/json " ),
198+ Arguments .of ("text/json ;" ),
199+ Arguments .of ("test/json" )
200+ );
201+ }
202+
154203 public static Stream <Arguments > serializeTestArgumentsDefault () {
155204 return Stream .of (
156205 Arguments .of (V03_MIN , "v03/min.json" ),
0 commit comments