Permalink
Browse files

Fixes #727 Use ByteBuddy to instrument classes instead Javassist: res…

…olve issue with JDK9
  • Loading branch information...
thekingnothing committed Oct 21, 2017
1 parent cec406f commit d1cb563cfb1de79eab925584a3b5c1ebcbce20d0
Showing with 51 additions and 64 deletions.
  1. +0 −16 .travis.yml
  2. +1 −3 powermock-core/src/test/java/org/powermock/core/classloader/MockClassLoaderConfigurationTest.java
  3. +3 −0 powermock-core/src/test/java/org/powermock/core/test/ClassLoaderTestHelper.java
  4. +2 −2 ...ock-core/src/test/java/org/powermock/core/transformers/ClassFinalModifierMockTransformerTest.java
  5. +2 −2 powermock-core/src/test/java/org/powermock/core/transformers/ConstructorCallMockTransformerTest.java
  6. +1 −1 powermock-core/src/test/java/org/powermock/core/transformers/ConstructorsMockTransformerTest.java
  7. +1 −2 powermock-core/src/test/java/org/powermock/core/transformers/InstrumentMockTransformerTest.java
  8. +1 −1 powermock-core/src/test/java/org/powermock/core/transformers/MethodSizeMockTransformerTest.java
  9. +25 −24 powermock-core/src/test/java/org/powermock/core/transformers/MethodsMockTransformerTest.java
  10. +1 −1 powermock-core/src/test/java/org/powermock/core/transformers/MockTransformerChainTest.java
  11. +1 −1 ...mock-core/src/test/java/org/powermock/core/transformers/StaticFinalFieldsMockTransformerTest.java
  12. +1 −1 powermock-core/src/test/java/org/powermock/core/transformers/StaticMethodsMockTransformerTest.java
  13. +1 −1 ...e/src/test/java/org/powermock/core/transformers/SuppressStaticInitializerMockTransformerTest.java
  14. +4 −2 powermock-reflect/src/main/java/org/powermock/reflect/internal/WhiteboxImpl.java
  15. +1 −1 tests/easymock/junit412/src/test/java/samples/junit412/bug/github755/TwoObjectsAnnotatedTest.java
  16. +1 −1 ...o/inline/src/test/java/samples/powermockito/inline/bugs/github793/PowerMockStaticMockingTest.java
  17. +1 −1 ...src/test/java/samples/powermockito/junit4/agent/AssertPowerMockRuleDelagatesToOtherRulesTest.java
  18. +1 −1 ...t/java/samples/powermockito/junit4/rule/xstream/AssertPowerMockRuleDelagatesToOtherRulesTest.java
  19. +1 −1 tests/mockito/junit4/src/test/java/samples/powermockito/junit4/staticmocking/MockStaticCases.java
  20. +1 −1 ...mockito/junit4/src/test/java/samples/powermockito/junit4/verify/VerifyNoMoreInteractionsTest.java
  21. +1 −1 ...s/mockito/junit4/src/test/java/samples/powermockito/junit4/verify/VerifyZeroInteractionsTest.java
