aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Leme <felipeal@google.com>2023-12-07 01:26:38 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-12-07 01:26:38 +0000
commitce4d5b121a46546d0d4424fa565f2b1e125fcb30 (patch)
treea452fbb39cd274c0c52de68014783cfd62df7334
parent7cb7ba96516b992809ba9c49c6d9f0a57c26ac94 (diff)
parentb0af9c5dc49cfd4977f08fd04663491692a5790b (diff)
downloadmodules-utils-ce4d5b121a46546d0d4424fa565f2b1e125fcb30.tar.gz
Merge "Added AbstractExtendedMockito.getClearInlineMethodsAtTheEnd()." into main am: b0af9c5dc4
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/modules-utils/+/2862586 Change-Id: I9a563c0b129ab742ce968676a04b3950680b7f45 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--java/com/android/modules/utils/testing/AbstractExtendedMockitoRule.java19
-rw-r--r--javatests/com/android/modules/utils/testing/ExtendedMockitoRuleTest.java10
2 files changed, 24 insertions, 5 deletions
diff --git a/java/com/android/modules/utils/testing/AbstractExtendedMockitoRule.java b/java/com/android/modules/utils/testing/AbstractExtendedMockitoRule.java
index 7a0f41b..5256d6a 100644
--- a/java/com/android/modules/utils/testing/AbstractExtendedMockitoRule.java
+++ b/java/com/android/modules/utils/testing/AbstractExtendedMockitoRule.java
@@ -133,8 +133,16 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock
return Collections.unmodifiableSet(staticClasses);
}
-
-
+ /**
+ * Gets whether the rule should clear the inline mocks after the given test.
+ *
+ * <p>By default, it returns {@code} (unless the rule was built with
+ * {@link AbstractBuilder#dontClearInlineMocks()}, but subclasses can override to change the
+ * behavior (for example, to decide based on custom annotations).
+ */
+ protected boolean getClearInlineMethodsAtTheEnd(Description description) {
+ return mClearInlineMocks;
+ }
@Override
public Statement apply(Statement base, Description description) {
@@ -247,12 +255,13 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock
}
}
} finally {
- clearInlineMocks();
+ clearInlineMocks(description);
}
}
- private void clearInlineMocks() {
- if (!mClearInlineMocks) {
+ private void clearInlineMocks(Description description) {
+ boolean clearIt = getClearInlineMethodsAtTheEnd(description);
+ if (!clearIt) {
Log.d(TAG, "NOT calling clearInlineMocks() as set on builder");
return;
}
diff --git a/javatests/com/android/modules/utils/testing/ExtendedMockitoRuleTest.java b/javatests/com/android/modules/utils/testing/ExtendedMockitoRuleTest.java
index 6a80268..765b318 100644
--- a/javatests/com/android/modules/utils/testing/ExtendedMockitoRuleTest.java
+++ b/javatests/com/android/modules/utils/testing/ExtendedMockitoRuleTest.java
@@ -639,6 +639,16 @@ public final class ExtendedMockitoRuleTest {
assertWithMessage("mockito framework cleared").that(mockitoFramework.called).isTrue();
}
+ @Test
+ public void testGetClearInlineMethodsAtTheEnd() throws Throwable {
+ assertWithMessage("getClearInlineMethodsAtTheEnd() by default")
+ .that(mBuilder.build().getClearInlineMethodsAtTheEnd(mDescription)).isTrue();
+ assertWithMessage("getClearInlineMethodsAtTheEnd() when built with dontClearInlineMocks()")
+ .that(mBuilder.dontClearInlineMocks().build()
+ .getClearInlineMethodsAtTheEnd(mDescription))
+ .isFalse();
+ }
+
private void applyRuleOnTestThatDoesntUseExpectation(@Nullable Strictness strictness)
throws Throwable {
Log.d(TAG, "applyRuleOnTestThatDoesntUseExpectation(): strictness= " + strictness);