1212import org .junit .Test ;
1313import org .junit .rules .ExpectedException ;
1414
15- import java .util .Arrays ;
16- import java .util .Collections ;
17- import java .util .Date ;
18- import java .util .Map ;
15+ import java .util .*;
1916
2017import static com .auth0 .jwt .impl .JWTParser .getDefaultObjectMapper ;
2118import static com .auth0 .jwt .impl .JsonNodeClaim .claimFromNode ;
@@ -268,12 +265,82 @@ public void shouldReturnBaseClaimWhenParsingNullValue() throws Exception {
268265 }
269266
270267 @ Test
271- public void shouldReturnValidButNullClaimIfTreeIsEmpty () throws Exception {
268+ public void shouldReturnNonNullClaimWhenParsingObject () throws Exception {
272269 JsonNode value = mapper .valueToTree (new Object ());
273270 Claim claim = claimFromNode (value );
274271
275272 assertThat (claim , is (notNullValue ()));
276273 assertThat (claim , is (instanceOf (JsonNodeClaim .class )));
277- assertThat (claim .isNull (), is (true ));
274+ assertThat (claim .isNull (), is (false ));
275+ }
276+
277+ @ Test
278+ public void shouldReturnNonNullClaimWhenParsingArray () throws Exception {
279+ JsonNode value = mapper .valueToTree (new String []{});
280+ Claim claim = claimFromNode (value );
281+
282+ assertThat (claim , is (notNullValue ()));
283+ assertThat (claim , is (instanceOf (JsonNodeClaim .class )));
284+ assertThat (claim .isNull (), is (false ));
285+ }
286+
287+ @ Test
288+ public void shouldReturnNonNullClaimWhenParsingList () throws Exception {
289+ JsonNode value = mapper .valueToTree (new ArrayList <String >());
290+ Claim claim = claimFromNode (value );
291+
292+ assertThat (claim , is (notNullValue ()));
293+ assertThat (claim , is (instanceOf (JsonNodeClaim .class )));
294+ assertThat (claim .isNull (), is (false ));
295+ }
296+
297+ @ Test
298+ public void shouldReturnNonNullClaimWhenParsingStringValue () throws Exception {
299+ JsonNode value = mapper .valueToTree ("" );
300+ Claim claim = claimFromNode (value );
301+
302+ assertThat (claim , is (notNullValue ()));
303+ assertThat (claim , is (instanceOf (JsonNodeClaim .class )));
304+ assertThat (claim .isNull (), is (false ));
305+ }
306+
307+ @ Test
308+ public void shouldReturnNonNullClaimWhenParsingIntValue () throws Exception {
309+ JsonNode value = mapper .valueToTree (Integer .MAX_VALUE );
310+ Claim claim = claimFromNode (value );
311+
312+ assertThat (claim , is (notNullValue ()));
313+ assertThat (claim , is (instanceOf (JsonNodeClaim .class )));
314+ assertThat (claim .isNull (), is (false ));
315+ }
316+
317+ @ Test
318+ public void shouldReturnNonNullClaimWhenParsingDoubleValue () throws Exception {
319+ JsonNode value = mapper .valueToTree (Double .MAX_VALUE );
320+ Claim claim = claimFromNode (value );
321+
322+ assertThat (claim , is (notNullValue ()));
323+ assertThat (claim , is (instanceOf (JsonNodeClaim .class )));
324+ assertThat (claim .isNull (), is (false ));
325+ }
326+
327+ @ Test
328+ public void shouldReturnNonNullClaimWhenParsingDateValue () throws Exception {
329+ JsonNode value = mapper .valueToTree (new Date ());
330+ Claim claim = claimFromNode (value );
331+
332+ assertThat (claim , is (notNullValue ()));
333+ assertThat (claim , is (instanceOf (JsonNodeClaim .class )));
334+ assertThat (claim .isNull (), is (false ));
335+ }
336+
337+ @ Test
338+ public void shouldReturnNonNullClaimWhenParsingBooleanValue () throws Exception {
339+ JsonNode value = mapper .valueToTree (Boolean .TRUE );
340+ Claim claim = claimFromNode (value );
341+
342+ assertThat (claim , is (notNullValue ()));
343+ assertThat (claim , is (instanceOf (JsonNodeClaim .class )));
344+ assertThat (claim .isNull (), is (false ));
278345 }
279346}
0 commit comments