Adapt unit test

This commit is contained in:
René Pfeuffer
2019-05-31 10:47:50 +02:00
parent 84ae5646a4
commit 55069cf2dd

View File

@@ -89,8 +89,7 @@ class DefaultRepositoryRoleManagerTest {
@BeforeEach @BeforeEach
void authorizeUser() { void authorizeUser() {
when(subject.isPermitted("repositoryRole:read")).thenReturn(true); when(subject.isPermitted("repositoryRole:write")).thenReturn(true);
when(subject.isPermitted("repositoryRole:modify")).thenReturn(true);
} }
@Test @Test
@@ -184,8 +183,15 @@ class DefaultRepositoryRoleManagerTest {
} }
@Test @Test
void shouldThrowException_forGet() { void shouldReturnNull_forNotExistingRole() {
assertThrows(UnauthorizedException.class, () -> manager.get("any")); RepositoryRole role = manager.get("noSuchRole");
assertThat(role).isNull();
}
@Test
void shouldReturnRole_forExistingRole() {
RepositoryRole role = manager.get(CUSTOM_ROLE_NAME);
assertThat(role).isNotNull();
} }
@Test @Test
@@ -201,18 +207,25 @@ class DefaultRepositoryRoleManagerTest {
} }
@Test @Test
void shouldReturnEmptyList() { void shouldReturnAllRoles() {
assertThat(manager.getAll()).isEmpty(); List<RepositoryRole> allRoles = manager.getAll();
assertThat(allRoles).containsExactly(CUSTOM_ROLE, SYSTEM_ROLE);
} }
@Test @Test
void shouldReturnEmptyFilteredList() { void shouldReturnFilteredList() {
assertThat(manager.getAll(x -> true, null)).isEmpty(); Collection<RepositoryRole> allRoles = manager.getAll(role -> CUSTOM_ROLE_NAME.equals(role.getName()), null);
assertThat(allRoles).containsExactly(CUSTOM_ROLE);
} }
@Test @Test
void shouldReturnEmptyPaginatedList() { void shouldReturnPaginatedRoles() {
assertThat(manager.getAll(1, 1)).isEmpty(); Collection<RepositoryRole> allRoles =
manager.getAll(
Comparator.comparing(RepositoryRole::getType),
1, 1
);
assertThat(allRoles).containsExactly(CUSTOM_ROLE);
} }
} }
} }