Skip to content

Commit

Permalink
Increase code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Radoslaw Orlowski committed May 15, 2020
1 parent 3ada921 commit ff623b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> model) {
public String userActivated(@RequestParam(required = false) final String redirectUri, @Nonnull final Map<String, Object> model) {
if (redirectUri != null) {
model.put("redirectUri", redirectUri);
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/uk/gov/hmcts/reform/idam/web/UserControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> 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));
}
}

0 comments on commit ff623b2

Please sign in to comment.