use of com.auth0.android.jwt.Claim in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldGetAsMapValue.
@SuppressWarnings({ "unchecked", "RedundantCast" })
@Test
public void shouldGetAsMapValue() {
JsonNode value = mapper.valueToTree(Collections.singletonMap("key", new UserPojo("john", 123)));
Claim claim = claimFromNode(value);
assertThat(claim, is(notNullValue()));
Map map = claim.as(Map.class);
assertThat(((Map<String, Object>) map.get("key")), hasEntry("name", (Object) "john"));
assertThat(((Map<String, Object>) map.get("key")), hasEntry("id", (Object) 123));
}
use of com.auth0.android.jwt.Claim in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldGetNullArrayIfNonArrayValue.
@Test
public void shouldGetNullArrayIfNonArrayValue() {
JsonNode value = mapper.valueToTree(1);
Claim claim = claimFromNode(value);
assertThat(claim.asArray(String.class), is(nullValue()));
}
use of com.auth0.android.jwt.Claim in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldConvertToString.
@Test
public void shouldConvertToString() {
JsonNode value = mapper.valueToTree(new UserPojo("john", 123));
JsonNode nullValue = mapper.valueToTree(null);
JsonNode missingValue = MissingNode.getInstance();
Claim claim = claimFromNode(value);
Claim nullClaim = claimFromNode(nullValue);
Claim missingClaim = claimFromNode(missingValue);
assertThat(claim.toString(), is("{\"name\":\"john\",\"id\":123}"));
assertThat(nullClaim.isNull(), is(true));
assertThat(nullClaim.toString(), is("Null claim"));
assertThat(missingClaim.isMissing(), is(true));
assertThat(missingClaim.toString(), is("Missing claim"));
}
use of com.auth0.android.jwt.Claim in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldGetNullArrayIfNullValue.
@Test
public void shouldGetNullArrayIfNullValue() {
JsonNode value = mapper.valueToTree(null);
Claim claim = claimFromNode(value);
assertThat(claim.asArray(String.class), is(nullValue()));
}
use of com.auth0.android.jwt.Claim in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldReturnNonNullClaimWhenParsingBooleanValue.
@Test
public void shouldReturnNonNullClaimWhenParsingBooleanValue() {
JsonNode value = mapper.valueToTree(Boolean.TRUE);
Claim claim = claimFromNode(value);
assertThat(claim, is(notNullValue()));
assertThat(claim, is(instanceOf(JsonNodeClaim.class)));
assertThat(claim.isNull(), is(false));
assertThat(claim.isMissing(), is(false));
}
Aggregations