mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 10:41:06 +01:00
Fix test for pagination
This commit is contained in:
@@ -63,14 +63,14 @@ public class UserCollectionToDtoMapperTest {
|
||||
@Test
|
||||
public void shouldSetPageNumber() {
|
||||
PageResult<User> pageResult = mockPageResult("Hannes");
|
||||
UserCollectionDto userCollectionDto = mapper.map(1, 1, pageResult);
|
||||
assertEquals(1, userCollectionDto.getPage());
|
||||
UserCollectionDto userCollectionDto = mapper.map(0, 1, pageResult);
|
||||
assertEquals(0, userCollectionDto.getPage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveSelfLink() {
|
||||
PageResult<User> pageResult = mockPageResult("Hannes");
|
||||
UserCollectionDto userCollectionDto = mapper.map(1, 1, pageResult);
|
||||
UserCollectionDto userCollectionDto = mapper.map(0, 1, pageResult);
|
||||
assertTrue(userCollectionDto.getLinks().getLinkBy("self").get().getHref().startsWith(expectedBaseUri.toString()));
|
||||
}
|
||||
|
||||
@@ -78,15 +78,15 @@ public class UserCollectionToDtoMapperTest {
|
||||
public void shouldCreateNextPageLink_whenHasMore() {
|
||||
PageResult<User> pageResult = createPage(createUsers("Hannes", "Karl"), 0, 1);
|
||||
|
||||
UserCollectionDto userCollectionDto = mapper.map(1, 1, pageResult);
|
||||
assertTrue(userCollectionDto.getLinks().getLinkBy("next").get().getHref().contains("page=2"));
|
||||
UserCollectionDto userCollectionDto = mapper.map(0, 1, pageResult);
|
||||
assertTrue(userCollectionDto.getLinks().getLinkBy("next").get().getHref().contains("page=1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCreateNextPageLink_whenNoMore() {
|
||||
PageResult<User> pageResult = mockPageResult("Hannes");
|
||||
UserCollectionDto userCollectionDto = mapper.map(1, 1, pageResult);
|
||||
assertFalse(userCollectionDto.getLinks().stream().anyMatch(link -> link.getHref().contains("page=2")));
|
||||
PageResult<User> pageResult = mockPageResult("Hannes", "Wurst", "X");
|
||||
UserCollectionDto userCollectionDto = mapper.map(0, 10, pageResult);
|
||||
assertFalse(userCollectionDto.getLinks().getLinkBy("next").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,7 +94,7 @@ public class UserCollectionToDtoMapperTest {
|
||||
PageResult<User> pageResult = mockPageResult("Hannes");
|
||||
when(subject.isPermitted("user:create")).thenReturn(true);
|
||||
|
||||
UserCollectionDto userCollectionDto = mapper.map(1, 1, pageResult);
|
||||
UserCollectionDto userCollectionDto = mapper.map(0, 1, pageResult);
|
||||
|
||||
assertTrue(userCollectionDto.getLinks().getLinkBy("create").isPresent());
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class UserCollectionToDtoMapperTest {
|
||||
PageResult<User> pageResult = mockPageResult("Hannes");
|
||||
when(subject.isPermitted("user:create")).thenReturn(false);
|
||||
|
||||
UserCollectionDto userCollectionDto = mapper.map(1, 1, pageResult);
|
||||
UserCollectionDto userCollectionDto = mapper.map(0, 1, pageResult);
|
||||
|
||||
assertFalse(userCollectionDto.getLinks().getLinkBy("create").isPresent());
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class UserCollectionToDtoMapperTest {
|
||||
@Test
|
||||
public void shouldMapUsers() {
|
||||
PageResult<User> pageResult = mockPageResult("Hannes", "Wurst");
|
||||
UserCollectionDto userCollectionDto = mapper.map(1, 2, pageResult);
|
||||
UserCollectionDto userCollectionDto = mapper.map(0, 2, pageResult);
|
||||
List<HalRepresentation> users = userCollectionDto.getEmbedded().getItemsBy("users");
|
||||
assertEquals(2, users.size());
|
||||
assertEquals("Hannes", ((UserDto) users.get(0)).getName());
|
||||
|
||||
Reference in New Issue
Block a user