소스 검색

Added clearContext() in @After. Test was leaving a TestingAuthenticationToken in the context.

Luke Taylor 17 년 전
부모
커밋
13caa48a24
1개의 변경된 파일16개의 추가작업 그리고 12개의 파일을 삭제
  1. 16 12
      core/src/test/java/org/springframework/security/intercept/method/aspectj/AspectJSecurityInterceptorTests.java

+ 16 - 12
core/src/test/java/org/springframework/security/intercept/method/aspectj/AspectJSecurityInterceptorTests.java

@@ -15,10 +15,12 @@
 
 package org.springframework.security.intercept.method.aspectj;
 
-import java.lang.reflect.Method;
+import static org.junit.Assert.*;
 
-import junit.framework.TestCase;
+import java.lang.reflect.Method;
 
+import org.junit.After;
+import org.junit.Test;
 import org.springframework.security.AccessDeniedException;
 import org.springframework.security.GrantedAuthority;
 import org.springframework.security.GrantedAuthorityImpl;
@@ -41,10 +43,16 @@ import org.springframework.security.util.AuthorityUtils;
  * @author Ben Alex
  * @version $Id$
  */
-public class AspectJSecurityInterceptorTests extends TestCase {
+public class AspectJSecurityInterceptorTests {
 
     //~ Methods ========================================================================================================
 
+    @After
+    public void clearContext() {
+        SecurityContextHolder.clearContext();
+    }
+
+    @Test
     public void testCallbackIsInvokedWhenPermissionGranted() throws Exception {
         AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
         si.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
@@ -76,6 +84,7 @@ public class AspectJSecurityInterceptorTests extends TestCase {
         assertEquals("object proceeded", result);
     }
 
+    @Test(expected=AccessDeniedException.class)
     public void testCallbackIsNotInvokedWhenPermissionDenied() throws Exception {
         AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
         si.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
@@ -98,16 +107,11 @@ public class AspectJSecurityInterceptorTests extends TestCase {
         MockAspectJCallback aspectJCallback = new MockAspectJCallback();
         aspectJCallback.setThrowExceptionIfInvoked(true);
 
-        SecurityContextHolder.getContext()
-                             .setAuthentication(new TestingAuthenticationToken("rod", "koala",
-                AuthorityUtils.NO_AUTHORITIES ));
+        SecurityContextHolder.getContext().setAuthentication(
+                new TestingAuthenticationToken("rod", "koala", AuthorityUtils.NO_AUTHORITIES ));
 
-        try {
-            si.invoke(joinPoint, aspectJCallback);
-            fail("Should have thrown AccessDeniedException");
-        } catch (AccessDeniedException expected) {
-            assertTrue(true);
-        }
+        si.invoke(joinPoint, aspectJCallback);
+        fail("Should have thrown AccessDeniedException");
     }
 
     //~ Inner Classes ==================================================================================================