@@ -19,29 +19,13 @@ group: edge
language: java
matrix:
allow_failures:
- jdk: openjdk6
env: SKIP_RELEASE=true
- jdk: openjdk7
env: SKIP_RELEASE=true
include:
- jdk: openjdk6
env: SKIP_RELEASE=true
- jdk: openjdk7
env: SKIP_RELEASE=true
- jdk: oraclejdk8
env: SKIP_RELEASE=true
- jdk: oraclejdk9
env: SKIP_RELEASE=true
- jdk: oraclejdk8
# see https://github.com/travis-ci/travis-ci/issues/7253#issuecomment-283670680
addons:
apt:
packages:
- oracle-java9-installer
#Below skips the installation step completely (https://docs.travis-ci.com/user/customizing-the-build/#Skipping-the-Installation-Step)
#We need it because otherwise Travis CI injects an awkward './gradlew assemble' step into the CI workflow
#We want to control and decide what Gradle tasks are executed
@@ -21,10 +21,8 @@
import org.junit.Before;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Java6Assertions.assertThat;
public class MockClassLoaderConfigurationTest {
@@ -20,6 +20,8 @@
import javassist.ClassPool;
import javassist.Loader;
import org.powermock.configuration.GlobalConfiguration;
import org.powermock.configuration.PowerMockConfiguration;
import org.powermock.core.classloader.MockClassLoader;
import org.powermock.core.transformers.MockTransformerChain;
@@ -75,6 +77,7 @@ private static MockClassLoader getMockClassLoader(final MockTransformerChain moc
if (loader == null) {
loader = mockClassloaderFactory.getInstance(new String[]{MockClassLoader.MODIFY_ALL_CLASSES});
loader.setMockTransformerChain(mockTransformerChain);
loader.getConfiguration().addIgnorePackage(GlobalConfiguration.powerMockConfiguration().getGlobalIgnore());
classloaders.put(mockTransformerChain, loader);
}
return loader;
@@ -31,8 +31,8 @@
import java.util.Collection;
import static java.lang.reflect.Modifier.isFinal;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.catchThrowable;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertFalse;
@@ -44,8 +44,8 @@
import java.util.ArrayList;
import java.util.Collection;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.catchThrowable;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assume.assumeThat;
import static org.junit.Assume.assumeTrue;
@@ -31,7 +31,7 @@
import java.util.Collection;
import java.util.Comparator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assume.assumeThat;
@@ -34,8 +34,7 @@
import java.lang.reflect.Field;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.powermock.core.test.ClassLoaderTestHelper.runTestWithNewClassLoader;
public class InstrumentMockTransformerTest extends AbstractBaseMockTransformerTest {
@@ -30,7 +30,7 @@
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.assertNotNull;
@@ -47,8 +47,8 @@
import java.util.ArrayList;
import java.util.Collection;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.Java6Assertions.catchThrowable;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.powermock.core.transformers.mock.MockGatewaySpy.ConditionBuilder.registered;
import static org.powermock.core.transformers.mock.MockGatewaySpy.methodCalls;
@@ -78,8 +78,8 @@ public void should_skip_call_to_void_public_method_if_getaway_return_not_PROCEED
MockGatewaySpy.returnOnMethodCall("voidMethod", "");
final Class<?> clazz = loadWithMockClassLoader(VoidMethodsTestClass.class.getName());
final Object instance = clazz.newInstance();
final Object instance = WhiteboxImpl.newInstance(clazz);
WhiteboxImpl.invokeMethod(instance, "voidMethod", "name", "field", 100d);
@@ -97,8 +97,8 @@ public void should_skip_call_to_final_void_public_method_if_getaway_return_not_P
MockGatewaySpy.returnOnMethodCall("finalVoidMethod", "");
final Class<?> clazz = loadWithMockClassLoader(VoidMethodsTestClass.class.getName());
final Object instance = clazz.newInstance();
final Object instance = WhiteboxImpl.newInstance(clazz);
WhiteboxImpl.invokeMethod(instance, "finalVoidMethod", "name", "field", 100d);
@@ -117,8 +117,8 @@ public void should_return_value_from_getaway_for_non_void_methods_is_it_is_not_P
MockGatewaySpy.returnOnMethodCall("returnMethod", expected);
final Class<?> clazz = loadWithMockClassLoader(ReturnMethodsTestClass.class.getName());
final Object instance = clazz.newInstance();
final Object instance = WhiteboxImpl.newInstance(clazz);
final Object result = WhiteboxImpl.invokeMethod(instance, "returnMethod", "name", "field", 100d);
@@ -136,8 +136,8 @@ public void should_return_value_from_getaway_for_final_non_void_methods_is_it_is
MockGatewaySpy.returnOnMethodCall("finalReturnMethod", expected);
final Class<?> clazz = loadWithMockClassLoader(ReturnMethodsTestClass.class.getName());
final Object instance = clazz.newInstance();
final Object instance = WhiteboxImpl.newInstance(clazz);
final Object result = WhiteboxImpl.invokeMethod(instance, "finalReturnMethod", "name", "field", 100d);
@@ -154,8 +154,8 @@ public void should_return_real_method_return_value_for_non_void_methods_if_getaw
MockGatewaySpy.returnOnMethodCall("returnMethod", MockGateway.PROCEED);
final Class<?> clazz = loadWithMockClassLoader(ReturnMethodsTestClass.class.getName());
final Object instance = clazz.newInstance();
final Object instance = WhiteboxImpl.newInstance(clazz);
final String name = "name";
final Object result = WhiteboxImpl.invokeMethod(instance, "returnMethod", name, "field", 100d);
@@ -174,8 +174,8 @@ public void should_return_real_method_return_value_for_final_non_void_methods_if
MockGatewaySpy.returnOnMethodCall("finalReturnMethod", MockGateway.PROCEED);
final Class<?> clazz = loadWithMockClassLoader(ReturnMethodsTestClass.class.getName());
final Object instance = clazz.newInstance();
final Object instance = WhiteboxImpl.newInstance(clazz);
final String name = "name";
final Object result = WhiteboxImpl.invokeMethod(instance, "finalReturnMethod", name, "field", 100d);
@@ -207,8 +207,8 @@ public void call() throws Throwable {
public void should_modify_bridge_methods() throws Throwable {
final Class<?> clazz = loadWithMockClassLoader(SubclassWithBridgeMethod.class.getName());
Object instance = clazz.newInstance();
final Object instance = WhiteboxImpl.newInstance(clazz);
clazz.getMethod("doSomething", String.class).invoke(instance, "value");
@@ -231,12 +231,13 @@ public void should_ignore_synthetic_non_bridge_methods() throws Throwable {
break;
}
}
Object instance = clazz.newInstance();
if (method != null) {
method.setAccessible(true);
}
final Object instance = WhiteboxImpl.newInstance(clazz);
assertThat(method)
.isNotNull();
method.setAccessible(true);
method.invoke(instance, "");
assertThat(methodCalls())
@@ -251,8 +252,8 @@ public void should_ignore_call_to_synthetic_non_bridge_methods() throws Throwabl
CtClass ctClass = prepareClassesForTest(classPool, "syntheticMethodIsCalled = true;");
final Class<?> clazz = loadWithMockClassLoader(ctClass);
Object instance = clazz.newInstance();
final Object instance = WhiteboxImpl.newInstance(clazz);
clazz.getMethod("doSomething", Object.class).invoke(instance, new Object());
@@ -21,7 +21,7 @@
import org.junit.Test;
import org.powermock.core.transformers.support.DefaultMockTransformerChain;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.assertThat;
public class MockTransformerChainTest {
@@ -31,7 +31,7 @@
import static java.lang.reflect.Modifier.isFinal;
import static java.lang.reflect.Modifier.isTransient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assume.assumeThat;
@@ -34,7 +34,7 @@
import java.util.ArrayList;
import java.util.Collection;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.powermock.core.transformers.mock.MockGatewaySpy.ConditionBuilder.registered;
import static org.powermock.core.transformers.mock.MockGatewaySpy.methodCalls;
@@ -32,7 +32,7 @@
import java.util.ArrayList;
import java.util.Collection;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assume.assumeThat;
@@ -1495,8 +1495,10 @@ private static Object createAndPopulateVarArgsArray(Class<?> varArgsType, int va
});
for (Method method : declaredMethods) {
method.setAccessible(true);
methods.add(method);
if(!"finalize".equals(method.getName())) {
method.setAccessible(true);
methods.add(method);
}
}
Collections.addAll(methods, type.getMethods());
thisType = thisType.getSuperclass();
@@ -8,7 +8,7 @@
import org.powermock.modules.junit4.PowerMockRunner;
import samples.newmocking.SomeDependency;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.assertThat;
@RunWith(PowerMockRunner.class)
public class TwoObjectsAnnotatedTest {
@@ -28,7 +28,7 @@
import org.powermock.modules.junit4.PowerMockRunner;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Java6Assertions.assertThatThrownBy;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.when;
@@ -27,7 +27,7 @@
import java.util.LinkedList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.assertThat;
/**
* This test demonstrates that the PowerMockRule delegates to other rules.
@@ -28,7 +28,7 @@
import java.util.List;
import static junit.framework.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.junit.Assert.assertEquals;
/**
@@ -28,7 +28,7 @@
import samples.singleton.StaticService;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Java6Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
@@ -27,7 +27,7 @@
import samples.singleton.StaticHelper;
import samples.singleton.StaticService;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Java6Assertions.assertThatThrownBy;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.times;
import static org.powermock.api.mockito.PowerMockito.mock;
@@ -29,7 +29,7 @@
import samples.singleton.StaticExample;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Java6Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;

0 comments on commit d1cb563

Please sign in to comment.