aboutsummaryrefslogtreecommitdiff
path: root/dexmaker-mockito-inline-tests
diff options
context:
space:
mode:
authorGarfield Tan <xutan@google.com>2019-09-10 15:29:53 -0700
committerGarfield Tan <xutan@google.com>2019-09-10 15:37:01 -0700
commit40a3dd85ebd10b1adb4e52338f6bce1f119e3235 (patch)
treee421f47e90eaf63d948164fe0ab52e22635897e1 /dexmaker-mockito-inline-tests
parentf3427490718493b3887e1ce8449e3f39421bf964 (diff)
downloaddexmaker-40a3dd85ebd10b1adb4e52338f6bce1f119e3235.tar.gz
Reland "Update to Mockito 2.25.0 and impl InlineMockMaker."
This reverts commit af29ec14cc2419ba013ffd2f66ee26b5541d098d. Bug: 140773999 Test: Builds. Change-Id: I76ce490869000e95f62f7dc9ff0c8fa013dabc71
Diffstat (limited to 'dexmaker-mockito-inline-tests')
-rw-r--r--dexmaker-mockito-inline-tests/build.gradle2
-rw-r--r--dexmaker-mockito-inline-tests/src/main/java/com/android/dx/mockito/inline/tests/MemoryLeaks.java74
2 files changed, 75 insertions, 1 deletions
diff --git a/dexmaker-mockito-inline-tests/build.gradle b/dexmaker-mockito-inline-tests/build.gradle
index c731115..02d0751 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.21.0', { exclude group: 'net.bytebuddy' }
+ api 'org.mockito:mockito-core:2.25.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
new file mode 100644
index 0000000..d78bb10
--- /dev/null
+++ b/dexmaker-mockito-inline-tests/src/main/java/com/android/dx/mockito/inline/tests/MemoryLeaks.java
@@ -0,0 +1,74 @@
+/*
+ * 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;
+ }
+ }
+}