You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bm...@apache.org on 2023/06/22 19:52:08 UTC
[shiro] branch #947_junit-jupiter updated: [#947] rewrite more groovy tests to Junit-Jupiter
This is an automated email from the ASF dual-hosted git repository.
bmarwell pushed a commit to branch #947_junit-jupiter
in repository https://gitbox.apache.org/repos/asf/shiro.git
The following commit(s) were added to refs/heads/#947_junit-jupiter by this push:
new df4305f64 [#947] rewrite more groovy tests to Junit-Jupiter
df4305f64 is described below
commit df4305f64ddff3642d3b2186be9911480a393281
Author: Benjamin Marwell <bm...@apache.org>
AuthorDate: Thu Jun 22 21:51:58 2023 +0200
[#947] rewrite more groovy tests to Junit-Jupiter
---
.../shiro/authc/AbstractAuthenticatorTest.java | 19 +++++++++----
pom.xml | 4 +--
.../AopAllianceMethodInvocationAdapterTest.java | 32 +++++++++++-----------
.../web/jaxrs/ShiroSecurityContextTest.groovy | 4 +--
web/pom.xml | 5 ++++
.../IniFilterChainResolverFactoryTest.groovy | 4 +--
.../mgt/DefaultFilterChainManagerTest.groovy | 4 +--
.../mgt/DefaultWebSessionManagerTest.groovy | 8 +++---
.../org/apache/shiro/web/util/WebUtilsTest.groovy | 4 +--
.../apache/shiro/web/servlet/SimpleCookieTest.java | 32 ++++------------------
10 files changed, 54 insertions(+), 62 deletions(-)
diff --git a/core/src/test/java/org/apache/shiro/authc/AbstractAuthenticatorTest.java b/core/src/test/java/org/apache/shiro/authc/AbstractAuthenticatorTest.java
index 0659ca7be..daadfbfdf 100644
--- a/core/src/test/java/org/apache/shiro/authc/AbstractAuthenticatorTest.java
+++ b/core/src/test/java/org/apache/shiro/authc/AbstractAuthenticatorTest.java
@@ -18,12 +18,16 @@
*/
package org.apache.shiro.authc;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.test.appender.ListAppender;
-import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
-import org.junit.ClassRule;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.net.URI;
+
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
@@ -35,12 +39,18 @@ import static org.junit.jupiter.api.Assertions.*;
*/
public class AbstractAuthenticatorTest {
- @ClassRule
- public static LoggerContextRule loggerContextRule = new LoggerContextRule("log4j2-list.xml");
+ static ListAppender listAppender;
AbstractAuthenticator abstractAuthenticator;
private final SimpleAuthenticationInfo info = new SimpleAuthenticationInfo("user1", "secret", "realmName");
+ @BeforeAll
+ static void setUpLogger() {
+ LoggerContext loggerContext = (LoggerContext) LogManager.getContext(AbstractAuthenticatorTest.class.getClassLoader(), false, URI.create("log4j2-list.xml"));
+ Configuration configuration = loggerContext.getConfiguration();
+ listAppender = configuration.getAppender("List");
+ }
+
private AbstractAuthenticator createAuthcReturnNull() {
return new AbstractAuthenticator() {
protected AuthenticationInfo doAuthenticate(AuthenticationToken token) throws AuthenticationException {
@@ -184,7 +194,6 @@ public class AbstractAuthenticatorTest {
}catch(AuthenticationException expectedException){
}
- final ListAppender listAppender = loggerContextRule.getListAppender("List");
String logMsg = String.join("\n", listAppender.getMessages());
assertTrue(logMsg.contains("WARN"));
assertTrue(logMsg.contains("java.lang.IllegalArgumentException: "+ expectedExceptionMessage));
diff --git a/pom.xml b/pom.xml
index a5af5687d..b9ef21c25 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1086,8 +1086,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/aop/AopAllianceMethodInvocationAdapterTest.java b/support/guice/src/test/java/org/apache/shiro/guice/aop/AopAllianceMethodInvocationAdapterTest.java
index 817e5717f..a06b5c547 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/aop/AopAllianceMethodInvocationAdapterTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/aop/AopAllianceMethodInvocationAdapterTest.java
@@ -18,14 +18,14 @@
*/
package org.apache.shiro.guice.aop;
-import org.aopalliance.intercept.MethodInvocation;
+import org.aopalliance.intercept.MethodInvocation;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Method;
-import static org.easymock.EasyMock.*;
-import static org.junit.jupiter.api.Assertions.assertSame;
-
+import static org.easymock.EasyMock.*;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
/**
* Created by IntelliJ IDEA.
* User: jbunting
@@ -33,9 +33,9 @@ import static org.junit.jupiter.api.Assertions.assertSame;
* Time: 5:02 PM
* To change this template use File | Settings | File Templates.
*/
-public class AopAllianceMethodInvocationAdapterTest {
- @Test
- void testGetMethod() throws Exception {
+public class AopAllianceMethodInvocationAdapterTest {
+ @Test
+ public void testGetMethod() throws Exception {
MethodInvocation mock = createMock(MethodInvocation.class);
Method method = AopAllianceMethodInvocationAdapterTest.class.getMethod("testGetMethod");
expect(mock.getMethod()).andReturn(method);
@@ -46,9 +46,9 @@ public class AopAllianceMethodInvocationAdapterTest {
assertSame(method, underTest.getMethod());
verify(mock);
- }
-
- @Test
+ }
+
+ @Test
void testGetArguments() throws Exception {
MethodInvocation mock = createMock(MethodInvocation.class);
Object[] args = new Object[0];
@@ -60,9 +60,9 @@ public class AopAllianceMethodInvocationAdapterTest {
assertSame(args, underTest.getArguments());
verify(mock);
- }
-
- @Test
+ }
+
+ @Test
void testProceed() throws Throwable {
MethodInvocation mock = createMock(MethodInvocation.class);
Object value = new Object();
@@ -74,9 +74,9 @@ public class AopAllianceMethodInvocationAdapterTest {
assertSame(value, underTest.proceed());
verify(mock);
- }
-
- @Test
+ }
+
+ @Test
void testGetThis() throws Exception {
MethodInvocation mock = createMock(MethodInvocation.class);
Object value = new Object();
diff --git a/support/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ShiroSecurityContextTest.groovy b/support/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ShiroSecurityContextTest.groovy
index 8b0efc79e..84fbadc8f 100644
--- a/support/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ShiroSecurityContextTest.groovy
+++ b/support/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ShiroSecurityContextTest.groovy
@@ -21,7 +21,7 @@ package org.apache.shiro.web.jaxrs
import org.apache.shiro.subject.SimplePrincipalCollection
import org.apache.shiro.subject.Subject
import org.apache.shiro.util.ThreadContext
-import org.junit.After
+import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import javax.ws.rs.container.ContainerRequestContext
@@ -183,7 +183,7 @@ class ShiroSecurityContextTest {
verify requestContext, originalSecurityContext, subject
}
- @After
+ @AfterEach
void cleanUp() {
ThreadContext.remove()
}
diff --git a/web/pom.xml b/web/pom.xml
index b7e4fade1..10622e3c4 100644
--- a/web/pom.xml
+++ b/web/pom.xml
@@ -85,6 +85,11 @@
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/web/src/test/groovy/org/apache/shiro/web/config/IniFilterChainResolverFactoryTest.groovy b/web/src/test/groovy/org/apache/shiro/web/config/IniFilterChainResolverFactoryTest.groovy
index cdf7bb032..0c45bda08 100644
--- a/web/src/test/groovy/org/apache/shiro/web/config/IniFilterChainResolverFactoryTest.groovy
+++ b/web/src/test/groovy/org/apache/shiro/web/config/IniFilterChainResolverFactoryTest.groovy
@@ -21,6 +21,7 @@ package org.apache.shiro.web.config
import org.apache.shiro.web.filter.InvalidRequestFilter
import org.apache.shiro.web.filter.mgt.DefaultFilter
import org.hamcrest.Matchers
+import org.junit.jupiter.api.BeforeEach
import javax.servlet.Filter
import javax.servlet.FilterConfig
@@ -29,7 +30,6 @@ import org.apache.shiro.config.Ini
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter
import org.apache.shiro.web.filter.authz.SslFilter
import org.apache.shiro.web.filter.mgt.FilterChainResolver
-import org.junit.Before
import org.junit.jupiter.api.Test
import static org.easymock.EasyMock.*
@@ -52,7 +52,7 @@ class IniFilterChainResolverFactoryTest {
return mock
}
- @Before
+ @BeforeEach
void setUp() {
this.factory = new IniFilterChainResolverFactory()
}
diff --git a/web/src/test/groovy/org/apache/shiro/web/filter/mgt/DefaultFilterChainManagerTest.groovy b/web/src/test/groovy/org/apache/shiro/web/filter/mgt/DefaultFilterChainManagerTest.groovy
index a01904bca..dc72f8c29 100644
--- a/web/src/test/groovy/org/apache/shiro/web/filter/mgt/DefaultFilterChainManagerTest.groovy
+++ b/web/src/test/groovy/org/apache/shiro/web/filter/mgt/DefaultFilterChainManagerTest.groovy
@@ -22,12 +22,12 @@ import org.apache.shiro.config.ConfigurationException
import org.apache.shiro.web.filter.authz.SslFilter
import org.apache.shiro.web.servlet.ShiroFilter
import org.hamcrest.Matchers
+import org.junit.jupiter.api.BeforeEach
import javax.servlet.Filter
import javax.servlet.FilterChain
import javax.servlet.FilterConfig
import javax.servlet.ServletContext
-import org.junit.Before
import org.junit.jupiter.api.Test
import static org.easymock.EasyMock.*
@@ -41,7 +41,7 @@ class DefaultFilterChainManagerTest {
DefaultFilterChainManager manager;
- @Before
+ @BeforeEach
void setUp() {
this.manager = new DefaultFilterChainManager();
}
diff --git a/web/src/test/groovy/org/apache/shiro/web/session/mgt/DefaultWebSessionManagerTest.groovy b/web/src/test/groovy/org/apache/shiro/web/session/mgt/DefaultWebSessionManagerTest.groovy
index 57fdaf020..4b0895c7c 100644
--- a/web/src/test/groovy/org/apache/shiro/web/session/mgt/DefaultWebSessionManagerTest.groovy
+++ b/web/src/test/groovy/org/apache/shiro/web/session/mgt/DefaultWebSessionManagerTest.groovy
@@ -24,8 +24,8 @@ import org.apache.shiro.web.servlet.Cookie
import org.apache.shiro.web.servlet.ShiroHttpServletRequest
import org.apache.shiro.web.servlet.ShiroHttpSession
import org.apache.shiro.web.servlet.SimpleCookie
-import org.junit.After
-import org.junit.Before
+import org.junit.jupiter.api.AfterEach
+import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import javax.servlet.ServletRequest
@@ -46,12 +46,12 @@ public class DefaultWebSessionManagerTest {
DefaultWebSessionManager mgr;
- @Before
+ @BeforeEach
void setUp() {
this.mgr = new DefaultWebSessionManager()
}
- @After
+ @AfterEach
public void clearThread() {
ThreadContext.remove();
}
diff --git a/web/src/test/groovy/org/apache/shiro/web/util/WebUtilsTest.groovy b/web/src/test/groovy/org/apache/shiro/web/util/WebUtilsTest.groovy
index 1d7cc53eb..fb9ea8682 100644
--- a/web/src/test/groovy/org/apache/shiro/web/util/WebUtilsTest.groovy
+++ b/web/src/test/groovy/org/apache/shiro/web/util/WebUtilsTest.groovy
@@ -19,14 +19,14 @@
package org.apache.shiro.web.util
import org.apache.shiro.web.RestoreSystemProperties
-import org.hamcrest.CoreMatchers
import org.junit.jupiter.api.Test
import javax.servlet.http.HttpServletRequest
import static org.easymock.EasyMock.*
+import static org.hamcrest.MatcherAssert.*
+import static org.hamcrest.Matchers.*
import static org.junit.jupiter.api.Assertions.*
-import static org.hamcrest.CoreMatchers.*
/**
* Tests for {@link WebUtils}.
diff --git a/web/src/test/java/org/apache/shiro/web/servlet/SimpleCookieTest.java b/web/src/test/java/org/apache/shiro/web/servlet/SimpleCookieTest.java
index 03c6131e7..81b98d61f 100644
--- a/web/src/test/java/org/apache/shiro/web/servlet/SimpleCookieTest.java
+++ b/web/src/test/java/org/apache/shiro/web/servlet/SimpleCookieTest.java
@@ -18,9 +18,8 @@
*/
package org.apache.shiro.web.servlet;
-import junit.framework.TestCase;
import org.easymock.IArgumentMatcher;
-import org.junit.Before;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import javax.servlet.http.HttpServletRequest;
@@ -28,20 +27,21 @@ import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
import static org.easymock.EasyMock.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* TODO - Class JavaDoc
*
* @since Apr 22, 2010 9:40:47 PM
*/
-public class SimpleCookieTest extends TestCase {
+public class SimpleCookieTest {
private SimpleCookie cookie;
private HttpServletRequest mockRequest;
private HttpServletResponse mockResponse;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
this.mockRequest = createMock(HttpServletRequest.class);
this.mockResponse = createMock(HttpServletResponse.class);
@@ -150,29 +150,7 @@ public class SimpleCookieTest extends TestCase {
replay(mockResponse);
this.cookie.setPath("/foo");
- assertEquals(null, this.cookie.readValue(mockRequest, mockResponse));
- }
-
- private static <T extends javax.servlet.http.Cookie> T eqCookie(final T in) {
- reportMatcher(new IArgumentMatcher() {
- public boolean matches(Object o) {
- javax.servlet.http.Cookie c = (javax.servlet.http.Cookie) o;
- return c.getName().equals(in.getName()) &&
- c.getValue().equals(in.getValue()) &&
- c.getPath().equals(in.getPath()) &&
- c.getMaxAge() == in.getMaxAge() &&
- c.getSecure() == in.getSecure() &&
- c.getValue().equals(in.getValue());
- }
-
- public void appendTo(StringBuffer sb) {
- sb.append("eqCookie(");
- sb.append(in.getClass().getName());
- sb.append(")");
-
- }
- });
- return null;
+ assertNull(this.cookie.readValue(mockRequest, mockResponse));
}
}