UserSpecs { public static Specification<User> hasUserIdIn(final Collection<Integer> ids) { return new Specification<User>() { @Override public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) { return root.get(User_.id).in(ids); } }; } 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 testHasUserIdIn() throws Exception { final User user1 = _userRepo.save(newUser(_inc)); final User user2 = _userRepo.save(newUser(_inc)); final User user3 = _userRepo.save(newUser(_inc)); final List<Integer> ids = Arrays.asList(user1.getId(), user2.getId()); final List<User> found = _userRepo.findAll(hasUserIdIn(ids)); assertEquals(2, found.size()); List<Integer> foundIds = Lists.transform(found, new Function<User, Integer>() { @Nullable @Override public Integer apply(@Nullable User input) { return input.getId(); } }); assertTrue(foundIds.contains(user1.getId())); assertTrue(foundIds.contains(user2.getId())); assertFalse(foundIds.contains(user3.getId())); }