diff options
author | Felipe Leme <felipeal@google.com> | 2023-12-07 01:53:28 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-12-07 01:53:28 +0000 |
commit | 21df7de7d070594fff5d7a5e03da20829e892d9f (patch) | |
tree | d55a12897a055c43a37babe13ce4bafc0118d11e | |
parent | a25bba6018c8be30ecd43aebdc0f4e696c0c3cbb (diff) | |
parent | b0af9c5dc49cfd4977f08fd04663491692a5790b (diff) | |
download | modules-utils-21df7de7d070594fff5d7a5e03da20829e892d9f.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: I5c843a88cc414a2d7fbacfef34505d6698b183c0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | java/com/android/modules/utils/testing/AbstractExtendedMockitoRule.java | 19 | ||||
-rw-r--r-- | javatests/com/android/modules/utils/testing/ExtendedMockitoRuleTest.java | 10 |
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); |