From af55bf6117c7e10582e62470d897820f7ad979fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Wed, 12 Sep 2018 09:19:52 +0200 Subject: [PATCH] Give name to initialization --- .../sonia/scm/api/v2/resources/ScmPathInfoStore.java | 10 +++++----- .../main/java/sonia/scm/api/rest/UriInfoFilter.java | 2 +- .../v2/resources/GroupCollectionToDtoMapperTest.java | 2 +- .../scm/api/v2/resources/ScmPathInfoStoreTest.java | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/api/v2/resources/ScmPathInfoStore.java b/scm-core/src/main/java/sonia/scm/api/v2/resources/ScmPathInfoStore.java index caa1183378..c6854e7117 100644 --- a/scm-core/src/main/java/sonia/scm/api/v2/resources/ScmPathInfoStore.java +++ b/scm-core/src/main/java/sonia/scm/api/v2/resources/ScmPathInfoStore.java @@ -4,17 +4,17 @@ import javax.ws.rs.core.UriInfo; public class ScmPathInfoStore { - private UriInfo uriInfo; + private ScmPathInfo pathInfo; public ScmPathInfo get() { - return () -> uriInfo.getBaseUri(); + return pathInfo; } - public void set(UriInfo uriInfo) { - if (this.uriInfo != null) { + public void setFromRestRequest(UriInfo uriInfo) { + if (this.pathInfo != null) { throw new IllegalStateException("UriInfo already set"); } - this.uriInfo = uriInfo; + this.pathInfo = uriInfo::getBaseUri; } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/UriInfoFilter.java b/scm-webapp/src/main/java/sonia/scm/api/rest/UriInfoFilter.java index 1683d5c11a..a0b5644a05 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/UriInfoFilter.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/UriInfoFilter.java @@ -19,6 +19,6 @@ public class UriInfoFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { - storeProvider.get().set(requestContext.getUriInfo()); + storeProvider.get().setFromRestRequest(requestContext.getUriInfo()); } } diff --git a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/GroupCollectionToDtoMapperTest.java b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/GroupCollectionToDtoMapperTest.java index b6dcf6d809..41faa49568 100644 --- a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/GroupCollectionToDtoMapperTest.java +++ b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/GroupCollectionToDtoMapperTest.java @@ -41,7 +41,7 @@ public class GroupCollectionToDtoMapperTest { @Before public void init() throws URISyntaxException { - scmPathInfoStore.set(uriInfo); + scmPathInfoStore.setFromRestRequest(uriInfo); URI baseUri = new URI("http://example.com/base/"); expectedBaseUri = baseUri.resolve(GroupRootResource.GROUPS_PATH_V2 + "/"); when(uriInfo.getBaseUri()).thenReturn(baseUri); diff --git a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/ScmPathInfoStoreTest.java b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/ScmPathInfoStoreTest.java index 4c3f49d2fd..1058dc182b 100644 --- a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/ScmPathInfoStoreTest.java +++ b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/ScmPathInfoStoreTest.java @@ -20,7 +20,7 @@ public class ScmPathInfoStoreTest { when(uriInfo.getBaseUri()).thenReturn(someUri); - scmPathInfoStore.set(uriInfo); + scmPathInfoStore.setFromRestRequest(uriInfo); assertSame(someUri, scmPathInfoStore.get().getApiRestUri()); } @@ -30,7 +30,7 @@ public class ScmPathInfoStoreTest { UriInfo uriInfo = mock(UriInfo.class); ScmPathInfoStore scmPathInfoStore = new ScmPathInfoStore(); - scmPathInfoStore.set(uriInfo); - scmPathInfoStore.set(uriInfo); + scmPathInfoStore.setFromRestRequest(uriInfo); + scmPathInfoStore.setFromRestRequest(uriInfo); } }