File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
main/java/com/bastiaanjansen/jwt
test/java/com/bastiaanjansen/jwt Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ public Map<String, Object> getAsMap() {
2222 }
2323
2424 public String base64Encoded () {
25- return Base64Utils .encodeBase64URL (new JSONObject (claims ).toString ());
25+ String json = new JSONObject (claims ).toString ();
26+ return Base64Utils .encodeBase64URL (json );
2627 }
2728
2829 public Object getClaim (String name ) {
Original file line number Diff line number Diff line change @@ -128,4 +128,36 @@ void base64EncodedWithIssuer() {
128128
129129 assertThat (payload .base64Encoded (), is (expected ));
130130 }
131+
132+ @ Test
133+ void getClaimAsString () {
134+ payload .addClaim ("key" , "value" );
135+ String expected = "value" ;
136+
137+ assertThat (payload .getClaim ("key" , String .class ), is (expected ));
138+ }
139+
140+ @ Test
141+ void getClaimAsInteger () {
142+ payload .addClaim ("key" , 100 );
143+ int expected = 100 ;
144+
145+ assertThat (payload .getClaim ("key" , Integer .class ), is (expected ));
146+ }
147+
148+ @ Test
149+ void getClaimAsLong () {
150+ payload .addClaim ("key" , 100L );
151+ long expected = 100 ;
152+
153+ assertThat (payload .getClaim ("key" , Long .class ), is (expected ));
154+ }
155+
156+ @ Test
157+ void getClaimConverted () {
158+ payload .addClaim ("key" , "value" );
159+ String expected = "VALUE" ;
160+
161+ assertThat (payload .getClaim ("key" , value -> String .valueOf (value ).toUpperCase ()), is (expected ));
162+ }
131163}
You can’t perform that action at this time.
0 commit comments