[SHIRO-777] remove powermock.
diff --git a/pom.xml b/pom.xml
index a31b45c..39b301a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -114,9 +114,6 @@
<junit.server.jetty.version>0.11.0</junit.server.jetty.version>
<hibernate.version>5.4.3.Final</hibernate.version>
<taglibs.standard.version>1.2.5</taglibs.standard.version>
- <!-- so we can mock static methods in 3rd party libraries that sometimes don't use proper interfaces
- ahem, hazelcast, ahem... -->
- <powermock.version>2.0.2</powermock.version>
<maven.compiler.source>${jdk.version}</maven.compiler.source>
<maven.compiler.target>${jdk.version}</maven.compiler.target>
@@ -636,6 +633,23 @@
</rules>
</configuration>
</execution>
+ <execution>
+ <id>enforce-forbidden-dependencies</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <fail>true</fail>
+ <rules>
+ <bannedDependencies>
+ <excludes>
+ <exclude>*:powermock-api-easymock</exclude>
+ <exclude>*:powermock-module-junit4</exclude>
+ </excludes>
+ </bannedDependencies>
+ </rules>
+ </configuration>
+ </execution>
</executions>
</plugin>
</plugins>
@@ -670,18 +684,6 @@
<version>${groovy.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <version>${powermock.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-easymock</artifactId>
- <version>${powermock.version}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
<dependencyManagement>
diff --git a/support/hazelcast/src/main/java/org/apache/shiro/hazelcast/cache/HazelcastCacheManager.java b/support/hazelcast/src/main/java/org/apache/shiro/hazelcast/cache/HazelcastCacheManager.java
index 68db4c9..a9e69de 100644
--- a/support/hazelcast/src/main/java/org/apache/shiro/hazelcast/cache/HazelcastCacheManager.java
+++ b/support/hazelcast/src/main/java/org/apache/shiro/hazelcast/cache/HazelcastCacheManager.java
@@ -242,4 +242,5 @@
public void setConfig(Config config) {
this.config = config;
}
+
}
diff --git a/support/hazelcast/src/test/groovy/org/apache/shiro/hazelcast/cache/HazelcastCacheManagerTest.groovy b/support/hazelcast/src/test/groovy/org/apache/shiro/hazelcast/cache/HazelcastCacheManagerTest.groovy
index 49b8e4a..e8901a2 100644
--- a/support/hazelcast/src/test/groovy/org/apache/shiro/hazelcast/cache/HazelcastCacheManagerTest.groovy
+++ b/support/hazelcast/src/test/groovy/org/apache/shiro/hazelcast/cache/HazelcastCacheManagerTest.groovy
@@ -19,164 +19,142 @@
package org.apache.shiro.hazelcast.cache
import com.hazelcast.config.Config
-import com.hazelcast.core.Hazelcast
import com.hazelcast.core.HazelcastInstance
-import com.hazelcast.core.IMap
import com.hazelcast.core.LifecycleService
-import org.apache.shiro.cache.MapCache
import org.junit.Test
-import org.junit.runner.RunWith
-import org.powermock.core.classloader.annotations.PrepareForTest
-import org.powermock.modules.junit4.PowerMockRunner
-import static org.easymock.EasyMock.expect
-import static org.easymock.EasyMock.same
+import static org.easymock.EasyMock.*
import static org.junit.Assert.*
-import static org.powermock.api.easymock.PowerMock.*
/**
- * Unit tests for {@link HazelcastCacheManager}. Uses PowerMock to mock Hazelcast's static method calls.
+ * Unit tests for {@link HazelcastCacheManager}.
*
* @since 1.3
*/
-@RunWith(PowerMockRunner)
-@PrepareForTest(Hazelcast)
class HazelcastCacheManagerTest {
@Test
void testGetSetHazelcastInstance() {
- def hc = createStrictMock(HazelcastInstance)
+
+ // given
+ HazelcastInstance hc = mock(HazelcastInstance)
def manager = new HazelcastCacheManager();
- manager.hazelcastInstance = hc
replay hc
+ // when
+ manager.hazelcastInstance = hc
+
+ // then
assertSame hc, manager.hazelcastInstance
verify hc
}
@Test
- void testInit() {
+ void testCustomConfig() {
- mockStatic(Hazelcast)
- //create a mock instead of starting a networked node:
- def hc = createStrictMock(HazelcastInstance)
+ // given
+ Config config = mock(Config)
+ def manager = new HazelcastCacheManager();
- expect(Hazelcast.newHazelcastInstance(null)).andReturn(hc)
+ // when
+ manager.config = config
- replay Hazelcast, hc
+ // then
+ assertSame config, manager.config
+ }
- def manager = new HazelcastCacheManager()
+ @Test
+ void testImplicitlyCreated() {
- try {
- manager.init()
+ // given
+ HazelcastInstance hazelcastInstance = niceMock(HazelcastInstance)
- assertNull manager.config
- assertSame hc, manager.hazelcastInstance
- assertTrue manager.implicitlyCreated
- } finally {
- verify Hazelcast, hc
- }
+ HazelcastCacheManager manager = createMockBuilder(HazelcastCacheManager)
+ .addMockedMethod("createHazelcastInstance")
+ .niceMock();
+ expect(manager.createHazelcastInstance()).andReturn(hazelcastInstance)
+
+ // when
+ manager.init()
+
+ // then
+ assertTrue manager.implicitlyCreated
}
@Test
void testDestroy() {
- mockStatic Hazelcast
- def hc = createStrictMock(HazelcastInstance)
- def lcService = createStrictMock(LifecycleService)
+ // given
+ LifecycleService lifecycleService = niceMock(LifecycleService)
- expect(Hazelcast.newHazelcastInstance(null)).andReturn(hc)
- expect(hc.getLifecycleService()).andReturn(lcService)
- lcService.shutdown()
+ HazelcastInstance hazelcastInstance = niceMock(HazelcastInstance)
+ expect(hazelcastInstance.getLifecycleService()).andReturn(lifecycleService)
- replay Hazelcast, hc, lcService
+ HazelcastCacheManager manager = createMockBuilder(HazelcastCacheManager)
+ .addMockedMethod("createHazelcastInstance")
+ .niceMock();
+ expect(manager.createHazelcastInstance()).andReturn(hazelcastInstance)
- def manager = new HazelcastCacheManager()
- manager.init() //force implicit creation
+ replay lifecycleService, hazelcastInstance, manager
- manager.destroy()
-
- assertNull manager.hazelcastInstance
- assertFalse manager.implicitlyCreated
-
- verify Hazelcast, hc, lcService
- }
-
- @Test
- void testDestroyWithThrowable() {
-
- mockStatic Hazelcast
- def hc = createStrictMock(HazelcastInstance)
- def lcService = createStrictMock(LifecycleService)
-
- expect(Hazelcast.newHazelcastInstance(null)).andReturn(hc)
- expect(hc.getLifecycleService()).andReturn(lcService)
- lcService.shutdown()
- expectLastCall().andThrow(new IllegalStateException())
-
- replay Hazelcast, hc, lcService
-
- def manager = new HazelcastCacheManager()
- manager.init() //force implicit creation
-
- manager.destroy()
-
- assertNull manager.hazelcastInstance
- assertFalse manager.implicitlyCreated
-
- verify Hazelcast, hc, lcService
- }
-
-
- @Test
- void testGetCache() {
-
- mockStatic Hazelcast
- def hc = createStrictMock(HazelcastInstance)
- def hcMap = createStrictMock(IMap)
-
- expect(Hazelcast.newHazelcastInstance(null)).andReturn(hc)
- expect(hc.getMap("foo")).andReturn(hcMap)
-
- replay Hazelcast, hc, hcMap
-
- try {
- def manager = new HazelcastCacheManager()
- def cache = manager.getCache("foo")
-
- assertNotNull cache
- assertTrue cache instanceof MapCache
- assertNotNull cache.map
- assertTrue cache.map instanceof IMap
- } finally {
- verify Hazelcast, hc, hcMap
- }
- }
-
- @Test
- void testCustomConfig() {
-
- mockStatic Hazelcast
-
- def hc = createStrictMock(HazelcastInstance)
- def config = createStrictMock(Config)
-
- expect(Hazelcast.newHazelcastInstance(same(config))).andReturn(hc)
-
- replay Hazelcast, config
-
- def manager = new HazelcastCacheManager()
- manager.config = config
-
+ // when
manager.init()
+ manager.destroy()
- assertSame config, manager.config
- assertSame hc, manager.hazelcastInstance
-
- verify Hazelcast, config
+ // then
+ assertFalse manager.implicitlyCreated
+ assertNull manager.hazelcastInstance
+ verify hazelcastInstance
+ verify manager
}
+ @Test
+ void testDestroyExplicit() {
+
+ // given
+ HazelcastInstance hazelcastInstance = niceMock(HazelcastInstance)
+ HazelcastCacheManager manager = new HazelcastCacheManager()
+ manager.hazelcastInstance = hazelcastInstance
+
+ replay hazelcastInstance
+
+ // when
+ manager.init()
+ manager.destroy()
+
+ // then
+ assertNotNull manager.hazelcastInstance
+ assertFalse manager.implicitlyCreated
+ }
+
+ @Test
+ void testUncleanShutdown() {
+
+ // given
+ LifecycleService lifecycleService = mock(LifecycleService)
+ expect(lifecycleService.shutdown()).andThrow(new IllegalStateException())
+
+ HazelcastInstance hazelcastInstance = mock(HazelcastInstance)
+ expect(hazelcastInstance.getLifecycleService()).andReturn(lifecycleService)
+
+ HazelcastCacheManager manager = createMockBuilder(HazelcastCacheManager)
+ .addMockedMethod("createHazelcastInstance")
+ .niceMock();
+ expect(manager.createHazelcastInstance()).andReturn(hazelcastInstance)
+
+ replay lifecycleService, hazelcastInstance, manager
+
+ // when
+ manager.init()
+ manager.destroy()
+
+ // then
+ assertFalse manager.implicitlyCreated
+ verify lifecycleService
+ verify hazelcastInstance
+ verify manager
+ }
}
diff --git a/web/src/test/java/org/apache/shiro/web/env/EnvironmentLoaderServiceTest.java b/web/src/test/java/org/apache/shiro/web/env/EnvironmentLoaderServiceTest.java
index 18ce9af..250370a 100644
--- a/web/src/test/java/org/apache/shiro/web/env/EnvironmentLoaderServiceTest.java
+++ b/web/src/test/java/org/apache/shiro/web/env/EnvironmentLoaderServiceTest.java
@@ -32,7 +32,7 @@
import static org.hamcrest.MatcherAssert.*;
/**
- * Tests for {@link EnvironmentLoader} that depend on PowerMock the stub out a ServiceLoader.
+ * Tests for {@link EnvironmentLoader} which will use a ServiceLoader.
*/
public class EnvironmentLoaderServiceTest {