/** * Private constructor to share common code between impl-based delegate and reference-based delegate * (cannot use method such as init() to share common code, due the use of final fields). * @param interfaceType static field defining the introduction * @param typePattern type pattern the introduction is restricted to * @param interceptor the delegation advice as {@link IntroductionInterceptor} */ private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, IntroductionInterceptor interceptor) { this.advice = interceptor; this.introducedInterface = interfaceType; // Excludes methods implemented. ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern); ClassFilter exclusion = (clazz -> !this.introducedInterface.isAssignableFrom(clazz)); this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion); }
@Test(expected = IllegalArgumentException.class) public void testInvalidPattern() { // should throw - pattern must be recognized as invalid new TypePatternClassFilter("-"); }
@Test(expected = IllegalArgumentException.class) public void testSetTypePatternWithNullArgument() throws Exception { new TypePatternClassFilter(null); }
@Test(expected = IllegalStateException.class) public void testInvocationOfMatchesMethodBlowsUpWhenNoTypePatternHasBeenSet() throws Exception { new TypePatternClassFilter().matches(String.class); }
case PERTYPEWITHIN: this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass))); return; default:
@Test public void testAndOrNotReplacement() { TypePatternClassFilter tpcf = new TypePatternClassFilter("java.lang.Object or java.lang.String"); assertFalse("matches Number",tpcf.matches(Number.class)); assertTrue("matches Object",tpcf.matches(Object.class)); assertTrue("matchesString",tpcf.matches(String.class)); tpcf = new TypePatternClassFilter("java.lang.Number+ and java.lang.Float"); assertTrue("matches Float",tpcf.matches(Float.class)); assertFalse("matches Double",tpcf.matches(Double.class)); tpcf = new TypePatternClassFilter("java.lang.Number+ and not java.lang.Float"); assertFalse("matches Float",tpcf.matches(Float.class)); assertTrue("matches Double",tpcf.matches(Double.class)); }
@Test public void testSubclassMatching() { TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.ITestBean+"); assertTrue("Must match: in package", tpcf.matches(TestBean.class)); assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class)); assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class)); assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class)); }
@Test public void testValidPatternMatching() { TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); assertTrue("Must match: in package", tpcf.matches(TestBean.class)); assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); assertTrue("Must match: in package", tpcf.matches(IOther.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(DeepBean.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(BeanFactory.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(DefaultListableBeanFactory.class)); }
/** * Private constructor to share common code between impl-based delegate and reference-based delegate * (cannot use method such as init() to share common code, due the use of final fields). * @param interfaceType static field defining the introduction * @param typePattern type pattern the introduction is restricted to * @param interceptor the delegation advice as {@link IntroductionInterceptor} */ private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, IntroductionInterceptor interceptor) { this.advice = interceptor; this.introducedInterface = interfaceType; // Excludes methods implemented. ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern); ClassFilter exclusion = (clazz -> !this.introducedInterface.isAssignableFrom(clazz)); this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion); }
/** * Private constructor to share common code between impl-based delegate and reference-based delegate * (cannot use method such as init() to share common code, due the use of final fields) * @param interfaceType static field defining the introduction * @param typePattern type pattern the introduction is restricted to * @param interceptor the delegation advice as {@link IntroductionInterceptor} */ private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, IntroductionInterceptor interceptor) { this.advice = interceptor; this.introducedInterface = interfaceType; // Excludes methods implemented. ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern); ClassFilter exclusion = new ClassFilter() { @Override public boolean matches(Class<?> clazz) { return !introducedInterface.isAssignableFrom(clazz); } }; this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion); }
case PERTYPEWITHIN: this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass))); return; default:
case PERTYPEWITHIN: this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass))); return; default: