UserSpecs { public static Specification<User> hasEnabled(final Boolean enabled) { return new Specification<User>() { @Override public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Path<Boolean> enabledAttributePath = root.get(User_.enabled); Predicate enabledEqualPredicate = cb.equal(enabledAttributePath, enabled); return enabledEqualPredicate; } }; } private  UserSpecs(); static Specification<User> hasUserId(final int userId); static Specification<User> hasProfile(final Profile profile); static Specification<User> hasUserName(final String userName); static Specification<User> hasEmail(final String email); static Specification<User> hasNullAuthType(); static Specification<User> hasAuthType(final String authType); static Specification<User> userIsNameNotOneOf(final Collection<String> usernames); static Specification<User> hasUserIdIn(final Collection<Integer> ids); static Specification<User> hasEnabled(final Boolean enabled); static Specification<User> loginDateBetweenAndByGroups(final ISODate loginDateFrom,
                                                                  final ISODate loginDateTo,
                                                                  final Collection<Integer> groups);  }
@Test public void testUserHasEnabled() throws Exception { User user1 = _userRepo.save(newUser(_inc)); final User user2 = newUser(_inc); _userRepo.save(user2); final User user3 = newUser(_inc); user3.setEnabled(false); _userRepo.save(user3); final Specification<User> spec = hasEnabled(true); final List<User> enabled = _userRepo.findAll(hasEnabled(true)); assertEquals(2, enabled.size()); final List<User> notEnabled = _userRepo.findAll(hasEnabled(false)); assertEquals(1, notEnabled.size()); assertEquals(user3.getId(), notEnabled.get(0).getId()); }