DATACMNS-1345 - RepositoryFactoryBeanSupport now properly reports missing MappingContext.

This commit is contained in:
Oliver Gierke
2018-06-21 08:55:45 +02:00
parent 92dccd67a8
commit 39303041ba
2 changed files with 19 additions and 2 deletions

View File

@@ -65,7 +65,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
private Optional<Object> customImplementation = Optional.empty();
private Optional<RepositoryFragments> repositoryFragments = Optional.empty();
private NamedQueries namedQueries;
private Optional<MappingContext<?, ?>> mappingContext;
private Optional<MappingContext<?, ?>> mappingContext = Optional.empty();
private ClassLoader classLoader;
private BeanFactory beanFactory;
private boolean lazyInit = false;
@@ -81,7 +81,6 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
*
* @param repositoryInterface must not be {@literal null}.
*/
@SuppressWarnings("null")
protected RepositoryFactoryBeanSupport(Class<? extends T> repositoryInterface) {
Assert.notNull(repositoryInterface, "Repository interface must not be null!");

View File

@@ -72,6 +72,24 @@ public class RepositoryFactoryBeanSupportUnitTests {
assertThat(information.getQueryMethods()).isEmpty();
}
@Test // DATACMNS-1345
public void reportsMappingContextUnavailableForPersistentEntityLookup() {
RepositoryFactoryBeanSupport<SampleRepository, Object, Long> bean = new RepositoryFactoryBeanSupport<SampleRepository, Object, Long>(
SampleRepository.class) {
@Override
protected RepositoryFactorySupport createRepositoryFactory() {
return new DummyRepositoryFactory(mock(SampleRepository.class));
}
};
bean.afterPropertiesSet();
assertThatExceptionOfType(IllegalStateException.class) //
.isThrownBy(() -> bean.getPersistentEntity());
}
interface SampleRepository extends Repository<Object, Long> {}
interface SampleWithQuerydslRepository extends Repository<Object, Long>, QuerydslPredicateExecutor<Object> {}