Fix injection

This commit is contained in:
René Pfeuffer
2019-04-12 15:26:22 +02:00
parent e56d6504c0
commit 20cf0507a2
2 changed files with 12 additions and 14 deletions

View File

@@ -111,9 +111,11 @@ public class AuthenticationResourceTest {
"}"
);
private AuthenticationResource authenticationResource;
@Before
public void prepareEnvironment() {
AuthenticationResource authenticationResource = new AuthenticationResource(accessTokenBuilderFactory, cookieIssuer, null);
authenticationResource = new AuthenticationResource(accessTokenBuilderFactory, cookieIssuer);
dispatcher.getRegistry().addSingletonResource(authenticationResource);
AccessToken accessToken = mock(AccessToken.class);
@@ -200,7 +202,7 @@ public class AuthenticationResourceTest {
@Test
public void shouldHandleLogoutRedirection() throws URISyntaxException, UnsupportedEncodingException {
mockResourceWithLogoutRedirection(of(create("http://example.com/cas/logout")));
authenticationResource.setLogoutRedirection(() -> of(create("http://example.com/cas/logout")));
MockHttpRequest request = MockHttpRequest.delete("/" + AuthenticationResource.PATH + "/access_token");
@@ -212,7 +214,7 @@ public class AuthenticationResourceTest {
@Test
public void shouldHandleDisabledLogoutRedirection() throws URISyntaxException {
mockResourceWithLogoutRedirection(empty());
authenticationResource.setLogoutRedirection(Optional::empty);
MockHttpRequest request = MockHttpRequest.delete("/" + AuthenticationResource.PATH + "/access_token");
@@ -221,13 +223,6 @@ public class AuthenticationResourceTest {
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
}
private void mockResourceWithLogoutRedirection(Optional<URI> target) {
dispatcher.getRegistry().removeRegistrations(AuthenticationResource.class);
AuthenticationResource authenticationResource =
new AuthenticationResource(accessTokenBuilderFactory, cookieIssuer, () -> target);
dispatcher.getRegistry().addSingletonResource(authenticationResource);
}
private void shouldReturnBadRequest(String requestBody) throws URISyntaxException {
MockHttpRequest request = getMockHttpRequest(requestBody);