Skip to content

Commit

Permalink
Made adjustments to pass new unit tests
Browse files Browse the repository at this point in the history
Made adjustments to pass new unit tests.

 - Fixed erroneous tests.
 - Added API note to MissingPermissionException
 - Changed default value of MissingPermissionException's "isForAnyPermission" field to a more appropriate default value for a single permission.
  • Loading branch information
c-massie committed Dec 17, 2021
1 parent 4955ac5 commit 92cd575
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MissingPermissionException(String permission, String message)
{
super(message);
this.permissionsMissing = Collections.singletonList(permission);
this.isForAnyPermissions = false;
this.isForAnyPermissions = true;
}

/**
Expand Down Expand Up @@ -196,6 +196,8 @@ public boolean multiplePermissionsWereMissing()

/**
* Gets whether having *any* permission required would have resulted in the permission check passing.
* @apiNote In the case of a single permission failing, this may still return false - this is more for checking if
* this is thrown as a result of an "any" check vs an "all" check.
* @return True if any permission required being present would have resulted in a pass for the permission check.
* Otherwise, (if all permissions were needed) false.
*/
Expand Down
14 changes: 4 additions & 10 deletions tests/scot/massie/lib/permissions/PermissionsRegistryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void assertHasAllPermissions_hasNoneOfOne()
.satisfies(ex -> assertThat(ex.getUserId()).isEqualTo("user1"))
.satisfies(ex -> assertThat(ex.getPermissions()).containsExactlyInAnyOrder("some.other.permission"))
.satisfies(ex -> assertThat(ex.multiplePermissionsWereMissing()).isFalse())
.satisfies(ex -> assertThat(ex.anySinglePermissionWouldHavePassedPermissionCheck()).isTrue())
.satisfies(ex -> assertThat(ex.anySinglePermissionWouldHavePassedPermissionCheck()).isFalse())
.satisfies(ex -> assertThat(ex.getPermission()).isEqualTo("some.other.permission"));
}

Expand Down Expand Up @@ -171,7 +171,7 @@ void assertHasAllPermissions_hasAllButOne()
.satisfies(ex -> assertThat(ex.getUserId()).isEqualTo("user1"))
.satisfies(ex -> assertThat(ex.getPermissions()).containsExactlyInAnyOrder("some.permission.doot"))
.satisfies(ex -> assertThat(ex.multiplePermissionsWereMissing()).isFalse())
.satisfies(ex -> assertThat(ex.anySinglePermissionWouldHavePassedPermissionCheck()).isTrue())
.satisfies(ex -> assertThat(ex.anySinglePermissionWouldHavePassedPermissionCheck()).isFalse())
.satisfies(ex -> assertThat(ex.getPermission()).isEqualTo("some.permission.doot"));
}

Expand Down Expand Up @@ -652,7 +652,6 @@ public void getPermissionStatus_negatedDirectlyCoveringWildcard_hasDirectlySameB
//endregion

//region Multiple

@Test
void getPermissionStatuses_none()
{
Expand Down Expand Up @@ -750,9 +749,9 @@ void getPermissionStatuses_multiple_hasAll()
{
PermissionsRegistry<String> reg = getNewPermissionsRegistry();
reg.assignUserPermission("user1", "some.permission.noot: permarg");
reg.assignUserPermission("user1", "some.permission.noot: somarg");
reg.assignUserPermission("user1", "some.permission.doot: somarg");
reg.assignUserPermission("user1", "some.permission.hoot: otharg");
reg.assignUserPermission("user1", "some.permission.noot: yetarg");
reg.assignUserPermission("user1", "some.permission.toot: yetarg");
reg.assignUserPermission("user1", "some.permission.joot: morarg");

Map<String, PermissionStatus> permStatuses = reg.getUserPermissionStatuses("user1",
Expand Down Expand Up @@ -794,7 +793,6 @@ void getPermissionStatuses_multiple_hasAllUnderSamePermission()
.isNotNull()
.containsExactlyInAnyOrderEntriesOf(expectedPermStatuses);
}

//endregion
//endregion

Expand Down Expand Up @@ -1687,7 +1685,6 @@ public void hasPermissionViaGroupViaGroup_negatedUniversal_negatesPermission()
//endregion

//region Has all

@Test
void hasAllPermissions_hasNone()
{
Expand Down Expand Up @@ -1790,11 +1787,9 @@ void hasAllPermissions_hasSomeDirectly_restViaSuperpermissions()
"yet.another.permission"))
.isTrue();
}

//endregion

//region Has any

@Test
void hasAnyPermissions_hasNone()
{
Expand Down Expand Up @@ -1891,7 +1886,6 @@ void hasAnyPermissions_hasSomeViaSuperpermissions()
"yet.another.permission"))
.isTrue();
}

//endregion

//region Has any subpermission of
Expand Down

0 comments on commit 92cd575

Please sign in to comment.