From 07a39af0089d71042afb9e568c1b3a070fb8aa48 Mon Sep 17 00:00:00 2001 From: Jim Anderson Date: Thu, 25 Apr 2024 17:33:14 -0500 Subject: [PATCH] nit cleanup - use statically imported mapper method, suppress warnings --- src/main/java/com/auth0/client/auth/AuthAPI.java | 6 ++++-- src/test/java/com/auth0/client/auth/AuthAPITest.java | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/auth0/client/auth/AuthAPI.java b/src/main/java/com/auth0/client/auth/AuthAPI.java index 773a1fba..a9f7a9e9 100644 --- a/src/main/java/com/auth0/client/auth/AuthAPI.java +++ b/src/main/java/com/auth0/client/auth/AuthAPI.java @@ -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 * Auth0 Authentication API. @@ -307,7 +309,7 @@ public Request 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) { @@ -359,7 +361,7 @@ public Request 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) { diff --git a/src/test/java/com/auth0/client/auth/AuthAPITest.java b/src/test/java/com/auth0/client/auth/AuthAPITest.java index 776f356b..6ae92f09 100644 --- a/src/test/java/com/auth0/client/auth/AuthAPITest.java +++ b/src/test/java/com/auth0/client/auth/AuthAPITest.java @@ -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> identities = (List>) response.getValues().get("identities"); assertThat(identities, hasSize(1)); assertThat(identities.get(0), hasEntry("user_id", "58454...")); @@ -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 metadata = (Map) body.get("user_metadata"); assertThat(metadata, hasEntry("age", "25")); assertThat(metadata, hasEntry("address", "123, fake street")); @@ -1008,6 +1010,7 @@ public void shouldCreateStartEmailPasswordlessFlowRequestWithCustomParams() thro assertThat(body, hasEntry("client_secret", CLIENT_SECRET)); assertThat(body, hasEntry("email", "user@domain.com")); assertThat(body, hasKey("authParams")); + @SuppressWarnings("unchecked") Map authParamsSent = (Map) body.get("authParams"); assertThat(authParamsSent, hasEntry("scope", authParams.get("scope"))); assertThat(authParamsSent, hasEntry("state", authParams.get("state"))); @@ -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> mockList = mock(List.class); when(mockList.toString()).thenReturn(mockList.getClass().getName()); IllegalArgumentException e = verifyThrows(IllegalArgumentException.class,