DATACMNS-406 - Tighten contract for RepositoryMetadata implementations.

We now resolve the domain and id-types eagerly within the constructor of AbstractRepositoryMetadata implementations to prevent a RepositoryMetadata instance to be created in an invalid state. Pulled-up repositoryInterface property to AbstractRepositoryMetadata.

Original pull request: #58.
This commit is contained in:
Thomas Darimont
2013-11-20 15:25:37 +01:00
committed by Oliver Gierke
parent 09b8989a7f
commit b96f613b98
6 changed files with 118 additions and 60 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2012 the original author or authors.
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
* Unit tests for {@link AbstractRepositoryMetadata}.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
public class AbstractRepositoryMetadataUnitTests {
@@ -118,10 +119,6 @@ public class AbstractRepositoryMetadataUnitTests {
public Class<?> getDomainType() {
return null;
}
public Class<?> getRepositoryInterface() {
return null;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2012 the original author or authors.
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import org.junit.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.util.ClassUtils;
@@ -31,6 +32,7 @@ import org.springframework.data.repository.util.ClassUtils;
* Unit tests for {@link DefaultRepositoryMetadata}.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
public class DefaultRepositoryMetadataUnitTests {
@@ -50,6 +52,14 @@ public class DefaultRepositoryMetadataUnitTests {
new DefaultRepositoryMetadata(Collection.class);
}
/**
* @see DATACMNS-406
*/
@Test(expected = IllegalArgumentException.class)
public void rejectsUnparameterizedRepositoryInterface() {
new DefaultRepositoryMetadata(Repository.class);
}
@Test
public void looksUpDomainClassCorrectly() throws Exception {
@@ -137,10 +147,7 @@ public class DefaultRepositoryMetadataUnitTests {
*
* @author Oliver Gierke
*/
static class GenericEntity<T> {
}
static class GenericEntity<T> {}
static interface GenericEntityRepository extends CrudRepository<GenericEntity<String>, Long> {
}
static interface GenericEntityRepository extends CrudRepository<GenericEntity<String>, Long> {}
}