PermissionCheckerImpl implements PermissionChecker { @Override public boolean hasPermission(String user, String domain, String instance, String action) throws ServerException, NotFoundException, ConflictException { return permissionsManager.exists(user, domain, instance, action) || permissionsManager.exists("*", domain, instance, action); } @Inject  PermissionCheckerImpl(PermissionsManager permissionsManager); @Override boolean hasPermission(String user, String domain, String instance, String action);  }
@Test public void shouldCheckExistingDirectUsersPermissions() throws Exception { when(permissionsManager.exists(anyString(), anyString(), anyString(), anyString())) .thenReturn(true); boolean hasPermission = permissionChecker.hasPermission("user123", "domain123", "instance123", "test"); assertEquals(hasPermission, true); verify(permissionsManager).exists("user123", "domain123", "instance123", "test"); }
@Test public void shouldCheckExistingPublicPermissionsIfThereIsNoDirectUsersPermissions() throws Exception { doReturn(false) .when(permissionsManager) .exists(eq("user123"), anyString(), anyString(), anyString()); doReturn(true).when(permissionsManager).exists(eq("*"), anyString(), anyString(), anyString()); boolean hasPermission = permissionChecker.hasPermission("user123", "domain123", "instance123", "test"); assertEquals(hasPermission, true); verify(permissionsManager).exists("user123", "domain123", "instance123", "test"); verify(permissionsManager).exists("*", "domain123", "instance123", "test"); }