55import org .junit .Test ;
66import org .junit .rules .ExpectedException ;
77
8- import java .util .Date ;
9- import java .util .HashMap ;
10- import java .util .Map ;
8+ import java .util .*;
119
1210import static org .hamcrest .Matchers .is ;
1311import static org .hamcrest .Matchers .notNullValue ;
@@ -153,14 +151,6 @@ public void shouldThrowOnNullCustomClaimName() throws Exception {
153151 .withClaim (null , "value" );
154152 }
155153
156- @ Test
157- public void shouldThrowOnIllegalCustomClaimValueClass () throws Exception {
158- exception .expect (IllegalArgumentException .class );
159- exception .expectMessage ("The Custom Claim's value class must be an instance of Integer, Double, Boolean, Date or String." );
160- JWTCreator .init ()
161- .withClaim ("name" , new Object ());
162- }
163-
164154 @ Test
165155 public void shouldAcceptCustomClaimOfTypeString () throws Exception {
166156 String jwt = JWTCreator .init ()
@@ -217,4 +207,47 @@ public void shouldAcceptCustomClaimOfTypeDate() throws Exception {
217207 assertThat (jwt , is (token ));
218208 }
219209
210+ @ Test
211+ public void shouldAcceptCustomClaimOfTypeArray () throws Exception {
212+ String jwt = JWTCreator .init ()
213+ .withClaim ("name" , new Object []{"text" , 123 , true })
214+ .sign (Algorithm .HMAC256 ("secret" ));
215+ String token = "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjpbInRleHQiLDEyMyx0cnVlXX0.uSulPFzLSbgfG8Lpr0jq0JDMhDlGGeQrx09PHEymu1E" ;
216+
217+ assertThat (jwt , is (notNullValue ()));
218+ assertThat (jwt , is (token ));
219+ }
220+
221+ @ Test
222+ public void shouldAcceptCustomClaimOfTypeList () throws Exception {
223+ String jwt = JWTCreator .init ()
224+ .withClaim ("name" , Arrays .asList ("text" , 123 , true ))
225+ .sign (Algorithm .HMAC256 ("secret" ));
226+ String token = "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjpbInRleHQiLDEyMyx0cnVlXX0.uSulPFzLSbgfG8Lpr0jq0JDMhDlGGeQrx09PHEymu1E" ;
227+
228+ assertThat (jwt , is (notNullValue ()));
229+ assertThat (jwt , is (token ));
230+ }
231+
232+ @ Test
233+ public void shouldAcceptCustomClaimOfTypeMap () throws Exception {
234+ String jwt = JWTCreator .init ()
235+ .withClaim ("name" , Collections .singletonMap ("value" , new Object []{"text" , 123 , true }))
236+ .sign (Algorithm .HMAC256 ("secret" ));
237+ String token = "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjp7InZhbHVlIjpbInRleHQiLDEyMyx0cnVlXX19.CtZqZMoG__8yJQisT__pcv3NlynrkDl6qvq4sERx6D0" ;
238+
239+ assertThat (jwt , is (notNullValue ()));
240+ assertThat (jwt , is (token ));
241+ }
242+
243+ @ Test
244+ public void shouldAcceptCustomClaimOfTypeObject () throws Exception {
245+ String jwt = JWTCreator .init ()
246+ .withClaim ("name" , new UserPojo ("john" , 123 ))
247+ .sign (Algorithm .HMAC256 ("secret" ));
248+ String token = "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjp7Im5hbWUiOiJqb2huIiwiaWQiOjEyM319.4ar5Q2vy8h7mw-FjFp1XRoiiKQrrPqdrSqEfATCGmNM" ;
249+
250+ assertThat (jwt , is (notNullValue ()));
251+ assertThat (jwt , is (token ));
252+ }
220253}
0 commit comments