99import org .junit .rules .ExpectedException ;
1010
1111import java .util .Date ;
12+ import java .util .HashMap ;
13+ import java .util .Map ;
1214
1315import static org .hamcrest .Matchers .*;
1416import static org .junit .Assert .assertThat ;
@@ -170,6 +172,7 @@ public void shouldThrowOnInvalidCustomClaimValueOfTypeBoolean() throws Exception
170172 .verify (token );
171173 }
172174
175+
173176 @ Test
174177 public void shouldThrowOnInvalidCustomClaimValueOfTypeDate () throws Exception {
175178 exception .expect (InvalidClaimException .class );
@@ -181,6 +184,17 @@ public void shouldThrowOnInvalidCustomClaimValueOfTypeDate() throws Exception {
181184 .verify (token );
182185 }
183186
187+ @ Test
188+ public void shouldThrowOnInvalidCustomClaimValue () throws Exception {
189+ exception .expect (InvalidClaimException .class );
190+ exception .expectMessage ("The Claim 'name' value doesn't match the required one." );
191+ String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjpbInNvbWV0aGluZyJdfQ.3ENLez6tU_fG0SVFrGmISltZPiXLSHaz_dyn-XFTEGQ" ;
192+ Map <String , Object > map = new HashMap <>();
193+ map .put ("name" , new Object ());
194+ JWTVerifier verifier = new JWTVerifier (Algorithm .HMAC256 ("secret" ), map , new Clock ());
195+ verifier .verify (token );
196+ }
197+
184198 @ Test
185199 public void shouldValidateCustomClaimOfTypeString () throws Exception {
186200 String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoidmFsdWUifQ.Jki8pvw6KGbxpMinufrgo6RDL1cu7AtNMJYVh6t-_cE" ;
@@ -239,6 +253,7 @@ public void shouldValidateCustomClaimOfTypeDate() throws Exception {
239253
240254
241255 // Generic Delta
256+ @ SuppressWarnings ("RedundantCast" )
242257 @ Test
243258 public void shouldAddDefaultTimeDeltaToDateClaims () throws Exception {
244259 Algorithm algorithm = mock (Algorithm .class );
@@ -251,6 +266,7 @@ public void shouldAddDefaultTimeDeltaToDateClaims() throws Exception {
251266 assertThat (verifier .claims , hasEntry ("nbf" , (Object ) 0L ));
252267 }
253268
269+ @ SuppressWarnings ("RedundantCast" )
254270 @ Test
255271 public void shouldAddCustomTimeDeltaToDateClaims () throws Exception {
256272 Algorithm algorithm = mock (Algorithm .class );
@@ -264,6 +280,7 @@ public void shouldAddCustomTimeDeltaToDateClaims() throws Exception {
264280 assertThat (verifier .claims , hasEntry ("nbf" , (Object ) 1234L ));
265281 }
266282
283+ @ SuppressWarnings ("RedundantCast" )
267284 @ Test
268285 public void shouldOverrideDefaultIssuedAtTimeDelta () throws Exception {
269286 Algorithm algorithm = mock (Algorithm .class );
@@ -278,6 +295,7 @@ public void shouldOverrideDefaultIssuedAtTimeDelta() throws Exception {
278295 assertThat (verifier .claims , hasEntry ("nbf" , (Object ) 1234L ));
279296 }
280297
298+ @ SuppressWarnings ("RedundantCast" )
281299 @ Test
282300 public void shouldOverrideDefaultExpiresAtTimeDelta () throws Exception {
283301 Algorithm algorithm = mock (Algorithm .class );
@@ -292,6 +310,7 @@ public void shouldOverrideDefaultExpiresAtTimeDelta() throws Exception {
292310 assertThat (verifier .claims , hasEntry ("nbf" , (Object ) 1234L ));
293311 }
294312
313+ @ SuppressWarnings ("RedundantCast" )
295314 @ Test
296315 public void shouldOverrideDefaultNotBeforeTimeDelta () throws Exception {
297316 Algorithm algorithm = mock (Algorithm .class );
0 commit comments