Skip to content

Commit

Permalink
Use PowerMock for internal state access
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Jan 26, 2018
1 parent 6621dea commit 70c1deb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 22 deletions.
12 changes: 6 additions & 6 deletions security/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>${jmockit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-testing-junit4</artifactId>
Expand All @@ -96,6 +90,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -72,8 +72,8 @@ public void testProvider() {
Set<Class<? extends org.seedstack.seed.security.Realm>> 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<Realm> realms = rp.get();
assertEquals(1, realms.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
}
Expand Down
6 changes: 0 additions & 6 deletions web/security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>${jmockit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down

0 comments on commit 70c1deb

Please sign in to comment.