diff options
-rw-r--r-- | Android.bp | 12 | ||||
-rw-r--r-- | OWNERS | 1 | ||||
-rw-r--r-- | README.md | 21 | ||||
-rw-r--r-- | README.version | 3 | ||||
-rw-r--r-- | TEST_MAPPING | 28 | ||||
-rw-r--r-- | dexmaker-mockito-inline-extended-tests/build.gradle | 2 | ||||
-rw-r--r-- | dexmaker-mockito-inline-extended/build.gradle | 2 | ||||
-rw-r--r-- | dexmaker-mockito-inline-tests/build.gradle | 2 | ||||
-rw-r--r-- | dexmaker-mockito-inline-tests/src/main/java/com/android/dx/mockito/inline/tests/MemoryLeaks.java | 74 | ||||
-rw-r--r-- | dexmaker-mockito-inline/build.gradle | 2 | ||||
-rw-r--r-- | dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/InlineDexmakerMockMaker.java | 13 | ||||
-rw-r--r-- | dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/MockMakerMultiplexer.java | 27 | ||||
-rw-r--r-- | dexmaker-mockito-tests/build.gradle | 2 | ||||
-rw-r--r-- | dexmaker-mockito-tests/src/main/java/com/android/dx/mockito/tests/Stress.java | 4 | ||||
-rw-r--r-- | dexmaker-mockito/build.gradle | 2 |
15 files changed, 33 insertions, 162 deletions
@@ -40,7 +40,7 @@ java_library_static { // Build dispatcher for Dexmaker's inline MockMaker java_library_static { name: "dexmaker-inline-mockmaker-dispatcher", - sdk_version: "core_current", + sdk_version: "current", srcs: ["dexmaker-mockito-inline-dispatcher/src/main/java/**/*.java"], } @@ -77,8 +77,8 @@ cc_defaults { "libz", ], - header_libs: [ - "libopenjdkjvmti_headers", + include_dirs: [ + "art/openjdkjvmti/include", ], } @@ -145,6 +145,7 @@ java_library_static { // methods. java_library_static { name: "mockito-target", + no_framework_libs: true, static_libs: [ "mockito-target-minus-junit4", "junit", @@ -155,6 +156,7 @@ java_library_static { // Same as mockito-target but does not bundle junit java_library_static { name: "mockito-target-minus-junit4", + no_framework_libs: true, static_libs: [ "mockito", "dexmaker", @@ -172,6 +174,7 @@ java_library_static { // Project depending on this also need to depend on the static JNI library libdexmakerjvmtiagent java_library_static { name: "mockito-target-inline", + no_framework_libs: true, static_libs: [ "mockito-target-inline-minus-junit4", "junit", @@ -182,6 +185,7 @@ java_library_static { // Same as mockito-target-inline but does not bundle junit java_library_static { name: "mockito-target-inline-minus-junit4", + no_framework_libs: true, static_libs: [ "mockito", "dexmaker", @@ -200,6 +204,7 @@ java_library_static { // libdexmakerjvmtiagent java_library_static { name: "mockito-target-extended", + no_framework_libs: true, static_libs: [ "mockito-target-extended-minus-junit4", "junit", @@ -210,6 +215,7 @@ java_library_static { // Same as mockito-target-extended but does not bundle junit java_library_static { name: "mockito-target-extended-minus-junit4", + no_framework_libs: true, static_libs: [ "mockito", "dexmaker", @@ -1,4 +1,3 @@ jmonk@google.com paulduffin@google.com moltmann@google.com -xutan@google.com @@ -107,18 +107,19 @@ public final class HelloWorldMaker { Use it in your app ------------------ -For Mockito support, download the latest .jar via Maven: -```xml - <dependency> - <groupId>com.linkedin.dexmaker</groupId> - <artifactId>dexmaker-mockito</artifactId> - <version>2.25.0</version> - <type>pom</type> - </dependency> -``` +Maven users can get dexmaker from Sonatype's central repository. The Mockito dependency is optional. ``` - androidTestCompile 'com.linkedin.dexmaker:dexmaker-mockito:2.25.0' + <dependency> + <groupId>com.google.dexmaker</groupId> + <artifactId>dexmaker</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>com.google.dexmaker</groupId> + <artifactId>dexmaker-mockito</artifactId> + <version>1.2</version> + </dependency> ``` Download [dexmaker-1.2.jar](http://search.maven.org/remotecontent?filepath=com/google/dexmaker/dexmaker/1.2/dexmaker-1.2.jar) diff --git a/README.version b/README.version index 4de4834..a4a21f2 100644 --- a/README.version +++ b/README.version @@ -14,6 +14,3 @@ Local Modifications: Do not read Build.VERSION to allow non-standard Android distributions (Ia8c4ba4c82cd6f193c565f1bfe48faffc4aac08f) Temporarily ignore failing test (Ibf7b6c2eb05c5ff83f0817f9224369e20c0b775d) Restrict InspectClass to current thread. (Ic62951ff81bed60ac7512455fad65210e4b728a9, need upstreaming) - Exclude Stress#mockALot from presubmit (Ic9a2927ffa07924bd759429e31c56dc1b71a826c) - Extend timeout of Stress#mockALot() for CTS. (Iad30a8cb07b38054b490b7006d11908fc752a024) - Update to Mockito 2.25.0 and impl InlineMockMaker (29a8674036d345e4ec8635b1d38d8b2a4fe91980a, need upstreaming) diff --git a/TEST_MAPPING b/TEST_MAPPING index 365ab7d..cd6767e 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,36 +1,16 @@ { "postsubmit": [ { - "name": "CtsMockingTestCases", - "options": [ - { - "exclude-annotation": "androidx.test.filters.LargeTest" - } - ] + "name": "CtsMockingTestCases" }, { - "name": "CtsInlineMockingTestCases", - "options": [ - { - "exclude-annotation": "androidx.test.filters.LargeTest" - } - ] + "name": "CtsInlineMockingTestCases" }, { - "name": "CtsMockingDebuggableTestCases", - "options": [ - { - "exclude-annotation": "androidx.test.filters.LargeTest" - } - ] + "name": "CtsMockingDebuggableTestCases" }, { - "name": "CtsExtendedMockingTestCases", - "options": [ - { - "exclude-annotation": "androidx.test.filters.LargeTest" - } - ] + "name": "CtsExtendedMockingTestCases" } ] } diff --git a/dexmaker-mockito-inline-extended-tests/build.gradle b/dexmaker-mockito-inline-extended-tests/build.gradle index b5664f2..fcff13c 100644 --- a/dexmaker-mockito-inline-extended-tests/build.gradle +++ b/dexmaker-mockito-inline-extended-tests/build.gradle @@ -50,5 +50,5 @@ dependencies { 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-tests/build.gradle b/dexmaker-mockito-inline-tests/build.gradle index 02d0751..c731115 100644 --- a/dexmaker-mockito-inline-tests/build.gradle +++ b/dexmaker-mockito-inline-tests/build.gradle @@ -50,5 +50,5 @@ dependencies { implementation 'junit:junit:4.12' implementation 'com.android.support.test:runner: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-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 9379d17..f051535 100644 --- a/dexmaker-mockito-tests/build.gradle +++ b/dexmaker-mockito-tests/build.gradle @@ -42,5 +42,5 @@ dependencies { 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-tests/src/main/java/com/android/dx/mockito/tests/Stress.java b/dexmaker-mockito-tests/src/main/java/com/android/dx/mockito/tests/Stress.java index 6b96f13..573ed67 100644 --- a/dexmaker-mockito-tests/src/main/java/com/android/dx/mockito/tests/Stress.java +++ b/dexmaker-mockito-tests/src/main/java/com/android/dx/mockito/tests/Stress.java @@ -24,7 +24,6 @@ import static org.mockito.Mockito.when; import android.util.Log; -import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; import org.junit.Test; @@ -41,8 +40,7 @@ public class Stress { } } - @LargeTest - @Test(timeout=600000) + @Test public void mockALot() { for (int i = 0; i < NUM_TESTS; i++) { if (i % 1024 == 0) { 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' } } |