DATACMNS-374 - Improved error handling in case of a missing repository.
In Repositories.getCrudInvoker(…) we now throw an IllegalArgumentException if we cannot find an appropriate repository for the given domain class. Previously it just blew up with a NullPointerException without a clear error message. Original pull request: #46.
This commit is contained in:
committed by
Oliver Gierke
parent
43b7a54294
commit
2d699b6b36
@@ -25,7 +25,9 @@ import java.util.Collections;
|
||||
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;
|
||||
@@ -51,12 +53,15 @@ import org.springframework.data.repository.query.QueryMethod;
|
||||
* 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() {
|
||||
|
||||
@@ -107,6 +112,19 @@ public class RepositoriesUnitTests {
|
||||
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 {
|
||||
|
||||
}
|
||||
@@ -115,6 +133,10 @@ public class RepositoriesUnitTests {
|
||||
|
||||
}
|
||||
|
||||
class EntityWithoutRepository {
|
||||
|
||||
}
|
||||
|
||||
interface PersonRepository extends CrudRepository<Person, Long> {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user