diff options
13 files changed, 19 insertions, 131 deletions
diff --git a/README.version b/README.version index 61b27e5..991a2e6 100644 --- a/README.version +++ b/README.version @@ -1,5 +1,5 @@ URL: https://github.com/linkedin/dexmaker/ -Version: master (c58ffebcbb2564c7d1fa6fb58b48f351c330296d) +Version: master (8ff85edb2793cc1e0f6a93c67b127cb9c43d924e) License: Apache 2.0 Description: Dexmaker is a Java-language API for doing compile time or runtime code generation targeting the Dalvik VM. Unlike cglib or ASM, this library creates Dalvik .dex files instead of Java .class files. diff --git a/dexmaker-mockito-inline-extended-tests/build.gradle b/dexmaker-mockito-inline-extended-tests/build.gradle index e930123..fcff13c 100644 --- a/dexmaker-mockito-inline-extended-tests/build.gradle +++ b/dexmaker-mockito-inline-extended-tests/build.gradle @@ -47,8 +47,8 @@ dependencies { androidTestImplementation project(':dexmaker-mockito-inline-extended') implementation 'junit:junit:4.12' - implementation 'androidx.test:runner:1.1.1' - implementation 'androidx.test:rules:1.1.1' + implementation 'com.android.support.test:runner:1.0.2' + implementation 'com.android.support.test:rules:1.0.2' - api 'org.mockito:mockito-core:2.25.0', { exclude group: 'net.bytebuddy' } + api 'org.mockito:mockito-core:2.21.0', { exclude group: 'net.bytebuddy' } } diff --git a/dexmaker-mockito-inline-extended/build.gradle b/dexmaker-mockito-inline-extended/build.gradle index fee152e..3234e33 100644 --- a/dexmaker-mockito-inline-extended/build.gradle +++ b/dexmaker-mockito-inline-extended/build.gradle @@ -119,5 +119,5 @@ repositories { dependencies { implementation project(':dexmaker-mockito-inline') - implementation 'org.mockito:mockito-core:2.25.0', { exclude group: 'net.bytebuddy' } + implementation 'org.mockito:mockito-core:2.21.0', { exclude group: 'net.bytebuddy' } } diff --git a/dexmaker-mockito-inline-extended/src/main/java/com/android/dx/mockito/inline/StaticMockMethodAdvice.java b/dexmaker-mockito-inline-extended/src/main/java/com/android/dx/mockito/inline/StaticMockMethodAdvice.java index 7a6f273..18c1bcc 100644 --- a/dexmaker-mockito-inline-extended/src/main/java/com/android/dx/mockito/inline/StaticMockMethodAdvice.java +++ b/dexmaker-mockito-inline-extended/src/main/java/com/android/dx/mockito/inline/StaticMockMethodAdvice.java @@ -152,7 +152,7 @@ class StaticMockMethodAdvice { return subclasses; } - private synchronized static native String nativeGetCalledClassName(Thread currentThread); + private synchronized static native String nativeGetCalledClassName(); private Class<?> getClassMethodWasCalledOn(MethodDesc methodDesc) throws ClassNotFoundException, NoSuchMethodException { @@ -183,7 +183,7 @@ class StaticMockMethodAdvice { return null; } - String calledClassName = nativeGetCalledClassName(Thread.currentThread()); + String calledClassName = nativeGetCalledClassName(); return Class.forName(calledClassName); } } diff --git a/dexmaker-mockito-inline-extended/src/main/jni/staticjvmtiagent/agent.cc b/dexmaker-mockito-inline-extended/src/main/jni/staticjvmtiagent/agent.cc index 5fcc4b1..3956893 100644 --- a/dexmaker-mockito-inline-extended/src/main/jni/staticjvmtiagent/agent.cc +++ b/dexmaker-mockito-inline-extended/src/main/jni/staticjvmtiagent/agent.cc @@ -747,9 +747,7 @@ namespace com_android_dx_mockito_inline { extern "C" JNIEXPORT jstring JNICALL Java_com_android_dx_mockito_inline_StaticMockMethodAdvice_nativeGetCalledClassName(JNIEnv* env, - jclass klass, - jthread currentThread) { - + jclass klass) { JavaVM *vm; jint jvmError = env->GetJavaVM(&vm); if (jvmError != JNI_OK) { @@ -806,7 +804,7 @@ namespace com_android_dx_mockito_inline { GOTO_ON_ERROR(unregister_env_and_exit); error = jvmtiEnv->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, - currentThread); + nullptr); GOTO_ON_ERROR(unset_cb_and_exit); frameToInspect = &frameInfo[callingFrameNum]; @@ -815,7 +813,7 @@ namespace com_android_dx_mockito_inline { disable_hook_and_exit: jvmtiEnv->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, - currentThread); + nullptr); unset_cb_and_exit: memset(&cb, 0, sizeof(cb)); diff --git a/dexmaker-mockito-inline-tests/build.gradle b/dexmaker-mockito-inline-tests/build.gradle index b5d3a68..c731115 100644 --- a/dexmaker-mockito-inline-tests/build.gradle +++ b/dexmaker-mockito-inline-tests/build.gradle @@ -49,6 +49,6 @@ dependencies { androidTestImplementation project(':dexmaker-mockito-inline') implementation 'junit:junit:4.12' - implementation 'androidx.test:runner:1.1.1' - api 'org.mockito:mockito-core:2.25.0', { exclude group: 'net.bytebuddy' } + implementation 'com.android.support.test:runner:1.0.2' + api 'org.mockito:mockito-core:2.21.0', { exclude group: 'net.bytebuddy' } } diff --git a/dexmaker-mockito-inline-tests/src/main/java/com/android/dx/mockito/inline/tests/MemoryLeaks.java b/dexmaker-mockito-inline-tests/src/main/java/com/android/dx/mockito/inline/tests/MemoryLeaks.java deleted file mode 100644 index d78bb10..0000000 --- a/dexmaker-mockito-inline-tests/src/main/java/com/android/dx/mockito/inline/tests/MemoryLeaks.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dx.mockito.inline.tests; - -import static org.mockito.Mockito.framework; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; - -import androidx.test.runner.AndroidJUnit4; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(AndroidJUnit4.class) -public class MemoryLeaks { - private static final int ARRAY_LENGTH = 1 << 20; // 4 MB - - @Test - public void callMethodWithMocksCycalically() { - for (int i = 0; i < 100; ++i) { - final A a = mock(A.class); - a.largeArray = new int[ARRAY_LENGTH]; - final B b = mock(B.class); - - a.accept(b); - b.accept(a); - - framework().clearInlineMocks(); - } - } - - @Test - public void spyRefersToItself() { - for (int i = 0; i < 100; ++i) { - final DeepRefSelfClass instance = spy(new DeepRefSelfClass()); - instance.refInstance(instance); - - framework().clearInlineMocks(); - } - } - - private static class A { - private int[] largeArray; - - void accept(B b) {} - } - - private static class B { - void accept(A a) {} - } - - private static class DeepRefSelfClass { - private final DeepRefSelfClass[] array = new DeepRefSelfClass[1]; - - private final int[] largeArray = new int[ARRAY_LENGTH]; - - private void refInstance(DeepRefSelfClass instance) { - array[0] = instance; - } - } -} diff --git a/dexmaker-mockito-inline/build.gradle b/dexmaker-mockito-inline/build.gradle index 00913a4..8ca3d3c 100644 --- a/dexmaker-mockito-inline/build.gradle +++ b/dexmaker-mockito-inline/build.gradle @@ -113,6 +113,6 @@ repositories { dependencies { implementation project(':dexmaker') - implementation 'org.mockito:mockito-core:2.25.0', { exclude group: 'net.bytebuddy' } + implementation 'org.mockito:mockito-core:2.21.0', { exclude group: 'net.bytebuddy' } } diff --git a/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/InlineDexmakerMockMaker.java b/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/InlineDexmakerMockMaker.java index 0a594e0..fc2a641 100644 --- a/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/InlineDexmakerMockMaker.java +++ b/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/InlineDexmakerMockMaker.java @@ -29,7 +29,6 @@ import org.mockito.exceptions.base.MockitoException; import org.mockito.internal.util.reflection.LenientCopyTool; import org.mockito.invocation.MockHandler; import org.mockito.mock.MockCreationSettings; -import org.mockito.plugins.InlineMockMaker; import org.mockito.plugins.InstantiatorProvider2; import org.mockito.plugins.MockMaker; @@ -55,7 +54,7 @@ import java.util.Set; * <p>This is done by transforming the byte code of the classes to add method entry hooks. */ -public final class InlineDexmakerMockMaker implements InlineMockMaker { +public final class InlineDexmakerMockMaker implements MockMaker { private static final String DISPATCHER_CLASS_NAME = "com.android.dx.mockito.inline.MockMethodDispatcher"; private static final String DISPATCHER_JAR = "dispatcher.jar"; @@ -347,16 +346,6 @@ public final class InlineDexmakerMockMaker implements InlineMockMaker { } @Override - public void clearMock(Object mock) { - mocks.remove(mock); - } - - @Override - public void clearAllMocks() { - mocks.clear(); - } - - @Override public MockHandler getHandler(Object mock) { InvocationHandlerAdapter adapter = getInvocationHandlerAdapter(mock); return adapter != null ? adapter.getHandler() : null; diff --git a/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/MockMakerMultiplexer.java b/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/MockMakerMultiplexer.java index 8949d46..c5f8db6 100644 --- a/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/MockMakerMultiplexer.java +++ b/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/MockMakerMultiplexer.java @@ -20,7 +20,6 @@ import android.util.Log; import org.mockito.invocation.MockHandler; import org.mockito.mock.MockCreationSettings; -import org.mockito.plugins.InlineMockMaker; import org.mockito.plugins.MockMaker; import java.lang.reflect.InvocationTargetException; @@ -29,7 +28,7 @@ import java.util.ArrayList; /** * Multiplexes multiple mock makers */ -public final class MockMakerMultiplexer implements InlineMockMaker { +public final class MockMakerMultiplexer implements MockMaker { private static final String LOG_TAG = MockMakerMultiplexer.class.getSimpleName(); private final static MockMaker[] MOCK_MAKERS; @@ -104,28 +103,4 @@ public final class MockMakerMultiplexer implements InlineMockMaker { return null; } - - @Override - public void clearMock(Object mock) { - for (MockMaker mockMaker : MOCK_MAKERS) { - if (!(mockMaker instanceof InlineMockMaker)) { - continue; - } - - InlineMockMaker inlineMockMaker = (InlineMockMaker) mockMaker; - inlineMockMaker.clearMock(mock); - } - } - - @Override - public void clearAllMocks() { - for (MockMaker mockMaker : MOCK_MAKERS) { - if (!(mockMaker instanceof InlineMockMaker)) { - continue; - } - - InlineMockMaker inlineMockMaker = (InlineMockMaker) mockMaker; - inlineMockMaker.clearAllMocks(); - } - } } diff --git a/dexmaker-mockito-tests/build.gradle b/dexmaker-mockito-tests/build.gradle index fece14e..f051535 100644 --- a/dexmaker-mockito-tests/build.gradle +++ b/dexmaker-mockito-tests/build.gradle @@ -40,7 +40,7 @@ dependencies { compileOnly project(':dexmaker-mockito') androidTestImplementation project(':dexmaker-mockito') - implementation 'androidx.test:runner:1.1.1' + implementation 'com.android.support.test:runner:0.5' implementation 'junit:junit:4.12' - api 'org.mockito:mockito-core:2.25.0', { exclude group: 'net.bytebuddy' } + api 'org.mockito:mockito-core:2.21.0', { exclude group: 'net.bytebuddy' } } diff --git a/dexmaker-mockito/build.gradle b/dexmaker-mockito/build.gradle index b15b30c..46cdd8f 100644 --- a/dexmaker-mockito/build.gradle +++ b/dexmaker-mockito/build.gradle @@ -26,5 +26,5 @@ repositories { dependencies { implementation project(':dexmaker') - implementation 'org.mockito:mockito-core:2.25.0', { exclude group: 'net.bytebuddy' } + implementation 'org.mockito:mockito-core:2.21.0', { exclude group: 'net.bytebuddy' } } diff --git a/dexmaker-tests/build.gradle b/dexmaker-tests/build.gradle index 7b2552c..5ae5f2d 100644 --- a/dexmaker-tests/build.gradle +++ b/dexmaker-tests/build.gradle @@ -36,6 +36,6 @@ dependencies { implementation project(":dexmaker") //noinspection GradleDependency - androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'com.android.support.test:runner:0.5' androidTestImplementation 'junit:junit:4.12' } |