Give name to initialization

This commit is contained in:
René Pfeuffer
2018-09-12 09:19:52 +02:00
parent 7c09f35ac8
commit af55bf6117
4 changed files with 10 additions and 10 deletions

View File

@@ -4,17 +4,17 @@ import javax.ws.rs.core.UriInfo;
public class ScmPathInfoStore { public class ScmPathInfoStore {
private UriInfo uriInfo; private ScmPathInfo pathInfo;
public ScmPathInfo get() { public ScmPathInfo get() {
return () -> uriInfo.getBaseUri(); return pathInfo;
} }
public void set(UriInfo uriInfo) { public void setFromRestRequest(UriInfo uriInfo) {
if (this.uriInfo != null) { if (this.pathInfo != null) {
throw new IllegalStateException("UriInfo already set"); throw new IllegalStateException("UriInfo already set");
} }
this.uriInfo = uriInfo; this.pathInfo = uriInfo::getBaseUri;
} }
} }

View File

@@ -19,6 +19,6 @@ public class UriInfoFilter implements ContainerRequestFilter {
@Override @Override
public void filter(ContainerRequestContext requestContext) { public void filter(ContainerRequestContext requestContext) {
storeProvider.get().set(requestContext.getUriInfo()); storeProvider.get().setFromRestRequest(requestContext.getUriInfo());
} }
} }

View File

@@ -41,7 +41,7 @@ public class GroupCollectionToDtoMapperTest {
@Before @Before
public void init() throws URISyntaxException { public void init() throws URISyntaxException {
scmPathInfoStore.set(uriInfo); scmPathInfoStore.setFromRestRequest(uriInfo);
URI baseUri = new URI("http://example.com/base/"); URI baseUri = new URI("http://example.com/base/");
expectedBaseUri = baseUri.resolve(GroupRootResource.GROUPS_PATH_V2 + "/"); expectedBaseUri = baseUri.resolve(GroupRootResource.GROUPS_PATH_V2 + "/");
when(uriInfo.getBaseUri()).thenReturn(baseUri); when(uriInfo.getBaseUri()).thenReturn(baseUri);

View File

@@ -20,7 +20,7 @@ public class ScmPathInfoStoreTest {
when(uriInfo.getBaseUri()).thenReturn(someUri); when(uriInfo.getBaseUri()).thenReturn(someUri);
scmPathInfoStore.set(uriInfo); scmPathInfoStore.setFromRestRequest(uriInfo);
assertSame(someUri, scmPathInfoStore.get().getApiRestUri()); assertSame(someUri, scmPathInfoStore.get().getApiRestUri());
} }
@@ -30,7 +30,7 @@ public class ScmPathInfoStoreTest {
UriInfo uriInfo = mock(UriInfo.class); UriInfo uriInfo = mock(UriInfo.class);
ScmPathInfoStore scmPathInfoStore = new ScmPathInfoStore(); ScmPathInfoStore scmPathInfoStore = new ScmPathInfoStore();
scmPathInfoStore.set(uriInfo); scmPathInfoStore.setFromRestRequest(uriInfo);
scmPathInfoStore.set(uriInfo); scmPathInfoStore.setFromRestRequest(uriInfo);
} }
} }