DefaultQueryByExampleExecutor implements DataStoreAware, RepositoryConfigurationAware, RepositoryMetadataAware,
                   RepositoryFactoryConfigurationAware { public Object findOne(Example example) { final Collection found = retrieveAll(example); if (found.isEmpty()) { return null; } else if (found.size() > 1) { throw new InvalidArgumentException("Expected to see exactly one item found, but found " + found.size() + ". You should use a better example."); } return found.iterator().next(); } DefaultQueryByExampleExecutor(); Object findOne(Example example); Iterable findAll(Example example); Iterable findAll(Example example, Sort sort); Page findAll(Example example, Pageable pageable); long count(Example example); boolean exists(Example example); @Override void setDataStore(DataStore dataStore); @Override void setRepositoryConfiguration(RepositoryConfiguration repositoryConfiguration); @Override void setRepositoryMetadata(RepositoryMetadata repositoryMetadata); @Override void setRepositoryFactoryConfiguration(RepositoryFactoryConfiguration configuration);  }
@Test public void testFindOneWhenThereIsNoMatch() { final Object result = executor.findOne(Example.of(new Person().setFirstName("Gigili").setLastName("Magooli"))); assertThat(result, is(nullValue())); }
@Test(expectedExceptions = InvalidArgumentException.class) public void testFindOneWhenThereIsMoreThanOneMatch() { executor.findOne(Example.of(new Person().setAddress(new Address().setCity("Tehran")))); }
@Test public void testFindOne() { final Object found = executor.findOne( Example.of(new Person().setAddress(new Address().setCity("Tehran")).setFirstName("Milad"))); assertThat(found, is(notNullValue())); assertThat(found, is(dataStore.retrieve("1"))); }