Jelajahi Sumber

Make sure test classes which are setting the context clear it in their tearDown methods.

Luke Taylor 18 tahun lalu
induk
melakukan
6a6bafa219
16 mengubah file dengan 89 tambahan dan 135 penghapusan
  1. 7 1
      core/src/test/java/org/acegisecurity/acls/jdbc/JdbcAclServiceTests.java
  2. 2 7
      core/src/test/java/org/acegisecurity/adapters/HttpRequestIntegrationFilterTests.java
  3. 4 4
      core/src/test/java/org/acegisecurity/context/httpinvoker/AuthenticationSimpleHttpInvokerRequestExecutorTests.java
  4. 7 7
      core/src/test/java/org/acegisecurity/context/rmi/ContextPropagatingRemoteInvocationTests.java
  5. 7 9
      core/src/test/java/org/acegisecurity/intercept/method/MethodDefinitionAttributesTests.java
  6. 8 7
      core/src/test/java/org/acegisecurity/intercept/method/aopalliance/MethodSecurityInterceptorTests.java
  7. 5 9
      core/src/test/java/org/acegisecurity/intercept/method/aspectj/AspectJSecurityInterceptorTests.java
  8. 9 22
      core/src/test/java/org/acegisecurity/intercept/web/FilterSecurityInterceptorTests.java
  9. 5 16
      core/src/test/java/org/acegisecurity/taglibs/authz/AclTagTests.java
  10. 5 4
      core/src/test/java/org/acegisecurity/taglibs/authz/AuthenticationTagTests.java
  11. 6 12
      core/src/test/java/org/acegisecurity/taglibs/authz/AuthorizeTagTests.java
  12. 7 11
      core/src/test/java/org/acegisecurity/ui/switchuser/SwitchUserProcessingFilterTests.java
  13. 1 1
      core/src/test/java/org/acegisecurity/ui/x509/X509ProcessingFilterTests.java
  14. 2 14
      core/src/test/java/org/acegisecurity/wrapper/SecurityContextHolderAwareRequestWrapperTests.java
  15. 10 11
      samples/attributes/src/test/java/sample/attributes/BankTests.java
  16. 4 0
      samples/dms/src/test/java/DmsIntegrationTests.java

+ 7 - 1
core/src/test/java/org/acegisecurity/acls/jdbc/JdbcAclServiceTests.java

@@ -58,6 +58,12 @@ public class JdbcAclServiceTests extends AbstractTransactionalDataSourceSpringCo
         this.jdbcMutableAclService = jdbcAclService;
     }
 
