From 70c1debcc6aee8400533131ef278aa30626f05e0 Mon Sep 17 00:00:00 2001 From: Adrien LAUER Date: Fri, 26 Jan 2018 10:09:00 +0100 Subject: [PATCH] Use PowerMock for internal state access --- security/core/pom.xml | 12 ++++++------ .../internal/DefaultSecurityModuleUnitTest.java | 4 ++-- .../SecurityInternalModuleIntegrationTest.java | 4 ++-- .../internal/SecurityInternalModuleUnitTest.java | 8 ++++---- .../internal/realms/ConfigurationRealmUnitTest.java | 4 ++-- web/security/pom.xml | 6 ------ 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/security/core/pom.xml b/security/core/pom.xml index 6f9742628..18f64e5d0 100644 --- a/security/core/pom.xml +++ b/security/core/pom.xml @@ -72,12 +72,6 @@ provided - - org.jmockit - jmockit - ${jmockit.version} - test - org.seedstack.seed seed-testing-junit4 @@ -96,6 +90,12 @@ ${mockito.version} test + + org.powermock + powermock-core + ${powermock.version} + test + org.glassfish javax.el diff --git a/security/core/src/test/java/org/seedstack/seed/security/internal/DefaultSecurityModuleUnitTest.java b/security/core/src/test/java/org/seedstack/seed/security/internal/DefaultSecurityModuleUnitTest.java index 53ee64c6d..acedf742f 100644 --- a/security/core/src/test/java/org/seedstack/seed/security/internal/DefaultSecurityModuleUnitTest.java +++ b/security/core/src/test/java/org/seedstack/seed/security/internal/DefaultSecurityModuleUnitTest.java @@ -16,8 +16,8 @@ import com.google.inject.binder.AnnotatedBindingBuilder; import com.google.inject.binder.AnnotatedElementBuilder; import java.lang.annotation.Annotation; -import mockit.Deencapsulation; import org.junit.Test; +import org.powermock.reflect.Whitebox; public class DefaultSecurityModuleUnitTest { @SuppressWarnings({"rawtypes", "unchecked"}) @@ -31,7 +31,7 @@ public void testShiroModule() { when(ab.annotatedWith(any(Annotation.class))).thenReturn(ab); AnnotatedElementBuilder aeb = mock(AnnotatedElementBuilder.class); when(b.expose(any(Class.class))).thenReturn(aeb); - Deencapsulation.setField(underTest, "binder", b); + Whitebox.setInternalState(underTest, "binder", b); underTest.configureShiro(); } } diff --git a/security/core/src/test/java/org/seedstack/seed/security/internal/SecurityInternalModuleIntegrationTest.java b/security/core/src/test/java/org/seedstack/seed/security/internal/SecurityInternalModuleIntegrationTest.java index bfd092593..905929f16 100644 --- a/security/core/src/test/java/org/seedstack/seed/security/internal/SecurityInternalModuleIntegrationTest.java +++ b/security/core/src/test/java/org/seedstack/seed/security/internal/SecurityInternalModuleIntegrationTest.java @@ -22,10 +22,10 @@ import java.util.Collection; import java.util.HashMap; import java.util.Set; -import mockit.Deencapsulation; import org.apache.shiro.realm.Realm; import org.junit.Before; import org.junit.Test; +import org.powermock.reflect.Whitebox; import org.seedstack.seed.security.SecurityConfig; import org.seedstack.seed.security.internal.authorization.ConfigurationRoleMapping; import org.seedstack.seed.security.internal.authorization.ConfigurationRolePermissionResolver; @@ -66,7 +66,7 @@ public void configure_should_bind_wanted_components() { assertEquals(ShiroRealmAdapter.class, exposedRealm.getClass()); ConfigurationRealm innerRealm = (ConfigurationRealm) ((ShiroRealmAdapter) exposedRealm).getRealm(); - Set users = Deencapsulation.getField(innerRealm, "users"); + Set users = Whitebox.getInternalState(innerRealm, "users"); assertTrue(users.size() > 0); assertNotNull(innerRealm.getRoleMapping()); diff --git a/security/core/src/test/java/org/seedstack/seed/security/internal/SecurityInternalModuleUnitTest.java b/security/core/src/test/java/org/seedstack/seed/security/internal/SecurityInternalModuleUnitTest.java index f398c0ca5..c9cf88288 100644 --- a/security/core/src/test/java/org/seedstack/seed/security/internal/SecurityInternalModuleUnitTest.java +++ b/security/core/src/test/java/org/seedstack/seed/security/internal/SecurityInternalModuleUnitTest.java @@ -24,10 +24,10 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Set; -import mockit.Deencapsulation; import org.apache.shiro.realm.Realm; import org.junit.Before; import org.junit.Test; +import org.powermock.reflect.Whitebox; import org.seedstack.seed.security.SecurityConfig; import org.seedstack.seed.security.internal.realms.ConfigurationRealm; @@ -50,7 +50,7 @@ public void before() { when(binder.skipSources(any(Class.class), any(Class.class))).thenReturn(binder); securityConfigurer = mock(SecurityConfigurer.class); underTest = new SecurityInternalModule(securityConfigurer, new HashMap<>()); - Deencapsulation.setField(underTest, "binder", binder); + Whitebox.setInternalState(underTest, "binder", binder); } @Test @@ -72,8 +72,8 @@ public void testProvider() { Set> realmClasses = new HashSet<>(); realmClasses.add(ConfigurationRealm.class); - Deencapsulation.setField(rp, "injector", i); - Deencapsulation.setField(rp, "realmClasses", realmClasses); + Whitebox.setInternalState(rp, "injector", i); + Whitebox.setInternalState(rp, "realmClasses", realmClasses); Set realms = rp.get(); assertEquals(1, realms.size()); diff --git a/security/core/src/test/java/org/seedstack/seed/security/internal/realms/ConfigurationRealmUnitTest.java b/security/core/src/test/java/org/seedstack/seed/security/internal/realms/ConfigurationRealmUnitTest.java index 0e1f97096..8e688991b 100644 --- a/security/core/src/test/java/org/seedstack/seed/security/internal/realms/ConfigurationRealmUnitTest.java +++ b/security/core/src/test/java/org/seedstack/seed/security/internal/realms/ConfigurationRealmUnitTest.java @@ -13,9 +13,9 @@ import com.google.common.collect.Sets; import java.util.Collections; import java.util.Set; -import mockit.Deencapsulation; import org.junit.Before; import org.junit.Test; +import org.powermock.reflect.Whitebox; import org.seedstack.seed.security.AuthenticationInfo; import org.seedstack.seed.security.AuthenticationToken; import org.seedstack.seed.security.IncorrectCredentialsException; @@ -38,7 +38,7 @@ public class ConfigurationRealmUnitTest { @Before public void before() { underTest = new ConfigurationRealm(null, null); - users = Deencapsulation.getField(underTest, "users"); + users = Whitebox.getInternalState(underTest, "users"); users.add(new ConfigurationUser(username, password, Sets.newHashSet(role1, role2))); users.add(new ConfigurationUser("toto", null, Sets.newHashSet())); } diff --git a/web/security/pom.xml b/web/security/pom.xml index ba24b92f5..7629e65f2 100644 --- a/web/security/pom.xml +++ b/web/security/pom.xml @@ -42,12 +42,6 @@ provided - - org.jmockit - jmockit - ${jmockit.version} - test - junit junit