Over a million developers have joined DZone.

Testing New Bean Scopes With Spring 2.0 - Example

·
// scoped bean definition

	
		
	

// an example test case

public class ScopedBeanTest extends AbstractRequestContextFilterTestBase {

	protected String[] getConfigLocations() {
		return new String[] { "classpath:applicationContext-with-scopedBean.xml" };
	}


	@Test
	public void testScopedBean() throws Exception {

		new FilterTest(new FilterChain() {

			public void doFilter(ServletRequest arg0, ServletResponse arg1)
					throws IOException, ServletException {
				ScopedBean scopedBean = (ScopedBean) applicationContext
						.getBean("scopedBean");
				...
				/* 
				 * let the classses under test do something with your scopedBean
				 * and check if modifications are done correctly 
				 */
				...
			}

		}).run();

	}
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}