diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java index ca3a54215d12..b174c9e7ee33 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java @@ -226,15 +226,16 @@ public class GeckoSessionTestRule extends UiThreadTestRule { @Retention(RetentionPolicy.RUNTIME) public @interface AssertCalled { /** - * @return True if the method must be called, + * @return True if the method must be called if count != 0, * or false if the method must not be called. */ boolean value() default true; /** - * @return If called, the number of calls called, or 0 to allow any number > 0. + * @return The number of calls allowed. Specify -1 to allow any number > 0. Specify 0 to + * assert the method is not called, even if value() is true. */ - int count() default 0; + int count() default -1; /** * @return If called, the order number for each call, or 0 to allow arbitrary @@ -325,8 +326,8 @@ public class GeckoSessionTestRule extends UiThreadTestRule { } /* package */ int getCount() { - return (requirement == null) ? 0 : - !requirement.allowed ? -1 : requirement.count; + return (requirement == null) ? -1 : + requirement.allowed ? requirement.count : 0; } /* package */ void incrementCounter() { @@ -338,12 +339,12 @@ public class GeckoSessionTestRule extends UiThreadTestRule { } /* package */ boolean allowUnlimitedCalls() { - return getCount() == 0; + return getCount() == -1; } /* package */ boolean allowMoreCalls() { final int count = getCount(); - return count == 0 || count > currentCount; + return count == -1 || count > currentCount; } /* package */ CallInfo getInfo() { @@ -569,9 +570,9 @@ public class GeckoSessionTestRule extends UiThreadTestRule { private void assertAllowMoreCalls(final MethodCall call) { final int count = call.getCount(); - if (count != 0) { + if (count != -1) { assertThat(call.method.getName() + " call count should be within limit", - call.getCurrentCount() + 1, lessThanOrEqualTo(Math.max(0, count))); + call.getCurrentCount() + 1, lessThanOrEqualTo(count)); } } @@ -588,10 +589,10 @@ public class GeckoSessionTestRule extends UiThreadTestRule { return; } final int count = call.getCount(); - if (count < 0) { + if (count == 0) { assertThat(call.method.getName() + " should not be called", call.getCurrentCount(), equalTo(0)); - } else if (count == 0) { + } else if (count == -1) { assertThat(call.method.getName() + " should be called", call.getCurrentCount(), greaterThan(0)); } else {