Rename UriInfoStore to ScmPathInfoStore

This commit is contained in:
René Pfeuffer
2018-09-12 08:53:15 +02:00
parent f718a2ba4c
commit 7c09f35ac8
30 changed files with 89 additions and 90 deletions

View File

@@ -29,8 +29,8 @@ import static sonia.scm.PageResult.createPage;
public class GroupCollectionToDtoMapperTest {
private final UriInfo uriInfo = mock(UriInfo.class);
private final UriInfoStore uriInfoStore = new UriInfoStore();
private final ResourceLinks resourceLinks = new ResourceLinks(uriInfoStore);
private final ScmPathInfoStore scmPathInfoStore = new ScmPathInfoStore();
private final ResourceLinks resourceLinks = new ResourceLinks(scmPathInfoStore);
private final GroupToGroupDtoMapper groupToDtoMapper = mock(GroupToGroupDtoMapper.class);
private final Subject subject = mock(Subject.class);
private final ThreadState subjectThreadState = new SubjectThreadState(subject);
@@ -41,7 +41,7 @@ public class GroupCollectionToDtoMapperTest {
@Before
public void init() throws URISyntaxException {
uriInfoStore.set(uriInfo);
scmPathInfoStore.set(uriInfo);
URI baseUri = new URI("http://example.com/base/");
expectedBaseUri = baseUri.resolve(GroupRootResource.GROUPS_PATH_V2 + "/");
when(uriInfo.getBaseUri()).thenReturn(baseUri);

View File

@@ -41,7 +41,7 @@ public class MeResourceTest {
@Mock
private ScmPathInfo uriInfo;
@Mock
private UriInfoStore uriInfoStore;
private ScmPathInfoStore scmPathInfoStore;
@Mock
private UserManager userManager;
@@ -62,7 +62,7 @@ public class MeResourceTest {
MeResource meResource = new MeResource(userToDtoMapper, userManager);
dispatcher.getRegistry().addSingletonResource(meResource);
when(uriInfo.getApiRestUri()).thenReturn(URI.create("/"));
when(uriInfoStore.get()).thenReturn(uriInfo);
when(scmPathInfoStore.get()).thenReturn(uriInfo);
}
@Test

View File

@@ -70,7 +70,7 @@ public class RepositoryRootResourceTest {
@Mock
private RepositoryService service;
@Mock
private UriInfoStore uriInfoStore;
private ScmPathInfoStore scmPathInfoStore;
@Mock
private ScmPathInfo uriInfo;
@@ -91,7 +91,7 @@ public class RepositoryRootResourceTest {
RepositoryCollectionResource repositoryCollectionResource = new RepositoryCollectionResource(repositoryManager, repositoryCollectionToDtoMapper, dtoToRepositoryMapper, resourceLinks);
RepositoryRootResource repositoryRootResource = new RepositoryRootResource(MockProvider.of(repositoryResource), MockProvider.of(repositoryCollectionResource));
when(serviceFactory.create(any(Repository.class))).thenReturn(service);
when(uriInfoStore.get()).thenReturn(uriInfo);
when(scmPathInfoStore.get()).thenReturn(uriInfo);
when(uriInfo.getApiRestUri()).thenReturn(URI.create("/x/y"));
dispatcher = createDispatcher(repositoryRootResource);
}

View File

@@ -48,7 +48,7 @@ public class RepositoryToRepositoryDtoMapperTest {
@Mock
private RepositoryService repositoryService;
@Mock
private UriInfoStore uriInfoStore;
private ScmPathInfoStore scmPathInfoStore;
@Mock
private ScmPathInfo uriInfo;
@@ -61,7 +61,7 @@ public class RepositoryToRepositoryDtoMapperTest {
when(serviceFactory.create(any(Repository.class))).thenReturn(repositoryService);
when(repositoryService.isSupported(any(Command.class))).thenReturn(true);
when(repositoryService.getSupportedProtocols()).thenReturn(emptySet());
when(uriInfoStore.get()).thenReturn(uriInfo);
when(scmPathInfoStore.get()).thenReturn(uriInfo);
when(uriInfo.getApiRestUri()).thenReturn(URI.create("/x/y"));
}

View File

@@ -17,7 +17,7 @@ public class ResourceLinksTest {
private static final String BASE_URL = "http://example.com/";
@Mock
private UriInfoStore uriInfoStore;
private ScmPathInfoStore scmPathInfoStore;
@Mock
private ScmPathInfo uriInfo;
@@ -176,7 +176,7 @@ public class ResourceLinksTest {
@Before
public void initUriInfo() {
initMocks(this);
when(uriInfoStore.get()).thenReturn(uriInfo);
when(scmPathInfoStore.get()).thenReturn(uriInfo);
when(uriInfo.getApiRestUri()).thenReturn(URI.create(BASE_URL));
}
}

View File

@@ -3,35 +3,34 @@ 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;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class UriInfoStoreTest {
public class ScmPathInfoStoreTest {
@Test
public void shouldReturnSetInfo() {
URI someUri = URI.create("/anything");
UriInfo uriInfo = mock(UriInfo.class);
UriInfoStore uriInfoStore = new UriInfoStore();
ScmPathInfoStore scmPathInfoStore = new ScmPathInfoStore();
when(uriInfo.getBaseUri()).thenReturn(someUri);
uriInfoStore.set(uriInfo);
scmPathInfoStore.set(uriInfo);
assertSame(someUri, uriInfoStore.get().getApiRestUri());
assertSame(someUri, scmPathInfoStore.get().getApiRestUri());
}
@Test(expected = IllegalStateException.class)
public void shouldFailIfSetTwice() {
UriInfo uriInfo = mock(UriInfo.class);
UriInfoStore uriInfoStore = new UriInfoStore();
ScmPathInfoStore scmPathInfoStore = new ScmPathInfoStore();
uriInfoStore.set(uriInfo);
uriInfoStore.set(uriInfo);
scmPathInfoStore.set(uriInfo);
scmPathInfoStore.set(uriInfo);
}
}