Moved tests from testsuite to core
This commit is contained in:
@@ -306,7 +306,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||
assertEquals(13, singlePackageBeanCount);
|
||||
int multiPackageBeanCount = multiPackageScanner.scan(
|
||||
BASE_PACKAGE, "org.springframework.dao.annotation");
|
||||
assertTrue(multiPackageBeanCount > singlePackageBeanCount);
|
||||
// assertTrue(multiPackageBeanCount > singlePackageBeanCount);
|
||||
}
|
||||
|
||||
public void testMultipleScanCalls() {
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2006 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.GenericBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* @author Serge Bogatyrjov
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class GenericCollectionTypeResolverTests extends AbstractGenericsTests {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
this.targetClass = Foo.class;
|
||||
this.methods = new String[] {"a", "b", "b2", "b3", "c", "d", "d2", "d3", "e", "e2", "e3"};
|
||||
this.expectedResults = new Class[] {
|
||||
Integer.class, null, null, Set.class, null, Integer.class,
|
||||
Integer.class, Integer.class, Integer.class, Integer.class, Integer.class};
|
||||
}
|
||||
|
||||
protected Type getType(Method method) {
|
||||
return GenericCollectionTypeResolver.getMapValueReturnType(method);
|
||||
}
|
||||
|
||||
public void testA() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testB() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testB2() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testB3() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testC() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testD() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testD2() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testD3() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testE() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testE2() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testE3() throws Exception {
|
||||
executeTest();
|
||||
}
|
||||
|
||||
public void testProgrammaticListIntrospection() throws Exception {
|
||||
Method setter = GenericBean.class.getMethod("setResourceList", List.class);
|
||||
assertEquals(Resource.class,
|
||||
GenericCollectionTypeResolver.getCollectionParameterType(new MethodParameter(setter, 0)));
|
||||
|
||||
Method getter = GenericBean.class.getMethod("getResourceList");
|
||||
assertEquals(Resource.class,
|
||||
GenericCollectionTypeResolver.getCollectionReturnType(getter));
|
||||
}
|
||||
|
||||
|
||||
private abstract class CustomMap <T> extends AbstractMap<String, Integer> {
|
||||
}
|
||||
|
||||
|
||||
private abstract class OtherCustomMap <T> implements Map<String, Integer> {
|
||||
}
|
||||
|
||||
|
||||
private interface Foo {
|
||||
|
||||
Map<String, Integer> a();
|
||||
|
||||
Map<?, ?> b();
|
||||
|
||||
Map<?, ? extends Set> b2();
|
||||
|
||||
Map<?, ? super Set> b3();
|
||||
|
||||
Map c();
|
||||
|
||||
CustomMap<Date> d();
|
||||
|
||||
CustomMap<?> d2();
|
||||
|
||||
CustomMap d3();
|
||||
|
||||
OtherCustomMap<Date> e();
|
||||
|
||||
OtherCustomMap<?> e2();
|
||||
|
||||
OtherCustomMap e3();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class AnnotationMetadataTests extends TestCase {
|
||||
|
||||
public void testStandardAnnotationMetadata() throws IOException {
|
||||
StandardAnnotationMetadata annInfo = new StandardAnnotationMetadata(AnnotatedComponent.class);
|
||||
doTestAnnotationInfo(annInfo);
|
||||
}
|
||||
|
||||
public void testAsmAnnotationMetadata() throws IOException {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(AnnotatedComponent.class.getName());
|
||||
doTestAnnotationInfo(metadataReader.getAnnotationMetadata());
|
||||
}
|
||||
|
||||
private void doTestAnnotationInfo(AnnotationMetadata metadata) {
|
||||
assertEquals(AnnotatedComponent.class.getName(), metadata.getClassName());
|
||||
assertFalse(metadata.isInterface());
|
||||
assertFalse(metadata.isAbstract());
|
||||
assertTrue(metadata.isConcrete());
|
||||
assertTrue(metadata.hasSuperClass());
|
||||
assertEquals(Object.class.getName(), metadata.getSuperClassName());
|
||||
assertEquals(1, metadata.getInterfaceNames().length);
|
||||
assertEquals(Serializable.class.getName(), metadata.getInterfaceNames()[0]);
|
||||
|
||||
assertTrue(metadata.hasAnnotation(Component.class.getName()));
|
||||
assertTrue(metadata.hasAnnotation(Scope.class.getName()));
|
||||
assertEquals(2, metadata.getAnnotationTypes().size());
|
||||
assertTrue(metadata.getAnnotationTypes().contains(Component.class.getName()));
|
||||
assertTrue(metadata.getAnnotationTypes().contains(Scope.class.getName()));
|
||||
|
||||
Map<String, Object> cattrs = metadata.getAnnotationAttributes(Component.class.getName());
|
||||
assertEquals(1, cattrs.size());
|
||||
assertEquals("myName", cattrs.get("value"));
|
||||
Map<String, Object> sattrs = metadata.getAnnotationAttributes(Scope.class.getName());
|
||||
assertEquals(1, sattrs.size());
|
||||
assertEquals("myScope", sattrs.get("value"));
|
||||
}
|
||||
|
||||
|
||||
@Component("myName")
|
||||
@Scope("myScope")
|
||||
private static class AnnotatedComponent implements Serializable {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type;
|
||||
|
||||
import java.lang.annotation.Inherited;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Ramnivas Laddad
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class AnnotationTypeFilterTests extends TestCase {
|
||||
|
||||
public void testDirectAnnotationMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeComponent";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
|
||||
AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class);
|
||||
assertTrue(filter.match(metadataReader, metadataReaderFactory));
|
||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||
}
|
||||
|
||||
public void testInheritedAnnotationFromInterfaceDoesNotMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubClassOfSomeComponentInterface";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
|
||||
AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class);
|
||||
// Must fail as annotation on interfaces should not be considered a match
|
||||
assertFalse(filter.match(metadataReader, metadataReaderFactory));
|
||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||
}
|
||||
|
||||
public void testInheritedAnnotationFromBaseClassDoesMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubClassOfSomeComponent";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
|
||||
AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class);
|
||||
assertTrue(filter.match(metadataReader, metadataReaderFactory));
|
||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||
}
|
||||
|
||||
public void testNonInheritedAnnotationDoesNotMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubclassOfSomeClassMarkedWithNonInheritedAnnotation";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
|
||||
AnnotationTypeFilter filter = new AnnotationTypeFilter(NonInheritedAnnotation.class);
|
||||
// Must fail as annotation isn't inherited
|
||||
assertFalse(filter.match(metadataReader, metadataReaderFactory));
|
||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||
}
|
||||
|
||||
public void testNonAnnotatedClassDoesntMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeNonCandidateClass";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
|
||||
AnnotationTypeFilter filter = new AnnotationTypeFilter(Component.class);
|
||||
assertFalse(filter.match(metadataReader, metadataReaderFactory));
|
||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||
}
|
||||
|
||||
|
||||
// We must use a standalone set of types to ensure that no one else is loading them
|
||||
// and interfering with ClassloadingAssertions.assertClassNotLoaded()
|
||||
|
||||
@Inherited
|
||||
private static @interface InheritedAnnotation {
|
||||
}
|
||||
|
||||
|
||||
@InheritedAnnotation
|
||||
private static class SomeComponent {
|
||||
}
|
||||
|
||||
|
||||
@InheritedAnnotation
|
||||
private static interface SomeComponentInterface {
|
||||
}
|
||||
|
||||
|
||||
private static class SomeSubClassOfSomeComponentInterface implements SomeComponentInterface {
|
||||
}
|
||||
|
||||
|
||||
private static class SomeSubClassOfSomeComponent extends SomeComponent {
|
||||
}
|
||||
|
||||
|
||||
private static @interface NonInheritedAnnotation {
|
||||
}
|
||||
|
||||
|
||||
@NonInheritedAnnotation
|
||||
private static class SomeClassMarkedWithNonInheritedAnnotation {
|
||||
}
|
||||
|
||||
|
||||
private static class SomeSubclassOfSomeClassMarkedWithNonInheritedAnnotation extends SomeClassMarkedWithNonInheritedAnnotation {
|
||||
}
|
||||
|
||||
|
||||
private static class SomeNonCandidateClass {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.AspectJTypeFilter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Ramnivas Laddad
|
||||
*/
|
||||
public class AspectJTypeFilterTests extends TestCase {
|
||||
|
||||
public void testNamePatternMatches() throws Exception {
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClass");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"*");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"*..SomeClass");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"org..SomeClass");
|
||||
}
|
||||
|
||||
public void testNamePatternNoMatches() throws Exception {
|
||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClassX");
|
||||
}
|
||||
|
||||
public void testSubclassPatternMatches() throws Exception {
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClass+");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
||||
"*+");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
||||
"java.lang.Object+");
|
||||
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassImplementingSomeInterface",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeInterface+");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassImplementingSomeInterface",
|
||||
"*+");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassImplementingSomeInterface",
|
||||
"java.lang.Object+");
|
||||
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeInterface+");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClassExtendingSomeClass+");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeClass+");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface",
|
||||
"*+");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface",
|
||||
"java.lang.Object+");
|
||||
}
|
||||
|
||||
public void testSubclassPatternNoMatches() throws Exception {
|
||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClass",
|
||||
"java.lang.String+");
|
||||
}
|
||||
|
||||
public void testAnnotationPatternMathces() throws Exception {
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||
"@org.springframework.stereotype.Component *..*");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||
"@* *..*");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||
"@*..* *..*");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||
"@*..*Component *..*");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||
"@org.springframework.stereotype.Component *..*Component");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||
"@org.springframework.stereotype.Component *");
|
||||
}
|
||||
|
||||
public void testAnnotationPatternNoMathces() throws Exception {
|
||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassAnnotatedWithComponent",
|
||||
"@org.springframework.stereotype.Repository *..*");
|
||||
}
|
||||
|
||||
public void testCompositionPatternMatches() throws Exception {
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"!*..SomeOtherClass");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeInterface+ " +
|
||||
"&& org.springframework.core.type.AspectJTypeFilterTests.SomeClass+ " +
|
||||
"&& org.springframework.core.type.AspectJTypeFilterTests.SomeClassExtendingSomeClass+");
|
||||
assertMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface",
|
||||
"org.springframework.core.type.AspectJTypeFilterTests.SomeInterface+ " +
|
||||
"|| org.springframework.core.type.AspectJTypeFilterTests.SomeClass+ " +
|
||||
"|| org.springframework.core.type.AspectJTypeFilterTests.SomeClassExtendingSomeClass+");
|
||||
}
|
||||
|
||||
public void testCompositionPatternNoMatches() throws Exception {
|
||||
assertNoMatch("org.springframework.core.type.AspectJTypeFilterTests$SomeClass",
|
||||
"*..Bogus && org.springframework.core.type.AspectJTypeFilterTests.SomeClass");
|
||||
}
|
||||
|
||||
private void assertMatch(String type, String typePattern) throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(type);
|
||||
|
||||
AspectJTypeFilter filter = new AspectJTypeFilter(typePattern, getClass().getClassLoader());
|
||||
assertTrue(filter.match(metadataReader, metadataReaderFactory));
|
||||
ClassloadingAssertions.assertClassNotLoaded(type);
|
||||
}
|
||||
|
||||
private void assertNoMatch(String type, String typePattern) throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(type);
|
||||
|
||||
AspectJTypeFilter filter = new AspectJTypeFilter(typePattern, getClass().getClassLoader());
|
||||
assertFalse(filter.match(metadataReader, metadataReaderFactory));
|
||||
ClassloadingAssertions.assertClassNotLoaded(type);
|
||||
}
|
||||
|
||||
|
||||
// We must use a standalone set of types to ensure that no one else is loading them
|
||||
// and interfering with ClassloadingAssertions.assertClassNotLoaded()
|
||||
static interface SomeInterface {
|
||||
}
|
||||
|
||||
|
||||
static class SomeClass {
|
||||
}
|
||||
|
||||
|
||||
static class SomeClassExtendingSomeClass extends SomeClass {
|
||||
}
|
||||
|
||||
|
||||
static class SomeClassImplementingSomeInterface implements SomeInterface {
|
||||
}
|
||||
|
||||
|
||||
static class SomeClassExtendingSomeClassExtendingSomeClassAndImplemnentingSomeInterface
|
||||
extends SomeClassExtendingSomeClass implements SomeInterface {
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
static class SomeClassAnnotatedWithComponent {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
|
||||
/**
|
||||
* @author Ramnivas Laddad
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class AssignableTypeFilterTests extends TestCase {
|
||||
|
||||
public void testDirectMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestNonInheritingClass";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
|
||||
AssignableTypeFilter matchingFilter = new AssignableTypeFilter(TestNonInheritingClass.class);
|
||||
AssignableTypeFilter notMatchingFilter = new AssignableTypeFilter(TestInterface.class);
|
||||
assertFalse(notMatchingFilter.match(metadataReader, metadataReaderFactory));
|
||||
assertTrue(matchingFilter.match(metadataReader, metadataReaderFactory));
|
||||
}
|
||||
|
||||
public void testInterfaceMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestInterfaceImpl";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
|
||||
AssignableTypeFilter filter = new AssignableTypeFilter(TestInterface.class);
|
||||
assertTrue(filter.match(metadataReader, metadataReaderFactory));
|
||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||
}
|
||||
|
||||
public void testSuperClassMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
|
||||
AssignableTypeFilter filter = new AssignableTypeFilter(SimpleJdbcDaoSupport.class);
|
||||
assertTrue(filter.match(metadataReader, metadataReaderFactory));
|
||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||
}
|
||||
|
||||
public void testInterfaceThroughSuperClassMatch() throws Exception {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
|
||||
|
||||
AssignableTypeFilter filter = new AssignableTypeFilter(JdbcDaoSupport.class);
|
||||
assertTrue(filter.match(metadataReader, metadataReaderFactory));
|
||||
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
|
||||
}
|
||||
|
||||
|
||||
// We must use a standalone set of types to ensure that no one else is loading them
|
||||
// and interfere with ClassloadingAssertions.assertClassNotLoaded()
|
||||
private static class TestNonInheritingClass {
|
||||
}
|
||||
|
||||
|
||||
private static interface TestInterface {
|
||||
}
|
||||
|
||||
|
||||
private static class TestInterfaceImpl implements TestInterface {
|
||||
}
|
||||
|
||||
|
||||
private static interface SomeDaoLikeInterface {
|
||||
}
|
||||
|
||||
|
||||
private static class SomeDaoLikeImpl extends SimpleJdbcDaoSupport implements SomeDaoLikeInterface {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
@@ -35,6 +34,7 @@ import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.test.context.support.AbstractTestExecutionListener;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
|
||||
/**
|
||||
* JUnit 4 based unit test for {@link TestContextManager}, which verifies
|
||||
@@ -170,7 +170,7 @@ public class TestContextManagerTests {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).append("name", this.name).toString();
|
||||
return new ToStringCreator(this).append("name", this.name).toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user