Remove PowerMock
Issue gh-611
This commit is contained in:
@@ -34,6 +34,7 @@ dependencies {
|
||||
testImplementation "commons-lang:commons-lang"
|
||||
testImplementation "gsbase:gsbase"
|
||||
testImplementation "org.mockito:mockito-core"
|
||||
testImplementation "org.mockito:mockito-inline"
|
||||
testImplementation "org.springframework:spring-test"
|
||||
testImplementation "org.assertj:assertj-core"
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.ldap.transaction.compensating.manager.TransactionAwar
|
||||
import org.springframework.ldap.transaction.compensating.support.DefaultTempEntryRenamingStrategy;
|
||||
import org.springframework.ldap.transaction.compensating.support.DifferentSubtreeTempEntryRenamingStrategy;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
@@ -44,11 +45,11 @@ import javax.naming.CannotProceedException;
|
||||
import javax.naming.CommunicationException;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.internal.util.reflection.Whitebox.getInternalState;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
@@ -73,7 +74,7 @@ public class LdapTemplateNamespaceHandlerTest {
|
||||
assertThat(new String[]{"ldap://localhost:389"}).isEqualTo((Object[]) getInternalState(contextSource, "urls"));
|
||||
assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "pooled"));
|
||||
assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly"));
|
||||
assertThat(getInternalState(contextSource, "referral")).isNull();
|
||||
assertThat((Object) getInternalState(contextSource, "referral")).isNull();
|
||||
|
||||
assertThat(outerContextSource).isSameAs(getInternalState(ldapTemplate, "contextSource"));
|
||||
assertThat(Boolean.FALSE).isEqualTo(getInternalState(ldapTemplate, "ignorePartialResultException"));
|
||||
@@ -183,7 +184,7 @@ public class LdapTemplateNamespaceHandlerTest {
|
||||
assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
|
||||
ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
|
||||
|
||||
assertArrayEquals(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" },
|
||||
assertArrayEquals(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" },
|
||||
(Object[]) getInternalState(contextSource, "urls"));
|
||||
|
||||
}
|
||||
@@ -283,8 +284,8 @@ public class LdapTemplateNamespaceHandlerTest {
|
||||
assertThat(pooledContextSource instanceof PoolingContextSource).isTrue();
|
||||
|
||||
Object objectFactory = getInternalState(pooledContextSource, "dirContextPoolableObjectFactory");
|
||||
assertThat(getInternalState(objectFactory, "contextSource")).isNotNull();
|
||||
assertThat(getInternalState(objectFactory, "dirContextValidator")).isNull();
|
||||
assertThat((Object) getInternalState(objectFactory, "contextSource")).isNotNull();
|
||||
assertThat((Object) getInternalState(objectFactory, "dirContextValidator")).isNull();
|
||||
Set<Class<? extends Throwable>> nonTransientExceptions =
|
||||
(Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
|
||||
assertThat(nonTransientExceptions).hasSize(1);
|
||||
@@ -366,11 +367,11 @@ public class LdapTemplateNamespaceHandlerTest {
|
||||
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
|
||||
assertThat(pooledContextSource).isNotNull();
|
||||
assertThat(pooledContextSource instanceof PooledContextSource).isTrue();
|
||||
assertThat(getInternalState(pooledContextSource, "poolConfig")).isNotNull();
|
||||
assertThat((Object) getInternalState(pooledContextSource, "poolConfig")).isNotNull();
|
||||
|
||||
Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory");
|
||||
assertThat(getInternalState(objectFactory, "contextSource")).isNotNull();
|
||||
assertThat(getInternalState(objectFactory, "dirContextValidator")).isNull();
|
||||
assertThat((Object) getInternalState(objectFactory, "contextSource")).isNotNull();
|
||||
assertThat((Object) getInternalState(objectFactory, "dirContextValidator")).isNull();
|
||||
Set<Class<? extends Throwable>> nonTransientExceptions =
|
||||
(Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
|
||||
assertThat(nonTransientExceptions).hasSize(1);
|
||||
@@ -523,4 +524,10 @@ public class LdapTemplateNamespaceHandlerTest {
|
||||
assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(14);
|
||||
assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18);
|
||||
}
|
||||
|
||||
private <T> T getInternalState(Object target, String fieldName) {
|
||||
Field field = ReflectionUtils.findField(target.getClass(), fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T) ReflectionUtils.getField(field, target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,15 @@ package org.springframework.ldap.core.support;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.internal.util.reflection.Whitebox;
|
||||
import org.springframework.ldap.core.ContextExecutor;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.LdapOperations;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -58,7 +59,7 @@ public class SingleContextSourceTest {
|
||||
operations.executeReadOnly(new ContextExecutor<Object>() {
|
||||
@Override
|
||||
public Object executeWithContext(DirContext ctx) throws NamingException {
|
||||
Object targetContex = Whitebox.getInternalState(Proxy.getInvocationHandler(ctx), "target");
|
||||
Object targetContex = getInternalState(Proxy.getInvocationHandler(ctx), "target");
|
||||
assertThat(targetContex).isSameAs(dirContextMock);
|
||||
return false;
|
||||
}
|
||||
@@ -69,7 +70,7 @@ public class SingleContextSourceTest {
|
||||
operations.executeReadOnly(new ContextExecutor<Object>() {
|
||||
@Override
|
||||
public Object executeWithContext(DirContext ctx) throws NamingException {
|
||||
Object targetContex = Whitebox.getInternalState(Proxy.getInvocationHandler(ctx), "target");
|
||||
Object targetContex = getInternalState(Proxy.getInvocationHandler(ctx), "target");
|
||||
assertThat(targetContex).isSameAs(dirContextMock);
|
||||
return false;
|
||||
}
|
||||
@@ -80,4 +81,9 @@ public class SingleContextSourceTest {
|
||||
});
|
||||
}
|
||||
|
||||
private <T> T getInternalState(Object target, String fieldName) {
|
||||
Field field = ReflectionUtils.findField(target.getClass(), fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T) ReflectionUtils.getField(field, target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.springframework.ldap.odm.core.impl;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.powermock.api.mockito.PowerMockito.spy;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -13,18 +11,18 @@ import javax.naming.Name;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.internal.util.reflection.Whitebox;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.core.SpringVersion;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(SpringVersion.class)
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultObjectDirectoryMapperTest {
|
||||
|
||||
private DefaultObjectDirectoryMapper tested;
|
||||
@@ -37,13 +35,12 @@ public class DefaultObjectDirectoryMapperTest {
|
||||
// LDAP-295
|
||||
@Test
|
||||
public void springVersionIsNull() {
|
||||
spy(SpringVersion.class);
|
||||
when(SpringVersion.getVersion()).thenReturn(null);
|
||||
|
||||
DefaultObjectDirectoryMapper mapper = new DefaultObjectDirectoryMapper();
|
||||
|
||||
// LDAP-300
|
||||
assertThat(Whitebox.getInternalState(mapper,"converterManager")).isNotNull();
|
||||
try (MockedStatic<SpringVersion> version = Mockito.mockStatic(SpringVersion.class)) {
|
||||
version.when(SpringVersion::getVersion).thenReturn(null);
|
||||
DefaultObjectDirectoryMapper mapper = new DefaultObjectDirectoryMapper();
|
||||
// LDAP-300
|
||||
assertThat((Object) getInternalState(mapper,"converterManager")).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,4 +137,10 @@ public class DefaultObjectDirectoryMapperTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T getInternalState(Object target, String fieldName) {
|
||||
Field field = ReflectionUtils.findField(target.getClass(), fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T) ReflectionUtils.getField(field, target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,15 @@ package org.springframework.ldap.pool.factory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.internal.util.reflection.Whitebox;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.pool.AbstractPoolTestCase;
|
||||
import org.springframework.ldap.pool.DirContextType;
|
||||
import org.springframework.ldap.pool.validation.DirContextValidator;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
@@ -101,7 +103,7 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase {
|
||||
|
||||
final Object createdDirContext = objectFactory.makeObject(DirContextType.READ_ONLY);
|
||||
InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext);
|
||||
assertThat(readOnlyContextMock).isEqualTo(Whitebox.getInternalState(invocationHandler, "target"));
|
||||
assertThat(readOnlyContextMock).isEqualTo(getInternalState(invocationHandler, "target"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,7 +118,7 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase {
|
||||
final Object createdDirContext = objectFactory.makeObject(DirContextType.READ_WRITE);
|
||||
|
||||
InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext);
|
||||
assertThat(readWriteContextMock).isEqualTo(Whitebox.getInternalState(invocationHandler, "target"));
|
||||
assertThat(readWriteContextMock).isEqualTo(getInternalState(invocationHandler, "target"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,4 +219,10 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase {
|
||||
objectFactory.destroyObject(DirContextType.READ_ONLY, throwingDirContextMock);
|
||||
verify(dirContextMock).close();
|
||||
}
|
||||
|
||||
private <T> T getInternalState(Object target, String fieldName) {
|
||||
Field field = ReflectionUtils.findField(target.getClass(), fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T) ReflectionUtils.getField(field, target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,15 @@ package org.springframework.ldap.pool2.factory;
|
||||
import org.apache.commons.pool2.PooledObject;
|
||||
import org.apache.commons.pool2.impl.DefaultPooledObject;
|
||||
import org.junit.Test;
|
||||
import org.mockito.internal.util.reflection.Whitebox;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.pool2.DirContextType;
|
||||
import org.springframework.ldap.pool2.validation.DirContextValidator;
|
||||
import org.springframework.ldap.pool2.AbstractPoolTestCase;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
@@ -103,7 +105,7 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
|
||||
|
||||
final PooledObject createdDirContext = objectFactory.makeObject(DirContextType.READ_ONLY);
|
||||
InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext.getObject());
|
||||
assertThat(readOnlyContextMock).isEqualTo(Whitebox.getInternalState(invocationHandler, "target"));
|
||||
assertThat(readOnlyContextMock).isEqualTo(getInternalState(invocationHandler, "target"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +120,7 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
|
||||
final PooledObject createdDirContext = objectFactory.makeObject(DirContextType.READ_WRITE);
|
||||
|
||||
InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext.getObject());
|
||||
assertThat(readWriteContextMock).isEqualTo(Whitebox.getInternalState(invocationHandler, "target"));
|
||||
assertThat(readWriteContextMock).isEqualTo(getInternalState(invocationHandler, "target"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,4 +229,10 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
|
||||
objectFactory.destroyObject(DirContextType.READ_ONLY, pooledObject);
|
||||
verify(dirContextMock).close();
|
||||
}
|
||||
|
||||
private <T> T getInternalState(Object target, String fieldName) {
|
||||
Field field = ReflectionUtils.findField(target.getClass(), fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T) ReflectionUtils.getField(field, target);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user