Skip to content

Commit

Permalink
nit cleanup - use statically imported mapper method, suppress warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyjames committed Apr 25, 2024
1 parent a9d193b commit 07a39af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/auth0/client/auth/AuthAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.Map;
import java.util.Objects;

import static com.auth0.json.ObjectMapperProvider.getMapper;

/**
* Class that provides an implementation of of the Authentication and Authorization API methods defined by the
* <a href="https://auth0.com/docs/api/authentication">Auth0 Authentication API</a>.
Expand Down Expand Up @@ -307,7 +309,7 @@ public Request<PushedAuthorizationResponse> pushedAuthorizationRequest(String re
}
try {
if (Objects.nonNull(authorizationDetails)) {
String authDetailsJson = ObjectMapperProvider.getMapper().writeValueAsString(authorizationDetails);
String authDetailsJson = getMapper().writeValueAsString(authorizationDetails);
request.addParameter("authorization_details", authDetailsJson);
}
} catch (JsonProcessingException e) {
Expand Down Expand Up @@ -359,7 +361,7 @@ public Request<PushedAuthorizationResponse> pushedAuthorizationRequestWithJAR(St

try {
if (Objects.nonNull(authorizationDetails)) {
String authDetailsJson = ObjectMapperProvider.getMapper().writeValueAsString(authorizationDetails);
String authDetailsJson = getMapper().writeValueAsString(authorizationDetails);
req.addParameter("authorization_details", authDetailsJson);
}
} catch (JsonProcessingException e) {
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/com/auth0/client/auth/AuthAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public void shouldCreateUserInfoRequest() throws Exception {
assertThat(response.getValues(), hasEntry("created_at", "2016-12-05T11:16:59.640Z"));
assertThat(response.getValues(), hasEntry("sub", "auth0|58454..."));
assertThat(response.getValues(), hasKey("identities"));
@SuppressWarnings("unchecked")
List<Map<String, Object>> identities = (List<Map<String, Object>>) response.getValues().get("identities");
assertThat(identities, hasSize(1));
assertThat(identities.get(0), hasEntry("user_id", "58454..."));
Expand Down Expand Up @@ -501,6 +502,7 @@ public void shouldCreateSignUpRequestWithCustomParameters() throws Exception {
assertThat(body, hasEntry("connection", "db-connection"));
assertThat(body, hasEntry("client_id", CLIENT_ID));
assertThat(body, hasKey("user_metadata"));
@SuppressWarnings("unchecked")
Map<String, String> metadata = (Map<String, String>) body.get("user_metadata");
assertThat(metadata, hasEntry("age", "25"));
assertThat(metadata, hasEntry("address", "123, fake street"));
Expand Down Expand Up @@ -1008,6 +1010,7 @@ public void shouldCreateStartEmailPasswordlessFlowRequestWithCustomParams() thro
assertThat(body, hasEntry("client_secret", CLIENT_SECRET));
assertThat(body, hasEntry("email", "[email protected]"));
assertThat(body, hasKey("authParams"));
@SuppressWarnings("unchecked")
Map<String, String> authParamsSent = (Map<String, String>) body.get("authParams");
assertThat(authParamsSent, hasEntry("scope", authParams.get("scope")));
assertThat(authParamsSent, hasEntry("state", authParams.get("state")));
Expand Down Expand Up @@ -1797,11 +1800,11 @@ public void shouldCreatePushedAuthorizationRequestWithAuthDetails() throws Excep
}

@Test
@SuppressWarnings("unchecked")
public void shouldThrowWhenCreatePushedAuthorizationRequestWithInvalidAuthDetails() {
// force Jackson to throw error on serialization
// see https://stackoverflow.com/questions/26716020/how-to-get-a-jsonprocessingexception-using-jackson
List mockList = mock(List.class);
@SuppressWarnings("unchecked")
List<Map<String, Object>> mockList = mock(List.class);
when(mockList.toString()).thenReturn(mockList.getClass().getName());

IllegalArgumentException e = verifyThrows(IllegalArgumentException.class,
Expand Down

0 comments on commit 07a39af

Please sign in to comment.