GroupSpecs { public static Specification<Group> isReserved() { return new Specification<Group>() { @Override public Predicate toPredicate(Root<Group> root, CriteriaQuery<?> query, CriteriaBuilder cb) { return getIsReserved(root, cb); } }; } private  GroupSpecs(); static Specification<Group> isReserved(); static Specification<Group> in(final List<Integer> ids); static Specification<UserGroup> isEditorOrMore(
        final Integer userId);  }
@Test public void testIsNotReserved() throws Exception { for (ReservedGroup reservedGroup : ReservedGroup.values()) { Group group = _repo.save(reservedGroup.getGroupEntityTemplate()); final Field idField = ReflectionUtils.findField(ReservedGroup.class, "_id"); idField.setAccessible(true); ReflectionUtils.setField(idField, reservedGroup, group.getId()); } Group notReserved = _repo.save(GroupRepositoryTest.newGroup(_inc)); List<Group> found = _repo.findAll(isReserved()); assertEquals(ReservedGroup.values().length, found.size()); for (Group group : found) { assertTrue(group.isReserved()); } found = _repo.findAll(not(isReserved())); assertEquals(1, found.size()); assertSameContents(notReserved, found.get(0)); }