Move info initialization to filter

This commit is contained in:
René Pfeuffer
2018-09-12 09:23:04 +02:00
parent af55bf6117
commit b809abaa45
4 changed files with 14 additions and 16 deletions

View File

@@ -11,7 +11,6 @@ import org.junit.Test;
import sonia.scm.PageResult;
import sonia.scm.group.Group;
import javax.ws.rs.core.UriInfo;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
@@ -28,7 +27,7 @@ import static sonia.scm.PageResult.createPage;
public class GroupCollectionToDtoMapperTest {
private final UriInfo uriInfo = mock(UriInfo.class);
private final ScmPathInfo uriInfo = mock(ScmPathInfo.class);
private final ScmPathInfoStore scmPathInfoStore = new ScmPathInfoStore();
private final ResourceLinks resourceLinks = new ResourceLinks(scmPathInfoStore);
private final GroupToGroupDtoMapper groupToDtoMapper = mock(GroupToGroupDtoMapper.class);
@@ -41,10 +40,10 @@ public class GroupCollectionToDtoMapperTest {
@Before
public void init() throws URISyntaxException {
scmPathInfoStore.setFromRestRequest(uriInfo);
scmPathInfoStore.set(uriInfo);
URI baseUri = new URI("http://example.com/base/");
expectedBaseUri = baseUri.resolve(GroupRootResource.GROUPS_PATH_V2 + "/");
when(uriInfo.getBaseUri()).thenReturn(baseUri);
when(uriInfo.getApiRestUri()).thenReturn(baseUri);
subjectThreadState.bind();
ThreadContext.bind(subject);
}

View File

@@ -2,7 +2,6 @@ package sonia.scm.api.v2.resources;
import org.junit.Test;
import javax.ws.rs.core.UriInfo;
import java.net.URI;
import static org.junit.Assert.assertSame;
@@ -15,22 +14,22 @@ public class ScmPathInfoStoreTest {
public void shouldReturnSetInfo() {
URI someUri = URI.create("/anything");
UriInfo uriInfo = mock(UriInfo.class);
ScmPathInfo uriInfo = mock(ScmPathInfo.class);
ScmPathInfoStore scmPathInfoStore = new ScmPathInfoStore();
when(uriInfo.getBaseUri()).thenReturn(someUri);
when(uriInfo.getApiRestUri()).thenReturn(someUri);
scmPathInfoStore.setFromRestRequest(uriInfo);
scmPathInfoStore.set(uriInfo);
assertSame(someUri, scmPathInfoStore.get().getApiRestUri());
}
@Test(expected = IllegalStateException.class)
public void shouldFailIfSetTwice() {
UriInfo uriInfo = mock(UriInfo.class);
ScmPathInfo uriInfo = mock(ScmPathInfo.class);
ScmPathInfoStore scmPathInfoStore = new ScmPathInfoStore();
scmPathInfoStore.setFromRestRequest(uriInfo);
scmPathInfoStore.setFromRestRequest(uriInfo);
scmPathInfoStore.set(uriInfo);
scmPathInfoStore.set(uriInfo);
}
}