alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (GenericBridgeMethodMatchingTests.java)

This example Spring Framework source code file (GenericBridgeMethodMatchingTests.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

abstractdependencyinjectionspringcontexttests, aspect, baseinterface, baseinterface, before, counteraspect, counteraspect, derivedinterface, derivedinterface, derivedstringparameterizedclass, genericbridgemethodmatchingtests, override, override, string

The Spring Framework GenericBridgeMethodMatchingTests.java source code

/*
 * 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.aop.aspectj.generic;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;

/**
 * Tests for AspectJ pointcut expression matching when working with bridge methods.
 *
 * <p>Depending on the caller's static type either the bridge method or the user-implemented method
 * gets called as the way into the proxy. Therefore, we need tests for calling a bean with
 * static type set to type with generic method and to type with specific non-generic implementation.
 *
 * <p>This class focuses on JDK proxy, while a subclass, GenericBridgeMethodMatchingClassProxyTests,
 * focuses on class proxying.
 *
 * See SPR-3556 for more details.
 *
 * @author Ramnivas Laddad
 */
public class GenericBridgeMethodMatchingTests extends AbstractDependencyInjectionSpringContextTests {

	protected DerivedInterface<String> testBean;

	protected CounterAspect counterAspect;


	public GenericBridgeMethodMatchingTests() {
		setPopulateProtectedVariables(true);
	}

	@Override
	protected String getConfigPath() {
		return "genericBridgeMethodMatchingTests-context.xml";
	}

	@Override
	protected void onSetUp() throws Exception {
		counterAspect.count = 0;
		super.onSetUp();
	}

	public void testGenericDerivedInterfaceMethodThroughInterface() {
		testBean.genericDerivedInterfaceMethod("");
		assertEquals(1, counterAspect.count);
	}

	public void testGenericBaseInterfaceMethodThroughInterface() {
		testBean.genericBaseInterfaceMethod("");
		assertEquals(1, counterAspect.count);
	}


	public interface BaseInterface<T> {

		void genericBaseInterfaceMethod(T t);
	}


	public interface DerivedInterface<T> extends BaseInterface {

		public void genericDerivedInterfaceMethod(T t);
	}


	public static class DerivedStringParameterizedClass implements DerivedInterface<String> {

		public void genericDerivedInterfaceMethod(String t) {
		}

		public void genericBaseInterfaceMethod(String t) {
		}
	}
	
	@Aspect
	public static class CounterAspect {

		public int count;

		@Before("execution(* *..BaseInterface+.*(..))")
		public void increment() {
			count++;
		}

	}

}

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework GenericBridgeMethodMatchingTests.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.