+
+    protected void onTearDown() throws Exception {
+        super.onTearDown();
+        SecurityContextHolder.clearContext();
+    }
+
     public void testLifecycle() {
         setComplete();
 
@@ -159,7 +165,7 @@ public class JdbcAclServiceTests extends AbstractTransactionalDataSourceSpringCo
         // Let's add an identical permission to the child, but it'll appear AFTER the current permission, so has no impact
         child.insertAce(null, BasePermission.DELETE, new PrincipalSid(auth), true);
 
-        // Let's also add another permission to the child 
+        // Let's also add another permission to the child
         child.insertAce(null, BasePermission.CREATE, new PrincipalSid(auth), true);
 
         // Save the changed child

+ 2 - 7
core/src/test/java/org/acegisecurity/adapters/HttpRequestIntegrationFilterTests.java

@@ -38,7 +38,6 @@ public class HttpRequestIntegrationFilterTests extends TestCase {
     //~ Constructors ===================================================================================================
 
     public HttpRequestIntegrationFilterTests() {
-        super();
     }
 
     public HttpRequestIntegrationFilterTests(String arg0) {
@@ -47,18 +46,14 @@ public class HttpRequestIntegrationFilterTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(HttpRequestIntegrationFilterTests.class);
-    }
-
     protected void setUp() throws Exception {
         super.setUp();
-        SecurityContextHolder.getContext().setAuthentication(null);
+        SecurityContextHolder.clearContext();
     }
 
     protected void tearDown() throws Exception {
         super.tearDown();
-        SecurityContextHolder.getContext().setAuthentication(null);
+        SecurityContextHolder.clearContext();
     }
 
     public void testCorrectOperation() throws Exception {

+ 4 - 4
core/src/test/java/org/acegisecurity/context/httpinvoker/AuthenticationSimpleHttpInvokerRequestExecutorTests.java

@@ -52,8 +52,10 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests extends TestCas
 
     //~ Methods ========================================================================================================
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(AuthenticationSimpleHttpInvokerRequestExecutorTests.class);
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
     }
 
     public void testNormalOperation() throws Exception {
@@ -71,8 +73,6 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests extends TestCas
         // See http://www.faqs.org/rfcs/rfc1945.html section 11.1 for example
         // we are comparing against
         assertEquals("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", conn.getRequestProperty("Authorization"));
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testNullContextHolderIsNull() throws Exception {

+ 7 - 7
core/src/test/java/org/acegisecurity/context/rmi/ContextPropagatingRemoteInvocationTests.java

@@ -41,7 +41,6 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
     //~ Constructors ===================================================================================================
 
     public ContextPropagatingRemoteInvocationTests() {
-        super();
     }
 
     public ContextPropagatingRemoteInvocationTests(String arg0) {
@@ -50,6 +49,12 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
+    }
+
     private ContextPropagatingRemoteInvocation getRemoteInvocation()
         throws Exception {
         Class clazz = TargetObject.class;
@@ -61,10 +66,6 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
         return (ContextPropagatingRemoteInvocation) factory.createRemoteInvocation(mi);
     }
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(ContextPropagatingRemoteInvocationTests.class);
-    }
-
     public void testContextIsResetEvenIfExceptionOccurs()
         throws Exception {
         // Setup client-side context
@@ -103,8 +104,7 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
             remoteInvocation.invoke(new TargetObject()));
     }
 
-    public void testNullContextHolderDoesNotCauseInvocationProblems()
-        throws Exception {
+    public void testNullContextHolderDoesNotCauseInvocationProblems() throws Exception {
         SecurityContextHolder.getContext().setAuthentication(null); // just to be explicit
 
         ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();

+ 7 - 9
core/src/test/java/org/acegisecurity/intercept/method/MethodDefinitionAttributesTests.java

@@ -64,6 +64,12 @@ public class MethodDefinitionAttributesTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
+    }
+
     private ConfigAttributeDefinition getConfigAttributeDefinition(Class clazz, String methodName, Class[] args)
         throws Exception {
         final Method method = clazz.getMethod(methodName, args);
@@ -79,10 +85,6 @@ public class MethodDefinitionAttributesTests extends TestCase {
         return config;
     }
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(MethodDefinitionAttributesTests.class);
-    }
-
     private ITargetObject makeInterceptedTarget() {
         ApplicationContext context = new ClassPathXmlApplicationContext(
                 "org/acegisecurity/intercept/method/applicationContext.xml");
@@ -186,8 +188,6 @@ public class MethodDefinitionAttributesTests extends TestCase {
         ITargetObject target = makeInterceptedTarget();
         String result = target.makeUpperCase("hello");
         assertEquals("HELLO org.acegisecurity.MockRunAsAuthenticationToken true", result);
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testMethodCallWithoutRunAsReplacement()
@@ -200,13 +200,11 @@ public class MethodDefinitionAttributesTests extends TestCase {
         String result = target.makeLowerCase("HELLO");
 
         assertEquals("hello org.acegisecurity.providers.UsernamePasswordAuthenticationToken true", result);
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testNullReturnedIfZeroAttributesDefinedForMethodInvocation()
         throws Exception {
-        // SomeDomain is not defined in the MockAttributes() 
+        // SomeDomain is not defined in the MockAttributes()
         // (which getConfigAttributeDefinition refers to)
         ConfigAttributeDefinition def = getConfigAttributeDefinition(SomeDomain.class, "getId", null);
         assertNull(def);

+ 8 - 7
core/src/test/java/org/acegisecurity/intercept/method/aopalliance/MethodSecurityInterceptorTests.java

@@ -70,8 +70,14 @@ public class MethodSecurityInterceptorTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(MethodSecurityInterceptorTests.class);
+    public final void setUp() throws Exception {
+        super.setUp();
+        SecurityContextHolder.clearContext();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
     }
 
     private ITargetObject makeInterceptedTarget() {
@@ -102,11 +108,6 @@ public class MethodSecurityInterceptorTests extends TestCase {
         return (ITargetObject) context.getBean("target");
     }
 
-    public final void setUp() throws Exception {
-        super.setUp();
-        SecurityContextHolder.getContext().setAuthentication(null);
-    }
-
     public void testCallingAPublicMethodFacadeWillNotRepeatSecurityChecksWhenPassedToTheSecuredMethodItFronts()
         throws Exception {
         ITargetObject target = makeInterceptedTarget();

+ 5 - 9
core/src/test/java/org/acegisecurity/intercept/method/aspectj/AspectJSecurityInterceptorTests.java

@@ -47,7 +47,6 @@ public class AspectJSecurityInterceptorTests extends TestCase {
     //~ Constructors ===================================================================================================
 
     public AspectJSecurityInterceptorTests() {
-        super();
     }
 
     public AspectJSecurityInterceptorTests(String arg0) {
@@ -56,14 +55,15 @@ public class AspectJSecurityInterceptorTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(AspectJSecurityInterceptorTests.class);
-    }
-
     public final void setUp() throws Exception {
         super.setUp();
     }
 
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
+    }    
+
     public void testCallbackIsInvokedWhenPermissionGranted()
         throws Exception {
         AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
@@ -94,8 +94,6 @@ public class AspectJSecurityInterceptorTests extends TestCase {
         Object result = si.invoke(joinPoint, aspectJCallback);
 
         assertEquals("object proceeded", result);
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testCallbackIsNotInvokedWhenPermissionDenied()
@@ -131,8 +129,6 @@ public class AspectJSecurityInterceptorTests extends TestCase {
         } catch (AccessDeniedException expected) {
             assertTrue(true);
         }
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     //~ Inner Classes ==================================================================================================

+ 9 - 22
core/src/test/java/org/acegisecurity/intercept/web/FilterSecurityInterceptorTests.java

@@ -57,7 +57,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
     //~ Constructors ===================================================================================================
 
     public FilterSecurityInterceptorTests() {
-        super();
     }
 
     public FilterSecurityInterceptorTests(String arg0) {
@@ -66,12 +65,14 @@ public class FilterSecurityInterceptorTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(FilterSecurityInterceptorTests.class);
-    }
-
     public final void setUp() throws Exception {
         super.setUp();
+        SecurityContextHolder.clearContext();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
     }
 
     public void testEnsuresAccessDecisionManagerSupportsFilterInvocationClass()
@@ -136,8 +137,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
         }
     }
 
-    public void testHttpsInvocationReflectsPortNumber()
-        throws Throwable {
+    public void testHttpsInvocationReflectsPortNumber() throws Throwable {
         // Setup the FilterSecurityInterceptor
         FilterSecurityInterceptor interceptor = new FilterSecurityInterceptor();
         interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
@@ -170,9 +170,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
         // Create and test our secure object
         FilterInvocation fi = new FilterInvocation(request, response, chain);
         interceptor.invoke(fi);
-
-        // Destroy the Context
-        SecurityContextHolder.clearContext();
     }
 
     public void testNormalStartupAndGetter() throws Exception {
@@ -225,9 +222,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
         // Create and test our secure object
         FilterInvocation fi = new FilterInvocation(request, response, chain);
         interceptor.invoke(fi);
-
-        // Destroy the Context
-        SecurityContextHolder.clearContext();
     }
 
     public void testNotLoadedFromApplicationContext() throws Exception {
@@ -239,8 +233,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
         mappings.add(mapping);
 
         PathBasedFilterInvocationDefinitionMap filterInvocationDefinitionSource = new PathBasedFilterInvocationDefinitionMap();
-        filterInvocationDefinitionSource
-                .setConvertUrlToLowercaseBeforeComparison(true);
+        filterInvocationDefinitionSource.setConvertUrlToLowercaseBeforeComparison(true);
         FilterInvocationDefinitionDecorator decorator = new FilterInvocationDefinitionDecorator(
                 filterInvocationDefinitionSource);
         decorator.setMappings(mappings);
@@ -252,8 +245,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
         filterChain.expectToProceed = true;
 
         FilterInvocation fi = new FilterInvocation(
-                new MockHttpServletRequest(), new MockHttpServletResponse(),
-                filterChain);
+                new MockHttpServletRequest(), new MockHttpServletResponse(), filterChain);
         filter.invoke(fi);
     }
 
@@ -267,7 +259,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
         }
 
         private MockFilterChain() {
-            super();
         }
 
         public void doFilter(ServletRequest request, ServletResponse response)
@@ -289,10 +280,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
             this.toReturn = toReturn;
         }
 
-        private MockFilterInvocationDefinitionMap() {
-            super();
-        }
-
         public ConfigAttributeDefinition getAttributes(Object object)
             throws IllegalArgumentException {
             FilterInvocation fi = (FilterInvocation) object;

+ 5 - 16
core/src/test/java/org/acegisecurity/taglibs/authz/AclTagTests.java

@@ -52,6 +52,11 @@ public class AclTagTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
+
+    protected void tearDown() throws Exception {
+        SecurityContextHolder.clearContext();
+    }
+
     public void testInclusionDeniedWhenAclManagerUnawareOfObject()
         throws JspException {
         Authentication auth = new TestingAuthenticationToken("marissa", "koala", new GrantedAuthority[] {});
@@ -60,8 +65,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(new Long(SimpleAclEntry.ADMINISTRATION).toString());
         aclTag.setDomainObject(new Integer(54));
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testInclusionDeniedWhenNoListOfPermissionsGiven()
@@ -72,8 +75,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(null);
         aclTag.setDomainObject("object1");
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testInclusionDeniedWhenPrincipalDoesNotHoldAnyPermissions()
@@ -87,8 +88,6 @@ public class AclTagTests extends TestCase {
         aclTag.setDomainObject("object1");
         assertEquals("object1", aclTag.getDomainObject());
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testInclusionDeniedWhenPrincipalDoesNotHoldRequiredPermissions()
@@ -99,8 +98,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(new Integer(SimpleAclEntry.DELETE).toString());
         aclTag.setDomainObject("object1");
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testInclusionDeniedWhenSecurityContextEmpty()
@@ -110,8 +107,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(new Long(SimpleAclEntry.ADMINISTRATION).toString());
         aclTag.setDomainObject("object1");
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testInclusionPermittedWhenDomainObjectIsNull()
@@ -134,8 +129,6 @@ public class AclTagTests extends TestCase {
         } catch (JspException expected) {
             assertTrue(true);
         }
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testOperationWhenPrincipalHoldsPermissionOfMultipleList()
@@ -146,8 +139,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(new Integer(SimpleAclEntry.ADMINISTRATION) + "," + new Integer(SimpleAclEntry.READ));
         aclTag.setDomainObject("object1");
         assertEquals(Tag.EVAL_BODY_INCLUDE, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testOperationWhenPrincipalHoldsPermissionOfSingleList()
@@ -158,8 +149,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(new Integer(SimpleAclEntry.READ).toString());
         aclTag.setDomainObject("object1");
         assertEquals(Tag.EVAL_BODY_INCLUDE, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     //~ Inner Classes ==================================================================================================

+ 5 - 4
core/src/test/java/org/acegisecurity/taglibs/authz/AuthenticationTagTests.java

@@ -43,6 +43,10 @@ public class AuthenticationTagTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
+    protected void tearDown() throws Exception {
+        SecurityContextHolder.clearContext();
+    }
+
     public void testOperationAndMethodPrefixWhenPrincipalIsAUserDetailsInstance()
         throws JspException {
         Authentication auth = new TestingAuthenticationToken(new User("marissaUserDetails", "koala", true, true, true,
@@ -83,15 +87,12 @@ public class AuthenticationTagTests extends TestCase {
         assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
     }
 
-    public void testOperationWhenSecurityContextIsNull()
-        throws JspException {
+    public void testOperationWhenSecurityContextIsNull() throws Exception {
         SecurityContextHolder.getContext().setAuthentication(null);
 
         authenticationTag.setOperation("principal");
         assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
         assertEquals(null, authenticationTag.getLastMessage());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testSkipsBodyIfNullOrEmptyOperation() throws Exception {

+ 6 - 12
core/src/test/java/org/acegisecurity/taglibs/authz/AuthorizeTagTests.java

@@ -57,16 +57,14 @@ public class AuthorizeTagTests extends TestCase {
         SecurityContextHolder.clearContext();
     }
 
-    public void testAlwaysReturnsUnauthorizedIfNoUserFound()
-        throws JspException {
+    public void testAlwaysReturnsUnauthorizedIfNoUserFound() throws JspException {
         SecurityContextHolder.getContext().setAuthentication(null);
 
         authorizeTag.setIfAllGranted("ROLE_TELLER");
         assertEquals("prevents request - no principal in Context", Tag.SKIP_BODY, authorizeTag.doStartTag());
     }
 
-    public void testDefaultsToNotOutputtingBodyWhenNoRequiredAuthorities()
-        throws JspException {
+    public void testDefaultsToNotOutputtingBodyWhenNoRequiredAuthorities() throws JspException {
         assertEquals("", authorizeTag.getIfAllGranted());
         assertEquals("", authorizeTag.getIfAnyGranted());
         assertEquals("", authorizeTag.getIfNotGranted());
@@ -85,15 +83,13 @@ public class AuthorizeTagTests extends TestCase {
             authorizeTag.doStartTag());
     }
 
-    public void testOutputsBodyWhenNotGrantedSatisfied()
-        throws JspException {
+    public void testOutputsBodyWhenNotGrantedSatisfied() throws JspException {
         authorizeTag.setIfNotGranted("ROLE_BANKER");
         assertEquals("allows request - principal doesn't have ROLE_BANKER", Tag.EVAL_BODY_INCLUDE,
             authorizeTag.doStartTag());
     }
 
-    public void testPreventsBodyOutputIfNoSecurityContext()
-        throws JspException {
+    public void testPreventsBodyOutputIfNoSecurityContext() throws JspException {
         SecurityContextHolder.getContext().setAuthentication(null);
         authorizeTag.setIfAnyGranted("ROLE_BANKER");
 
@@ -105,14 +101,12 @@ public class AuthorizeTagTests extends TestCase {
         assertEquals("unauthorized - ROLE_BANKER not in granted authorities", Tag.SKIP_BODY, authorizeTag.doStartTag());
     }
 
-    public void testSkipsBodyWhenMissingAnAllGranted()
-        throws JspException {
+    public void testSkipsBodyWhenMissingAnAllGranted() throws JspException {
         authorizeTag.setIfAllGranted("ROLE SUPERVISOR,ROLE_TELLER,ROLE_BANKER");
         assertEquals("prevents request - missing ROLE_BANKER on principal", Tag.SKIP_BODY, authorizeTag.doStartTag());
     }
 
-    public void testSkipsBodyWhenNotGrantedUnsatisfied()
-        throws JspException {
+    public void testSkipsBodyWhenNotGrantedUnsatisfied() throws JspException {
         authorizeTag.setIfNotGranted("ROLE_TELLER");
         assertEquals("prevents request - principal has ROLE_TELLER", Tag.SKIP_BODY, authorizeTag.doStartTag());
     }

+ 7 - 11
core/src/test/java/org/acegisecurity/ui/switchuser/SwitchUserProcessingFilterTests.java

@@ -52,7 +52,6 @@ public class SwitchUserProcessingFilterTests extends TestCase {
     //~ Constructors ===================================================================================================
 
     public SwitchUserProcessingFilterTests() {
-        super();
     }
 
     public SwitchUserProcessingFilterTests(String arg0) {
@@ -61,6 +60,11 @@ public class SwitchUserProcessingFilterTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
+
+    protected void tearDown() throws Exception {
+        SecurityContextHolder.clearContext();
+    }
+
     private MockHttpServletRequest createMockSwitchRequest() {
         MockHttpServletRequest request = new MockHttpServletRequest();
         request.setScheme("http");
@@ -70,14 +74,6 @@ public class SwitchUserProcessingFilterTests extends TestCase {
         return request;
     }
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(SwitchUserProcessingFilterTests.class);
-    }
-
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
-
     public void testAttemptSwitchToUnknownUser() throws Exception {
         // set current user
         UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("dano", "hawaii50");
@@ -179,7 +175,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
         Authentication result = filter.attemptSwitchUser(request);
         assertTrue(result != null);
     }
-    
+
     public void testIfSwitchUserWithNullUsernameThrowsException() throws Exception {
         // set current user
         UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("dano", "hawaii50");
@@ -196,7 +192,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
         	 result = filter.attemptSwitchUser(request);
         	 fail("UsernameNotFoundException should have been thrown");
         } catch (UsernameNotFoundException e) {
-        	
+
         }
         assertFalse(result != null);
     }

+ 1 - 1
core/src/test/java/org/acegisecurity/ui/x509/X509ProcessingFilterTests.java

@@ -64,7 +64,7 @@ public class X509ProcessingFilterTests extends TestCase {
     }
 
     public void tearDown() {
-        SecurityContextHolder.getContext().setAuthentication(null);
+        SecurityContextHolder.clearContext();
     }
 
     public void testAuthenticationIsNullWithNoCertificate()

+ 2 - 14
core/src/test/java/org/acegisecurity/wrapper/SecurityContextHolderAwareRequestWrapperTests.java

@@ -37,7 +37,6 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
     //~ Constructors ===================================================================================================
 
     public SecurityContextHolderAwareRequestWrapperTests() {
-        super();
     }
 
     public SecurityContextHolderAwareRequestWrapperTests(String arg0) {
@@ -46,12 +45,9 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(SecurityContextHolderAwareRequestWrapperTests.class);
-    }
 
-    public final void setUp() throws Exception {
-        super.setUp();
+    protected void tearDown() throws Exception {
+        SecurityContextHolder.clearContext();
     }
 
     public void testCorrectOperationWithStringBasedPrincipal()
@@ -69,8 +65,6 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
         assertTrue(wrapper.isUserInRole("ROLE_FOO"));
         assertFalse(wrapper.isUserInRole("ROLE_NOT_GRANTED"));
         assertEquals(auth, wrapper.getUserPrincipal());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testCorrectOperationWithUserDetailsBasedPrincipal()
@@ -91,8 +85,6 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
         assertTrue(wrapper.isUserInRole("ROLE_FOOBAR"));
         assertTrue(wrapper.isUserInRole("ROLE_HELLO"));
         assertEquals(auth, wrapper.getUserPrincipal());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testNullAuthenticationHandling() throws Exception {
@@ -105,8 +97,6 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
         assertNull(wrapper.getRemoteUser());
         assertFalse(wrapper.isUserInRole("ROLE_ANY"));
         assertNull(wrapper.getUserPrincipal());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 
     public void testNullPrincipalHandling() throws Exception {
@@ -123,7 +113,5 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
         assertFalse(wrapper.isUserInRole("ROLE_HELLO")); // principal is null, so reject
         assertFalse(wrapper.isUserInRole("ROLE_FOOBAR")); // principal is null, so reject
         assertNull(wrapper.getUserPrincipal());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
 }

+ 10 - 11
samples/attributes/src/test/java/sample/attributes/BankTests.java

@@ -44,7 +44,6 @@ public class BankTests extends TestCase {
     //~ Constructors ===================================================================================================
 
     public BankTests() {
-        super();
     }
 
     public BankTests(String arg0) {
@@ -53,6 +52,16 @@ public class BankTests extends TestCase {
 
     //~ Methods ========================================================================================================
 
+    public final void setUp() throws Exception {
+        super.setUp();
+        ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
+        service = (BankService) ctx.getBean("bankService");
+    }
+
+    public void tearDown() {
+        SecurityContextHolder.clearContext();
+    }
+
     private static void createSecureContext() {
         TestingAuthenticationToken auth = new TestingAuthenticationToken("test", "test",
                 new GrantedAuthority[] {
@@ -66,16 +75,6 @@ public class BankTests extends TestCase {
         SecurityContextHolder.setContext(new SecurityContextImpl());
     }
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(BankTests.class);
-    }
-
-    public final void setUp() throws Exception {
-        super.setUp();
-        ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
-        service = (BankService) ctx.getBean("bankService");
-    }
-
     public void testDeniedAccess() throws Exception {
         createSecureContext();
 

+ 4 - 0
samples/dms/src/test/java/DmsIntegrationTests.java

@@ -20,6 +20,10 @@ public class DmsIntegrationTests extends AbstractTransactionalDataSourceSpringCo
         return new String[] {"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-insecure.xml"};
     }
 
+    public void tearDown() {
+        SecurityContextHolder.clearContext();
+    }
+
     public void setDocumentDao(DocumentDao documentDao) {
         this.documentDao = documentDao;
     }