This is an automated email from the ASF dual-hosted git repository.
fpapon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shiro.git
The following commit(s) were added to refs/heads/master by this push:
new b178b23 [SHIRO-777] remove powermock.
new 5be3a50 Merge pull request #235 from bmhm/SHIRO-777-powermock
b178b23 is described below
commit b178b232c9ec9c3d20f7445a59d87b12eb8b2ad5
Author: Benjamin Marwell <[email protected]>
AuthorDate: Tue May 12 06:44:00 2020 +0200
[SHIRO-777] remove powermock.
---
pom.xml | 32 ++--
.../hazelcast/cache/HazelcastCacheManager.java | 1 +
.../cache/HazelcastCacheManagerTest.groovy | 170 +++++++++------------
.../web/env/EnvironmentLoaderServiceTest.java | 2 +-
4 files changed, 93 insertions(+), 112 deletions(-)
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 class HazelcastCacheManager implements CacheManager,
Initializable, Destr
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() {
-
- mockStatic(Hazelcast)
- //create a mock instead of starting a networked node:
- def hc = createStrictMock(HazelcastInstance)
-
- expect(Hazelcast.newHazelcastInstance(null)).andReturn(hc)
-
- replay Hazelcast, hc
+ void testCustomConfig() {
- def manager = new HazelcastCacheManager()
+ // given
+ Config config = mock(Config)
+ def manager = new HazelcastCacheManager();
- try {
- manager.init()
+ // when
+ manager.config = config
- assertNull manager.config
- assertSame hc, manager.hazelcastInstance
- assertTrue manager.implicitlyCreated
- } finally {
- verify Hazelcast, hc
- }
+ // then
+ assertSame config, manager.config
}
@Test
- void testDestroy() {
-
- mockStatic Hazelcast
- def hc = createStrictMock(HazelcastInstance)
- def lcService = createStrictMock(LifecycleService)
+ void testImplicitlyCreated() {
- expect(Hazelcast.newHazelcastInstance(null)).andReturn(hc)
- expect(hc.getLifecycleService()).andReturn(lcService)
- lcService.shutdown()
+ // given
+ HazelcastInstance hazelcastInstance = niceMock(HazelcastInstance)
- 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
-
- manager.destroy()
-
- assertNull manager.hazelcastInstance
- assertFalse manager.implicitlyCreated
+ // when
+ manager.init()
- verify Hazelcast, hc, lcService
+ // then
+ assertTrue manager.implicitlyCreated
}
@Test
- void testDestroyWithThrowable() {
+ 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()
- expectLastCall().andThrow(new IllegalStateException())
+ 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
+ // when
+ manager.init()
manager.destroy()
- assertNull manager.hazelcastInstance
+ // then
assertFalse manager.implicitlyCreated
-
- verify Hazelcast, hc, lcService
+ assertNull manager.hazelcastInstance
+ verify hazelcastInstance
+ verify manager
}
-
@Test
- void testGetCache() {
-
- mockStatic Hazelcast
- def hc = createStrictMock(HazelcastInstance)
- def hcMap = createStrictMock(IMap)
+ void testDestroyExplicit() {
- expect(Hazelcast.newHazelcastInstance(null)).andReturn(hc)
- expect(hc.getMap("foo")).andReturn(hcMap)
+ // given
+ HazelcastInstance hazelcastInstance = niceMock(HazelcastInstance)
+ HazelcastCacheManager manager = new HazelcastCacheManager()
+ manager.hazelcastInstance = hazelcastInstance
- replay Hazelcast, hc, hcMap
+ replay hazelcastInstance
- try {
- def manager = new HazelcastCacheManager()
- def cache = manager.getCache("foo")
+ // when
+ manager.init()
+ manager.destroy()
- assertNotNull cache
- assertTrue cache instanceof MapCache
- assertNotNull cache.map
- assertTrue cache.map instanceof IMap
- } finally {
- verify Hazelcast, hc, hcMap
- }
+ // then
+ assertNotNull manager.hazelcastInstance
+ assertFalse manager.implicitlyCreated
}
@Test
- void testCustomConfig() {
-
- mockStatic Hazelcast
+ void testUncleanShutdown() {
- def hc = createStrictMock(HazelcastInstance)
- def config = createStrictMock(Config)
+ // given
+ LifecycleService lifecycleService = mock(LifecycleService)
+ expect(lifecycleService.shutdown()).andThrow(new
IllegalStateException())
- expect(Hazelcast.newHazelcastInstance(same(config))).andReturn(hc)
+ HazelcastInstance hazelcastInstance = mock(HazelcastInstance)
+
expect(hazelcastInstance.getLifecycleService()).andReturn(lifecycleService)
- replay Hazelcast, config
+ HazelcastCacheManager manager =
createMockBuilder(HazelcastCacheManager)
+ .addMockedMethod("createHazelcastInstance")
+ .niceMock();
+ expect(manager.createHazelcastInstance()).andReturn(hazelcastInstance)
- def manager = new HazelcastCacheManager()
- manager.config = config
+ replay lifecycleService, hazelcastInstance, manager
+ // when
manager.init()
+ manager.destroy()
- assertSame config, manager.config
- assertSame hc, manager.hazelcastInstance
-
- verify Hazelcast, config
+ // 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.Matchers.*;
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 {