Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ public <T> CrudInvoker<T> getCrudInvoker(Class<T> domainClass) {
RepositoryInformation information = getRepositoryInformationFor(domainClass);
Object repository = getRepositoryFor(domainClass);

Assert.notNull(repository, String.format("No repository found for domain class: %s", domainClass));

if (repository instanceof CrudRepository) {
return new CrudRepositoryInvoker<T>((CrudRepository<T, Serializable>) repository);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import java.util.List;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
Expand All @@ -51,12 +53,15 @@
* Unit tests for {@link Repositories}.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
@RunWith(MockitoJUnitRunner.class)
public class RepositoriesUnitTests {

ApplicationContext context;

@Rule public ExpectedException exception = ExpectedException.none();

@Before
public void setUp() {

Expand Down Expand Up @@ -107,6 +112,19 @@ public void exposesPersistentEntityForDomainTypes() {
assertThat(repositories.getPersistentEntity(Address.class), is(notNullValue()));
}

/**
* @see DATACMNS-374
*/
@Test
public void shouldThrowMeaningfulExceptionWhenTheRepositoryForAGivenDomainClassCannotBeFound() {

exception.expect(IllegalArgumentException.class);
exception.expectMessage(containsString("No repository found for domain class: "));

Repositories repositories = new Repositories(context);
repositories.getCrudInvoker(EntityWithoutRepository.class);
}

class Person {

}
Expand All @@ -115,6 +133,10 @@ class Address {

}

class EntityWithoutRepository {

}

interface PersonRepository extends CrudRepository<Person, Long> {

}
Expand Down