-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #917 from alphagov/bau-reduce-ObjectMapper-instant…
…iation bau: Reduce ObjectMapper instantiation
- Loading branch information
Showing
24 changed files
with
277 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,20 @@ | |
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.IsNull.notNullValue; | ||
|
||
public class CreateUserRequestTest { | ||
class CreateUserRequestTest { | ||
|
||
private static ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Test | ||
public void shouldConstructAUser_fromMinimalValidUserJson() throws Exception { | ||
void shouldConstructAUser_fromMinimalValidUserJson() throws Exception { | ||
String minimumUserJson = "{" + | ||
"\"username\": \"a-username\"," + | ||
"\"telephone_number\": \"2123524\"," + | ||
"\"gateway_account_ids\": [\"1\", \"2\"]," + | ||
"\"email\": \"[email protected]\"" + | ||
"}"; | ||
|
||
JsonNode jsonNode = new ObjectMapper().readTree(minimumUserJson); | ||
JsonNode jsonNode = objectMapper.readTree(minimumUserJson); | ||
CreateUserRequest createUserRequest = CreateUserRequest.from(jsonNode); | ||
|
||
assertThat(createUserRequest.getUsername(), is("a-username")); | ||
|
@@ -33,7 +35,7 @@ public void shouldConstructAUser_fromMinimalValidUserJson() throws Exception { | |
} | ||
|
||
@Test | ||
public void shouldConstructAUser_fromCompleteValidUserJson() throws Exception { | ||
void shouldConstructAUser_fromCompleteValidUserJson() throws Exception { | ||
String minimunUserJson = "{" + | ||
"\"username\": \"a-username\"," + | ||
"\"password\": \"a-password\"," + | ||
|
@@ -43,7 +45,7 @@ public void shouldConstructAUser_fromCompleteValidUserJson() throws Exception { | |
"\"email\": \"[email protected]\"" + | ||
"}"; | ||
|
||
JsonNode jsonNode = new ObjectMapper().readTree(minimunUserJson); | ||
JsonNode jsonNode = objectMapper.readTree(minimunUserJson); | ||
CreateUserRequest createUserRequest = CreateUserRequest.from(jsonNode); | ||
|
||
assertThat(createUserRequest.getUsername(), is("a-username")); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,9 @@ | |
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.IsNull.nullValue; | ||
|
||
public class UpdateMerchantDetailsRequestTest { | ||
class UpdateMerchantDetailsRequestTest { | ||
|
||
private static ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
private final String name = "name"; | ||
private final String telephoneNumber = "03069990000"; | ||
|
@@ -22,14 +24,14 @@ public class UpdateMerchantDetailsRequestTest { | |
private final String email = "[email protected]"; | ||
|
||
@Test | ||
public void shouldConstructMerchantDetails_fromMinimalValidJson() { | ||
void shouldConstructMerchantDetails_fromMinimalValidJson() { | ||
Map<String, Object> payload = Map.of( | ||
"name", name, | ||
"address_line1", addressLine1, | ||
"address_city", addressCity, | ||
"address_country", addressCountry, | ||
"address_postcode", addressPostcode); | ||
JsonNode jsonNode = new ObjectMapper().valueToTree(payload); | ||
JsonNode jsonNode = objectMapper.valueToTree(payload); | ||
UpdateMerchantDetailsRequest updateMerchantDetailsRequest = UpdateMerchantDetailsRequest.from(jsonNode); | ||
assertThat(updateMerchantDetailsRequest.getName(), is(name)); | ||
assertThat(updateMerchantDetailsRequest.getAddressLine1(), is(addressLine1)); | ||
|
@@ -40,7 +42,7 @@ public void shouldConstructMerchantDetails_fromMinimalValidJson() { | |
} | ||
|
||
@Test | ||
public void shouldConstructMerchantDetails_fromCompleteValidJson() { | ||
void shouldConstructMerchantDetails_fromCompleteValidJson() { | ||
Map<String, Object> payload = Map.of( | ||
"name", name, | ||
"telephone_number", telephoneNumber, | ||
|
@@ -50,7 +52,7 @@ public void shouldConstructMerchantDetails_fromCompleteValidJson() { | |
"address_country", addressCountry, | ||
"address_postcode", addressPostcode, | ||
"email", email); | ||
JsonNode jsonNode = new ObjectMapper().valueToTree(payload); | ||
JsonNode jsonNode = objectMapper.valueToTree(payload); | ||
UpdateMerchantDetailsRequest updateMerchantDetailsRequest = UpdateMerchantDetailsRequest.from(jsonNode); | ||
assertThat(updateMerchantDetailsRequest.getName(), is(name)); | ||
assertThat(updateMerchantDetailsRequest.getTelephoneNumber(), is(telephoneNumber)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,18 +18,20 @@ | |
import static uk.gov.pay.adminusers.model.Permission.permission; | ||
import static uk.gov.pay.adminusers.model.Role.role; | ||
|
||
public class UserEntityTest { | ||
class UserEntityTest { | ||
|
||
private static ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Test | ||
public void shouldConstructAUser_fromMinimalValidUserJson() throws Exception { | ||
void shouldConstructAUser_fromMinimalValidUserJson() throws Exception { | ||
String minimumUserJson = "{" + | ||
"\"username\": \"a-username\"," + | ||
"\"telephone_number\": \"+441134960000\"," + | ||
"\"gateway_account_ids\": [\"1\", \"2\"]," + | ||
"\"email\": \"[email protected]\"" + | ||
"}"; | ||
|
||
JsonNode jsonNode = new ObjectMapper().readTree(minimumUserJson); | ||
JsonNode jsonNode = objectMapper.readTree(minimumUserJson); | ||
CreateUserRequest createUserRequest = CreateUserRequest.from(jsonNode); | ||
|
||
UserEntity userEntity = UserEntity.from(createUserRequest); | ||
|
@@ -46,7 +48,7 @@ public void shouldConstructAUser_fromMinimalValidUserJson() throws Exception { | |
} | ||
|
||
@Test | ||
public void creatingAUser_shouldSetGatewayAccountAndRole_whenServiceRoleIsSet() { | ||
void creatingAUser_shouldSetGatewayAccountAndRole_whenServiceRoleIsSet() { | ||
UserEntity userEntity = new UserEntity(); | ||
String gatewayAccountId = "1"; | ||
ServiceEntity service = new ServiceEntity(List.of(gatewayAccountId)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package uk.gov.pay.adminusers.resources; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Test; | ||
import uk.gov.pay.adminusers.fixtures.ServiceDbFixture; | ||
import uk.gov.pay.adminusers.model.MerchantDetails; | ||
|
@@ -11,7 +10,6 @@ | |
|
||
public class EmailResourceIT extends IntegrationTest { | ||
|
||
private ObjectMapper objectMapper = new ObjectMapper(); | ||
private static final String GATEWAY_ACCOUNT_ID = "DIRECT_DEBIT:mdshfsehdtfsdtjg"; | ||
private Map<String, Object> validEmailRequest = Map.of( | ||
"address", "[email protected]", | ||
|
@@ -32,7 +30,7 @@ public void shouldReceiveAPayloadAndSendEmail() { | |
"postcode", "country", "[email protected]" | ||
)) | ||
.insertService(); | ||
String body = objectMapper.valueToTree(validEmailRequest).toString(); | ||
String body = mapper.valueToTree(validEmailRequest).toString(); | ||
givenSetup() | ||
.when() | ||
.accept(JSON) | ||
|
Oops, something went wrong.