DefaultQueryDslPredicateExecutor extends PagingAndSortingSupport implements DataStoreAware { public Object findOne(Predicate predicate) { return ((CollQuery) CollQueryFactory.from(alias, dataStore.retrieveAll()).where(predicate)).fetchOne(); }  Object findOne(Predicate predicate); Iterable findAll(Predicate predicate); Iterable findAll(Predicate predicate, Sort sort); Page findAll(Predicate predicate, Pageable pageable); long count(Predicate predicate); boolean exists(Predicate predicate); Iterable findAll(OrderSpecifier... orders); Iterable findAll(Predicate predicate, OrderSpecifier... orders); @Override void setDataStore(DataStore dataStore);  }
@Test public void testFindOne() { final Person saved = new Person().setId("1").setAge(10); dataStore.save("1", saved); dataStore.save("2", new Person().setId("2")); final Person person = alias(Person.class); final BooleanExpression predicate = $(person.getId()).eq("1"); final Object one = executor.findOne(predicate); assertThat(one, is(notNullValue())); assertThat(one, Matchers.is(saved)); }
@Test public void testFindOneWhenNoneExists() { final Person person = alias(Person.class); final BooleanExpression predicate = $(person.getId()).eq("1"); final Object one = executor.findOne(predicate); assertThat(one, is(nullValue())); }
@Test(expectedExceptions = NonUniqueResultException.class) public void testFindOneWhenMoreThanOneMatches() { dataStore.save("1", new Person().setId("1").setFirstName("Milad").setLastName("Naseri")); dataStore.save("2", new Person().setId("2").setFirstName("Hassan").setLastName("Naseri")); final Person person = alias(Person.class); final BooleanExpression predicate = $(person.getLastName()).eq("Naseri"); final Object one = executor.findOne(predicate); assertThat(one, is(nullValue())); }