PermissionsManager { @SuppressWarnings("unchecked") public Page<AbstractPermissions> getByInstance( String domainId, String instanceId, int maxItems, long skipCount) throws ServerException, NotFoundException { return (Page<AbstractPermissions>) getPermissionsDao(domainId).getByInstance(instanceId, maxItems, skipCount); } @Inject  PermissionsManager(
      EventService eventService, Set<PermissionsDao<? extends AbstractPermissions>> daos); void storePermission(Permissions permissions); AbstractPermissions get(String userId, String domainId, String instanceId); @SuppressWarnings("unchecked") Page<AbstractPermissions> getByInstance(
      String domainId, String instanceId, int maxItems, long skipCount); void remove(String userId, String domainId, String instanceId); boolean exists(String userId, String domainId, String instanceId, String action); void checkActionsSupporting(String domainId, List<String> actions); List<AbstractPermissionsDomain> getDomains(); AbstractPermissionsDomain<? extends AbstractPermissions> getDomain(String domain);  }
@Test public void shouldBeAbleToGetPermissionsByInstance() throws Exception { final TestPermissionsImpl firstPermissions = new TestPermissionsImpl("user", "test", "test123", singletonList("read")); final TestPermissionsImpl secondPermissions = new TestPermissionsImpl("user1", "test", "test123", singletonList("read")); doReturn(new Page<>(asList(firstPermissions, secondPermissions), 1, 2, 4)) .when(permissionsDao) .getByInstance(nullable(String.class), nullable(Integer.class), nullable(Long.class)); final Page<AbstractPermissions> permissionsPage = permissionsManager.getByInstance("test", "test123", 2, 1); final List<AbstractPermissions> fetchedPermissions = permissionsPage.getItems(); verify(permissionsDao).getByInstance("test123", 2, 1); assertEquals(permissionsPage.getTotalItemsCount(), 4); assertEquals(permissionsPage.getItemsCount(), 2); assertTrue(fetchedPermissions.contains(firstPermissions)); assertTrue(fetchedPermissions.contains(secondPermissions)); }