@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2011 the original author or authors .
* Copyright 2002 - 2012 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 .
@ -16,18 +16,24 @@
@@ -16,18 +16,24 @@
package org.springframework.test.context ;
import static org.junit.Assert.* ;
import java.util.Comparator ;
import java.util.List ;
import org.junit.AfterClass ;
import org.junit.BeforeClass ;
import org.junit.Ignore ;
import org.junit.Test ;
import org.junit.runner.RunWith ;
import org.junit.runners.model.FrameworkMethod ;
import org.junit.runners.model.InitializationError ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.context.ApplicationContext ;
import org.springframework.test.annotation.DirtiesContext ;
import org.springframework.test.context.SpringRunnerContextCacheTests.OrderedMethodsSpringJUnit4ClassRunner ;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner ;
import static org.junit.Assert.* ;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener ;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener ;
/ * *
* JUnit 4 based unit test which verifies correct { @link ContextCache
@ -40,9 +46,9 @@ import static org.junit.Assert.*;
@@ -40,9 +46,9 @@ import static org.junit.Assert.*;
* @since 2 . 5
* @see TestContextCacheKeyTests
* /
@Ignore
@RunWith ( SpringJUnit4ClassRun ner . class )
@ContextConfiguration ( "/org/springframework/test/context/ junit4/SpringJUnit4ClassRunnerAppCtxTests-context.xml" )
@RunWith ( OrderedMethodsSpringJUnit4ClassRunner . class )
@TestExecutionListeners ( { DependencyInjectionTestExecutionListener . class , DirtiesContextTestExecutionListe ner . class } )
@ContextConfiguration ( "junit4/SpringJUnit4ClassRunnerAppCtxTests-context.xml" )
public class SpringRunnerContextCacheTests {
private static ApplicationContext dirtiedApplicationContext ;
@ -124,4 +130,30 @@ public class SpringRunnerContextCacheTests {
@@ -124,4 +130,30 @@ public class SpringRunnerContextCacheTests {
SpringRunnerContextCacheTests . dirtiedApplicationContext , this . applicationContext ) ;
}
/ * *
* @since 3 . 2
* /
public static class OrderedMethodsSpringJUnit4ClassRunner extends SpringJUnit4ClassRunner {
public OrderedMethodsSpringJUnit4ClassRunner ( Class < ? > clazz ) throws InitializationError {
super ( clazz ) ;
}
@Override
protected List < FrameworkMethod > computeTestMethods ( ) {
List < FrameworkMethod > testMethods = super . computeTestMethods ( ) ;
java . util . Collections . sort ( testMethods , new Comparator < FrameworkMethod > ( ) {
public int compare ( FrameworkMethod method1 , FrameworkMethod method2 ) {
return method1 . getName ( ) . compareTo ( method2 . getName ( ) ) ;
}
} ) ;
return testMethods ;
}
}
}