diff --git a/src/main/java/uk/gov/hmcts/reform/idam/web/UserController.java b/src/main/java/uk/gov/hmcts/reform/idam/web/UserController.java index 217894847..cfde55615 100644 --- a/src/main/java/uk/gov/hmcts/reform/idam/web/UserController.java +++ b/src/main/java/uk/gov/hmcts/reform/idam/web/UserController.java @@ -33,6 +33,7 @@ import uk.gov.hmcts.reform.idam.web.strategic.SPIService; import uk.gov.hmcts.reform.idam.web.strategic.ValidationService; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -313,7 +314,7 @@ public ModelAndView activateUser(@RequestParam("token") String token, @RequestPa } @GetMapping("/useractivated") - public String userActivated(@RequestParam(required = false) final String redirectUri, final Map model) { + public String userActivated(@RequestParam(required = false) final String redirectUri, @Nonnull final Map model) { if (redirectUri != null) { model.put("redirectUri", redirectUri); } diff --git a/src/test/java/uk/gov/hmcts/reform/idam/web/UserControllerTest.java b/src/test/java/uk/gov/hmcts/reform/idam/web/UserControllerTest.java index 5460709e9..4242f6707 100644 --- a/src/test/java/uk/gov/hmcts/reform/idam/web/UserControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/idam/web/UserControllerTest.java @@ -18,14 +18,17 @@ import uk.gov.hmcts.reform.idam.web.strategic.SPIService; import uk.gov.hmcts.reform.idam.web.strategic.ValidationService; +import java.util.HashMap; import java.util.Map; import java.util.Optional; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -542,4 +545,27 @@ public void buildRegistrationLink_shouldBuildLinkIfRedirecturiAndClientidArePres new ActivationResult().redirectUri(GOOGLE_WEB_ADDRESS).clientId(CLIENT_ID)), is("/users/selfRegister?redirect_uri=https://www.google.com&client_id=clientId")); } + + @Test + public void userActivated_shouldReturnCorrectValue() { + UserController userController = new UserController(); + String result; + Map model = new HashMap<>(); + + result = userController.userActivated(null, model); + assertEquals("useractivated", result); + assertTrue(model.isEmpty()); + + model.clear(); + result = userController.userActivated("uri", model); + assertEquals("useractivated", result); + assertEquals(1, model.size()); + assertEquals("uri", model.get("redirectUri")); + } + + @Test + public void expiredToken_shouldReturnCorrectValue() { + UserController userController = new UserController(); + assertEquals("expiredtoken", userController.expiredToken(null)); + } }