OperationAllowedSpecs { public static Specification<OperationAllowed> isPublic(final ReservedOperation operation) { return new Specification<OperationAllowed>() { @Override public Predicate toPredicate(Root<OperationAllowed> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Path<Integer> opIdAttributePath = root.get(OperationAllowed_.id).get(OperationAllowedId_.operationId); Path<Integer> groupIdAttributePath = root.get(OperationAllowed_.id).get(OperationAllowedId_.groupId); Predicate opIdEqualPredicate = cb.equal(opIdAttributePath, cb.literal(operation.getId())); Predicate allGroup = cb.equal(groupIdAttributePath, cb.literal(ReservedGroup.all.getId())); return cb.and(opIdEqualPredicate, allGroup); } }; } private  OperationAllowedSpecs(); static Specification<OperationAllowed> hasMetadataId(final String metadataId); static Specification<OperationAllowed> hasMetadataId(final int metadataId); static Specification<OperationAllowed> hasGroupId(final int groupId); static Specification<OperationAllowed> hasOperation(final ReservedOperation operation); static Specification<OperationAllowed> hasOperationId(final int operationId); static Specification<OperationAllowed> isPublic(final ReservedOperation operation); static Specification<OperationAllowed> hasMetadataIdIn(final Collection<Integer> metadataIds); static Specification<OperationAllowed> hasGroupIdIn(final Collection<Integer> groupIds); static Specification<OperationAllowed> hasOperationIdIn(final Collection<Integer> operationIds);  }
@Test public void testIsPublic() throws Exception { int viewOpId = ReservedOperation.view.getId(); int allGroupId = ReservedGroup.all.getId(); try { setId(ReservedOperation.view, _viewOp.getId()); setId(ReservedGroup.all, _allGroup.getId()); Specification<OperationAllowed> isPublic = OperationAllowedSpecs.isPublic(ReservedOperation.view); List<OperationAllowed> found = _opAllowRepo.findAll(isPublic); assertEquals(1, found.size()); assertEquals(_opAllowed1.getId(), found.get(0).getId()); } finally { setId(ReservedOperation.view, viewOpId); setId(ReservedGroup.all, allGroupId); } }