public final class Criteria {
public static <T> void checkThat(T actual, Matcher<T> matcher) {
if (matcher.matches(actual)) return;
Description description = new StringDescription();
description.appendText("Expected: ")
.appendDescriptionOf(matcher)
.appendText(System.lineSeparator())
.appendText(" but: ");
matcher.describeMismatch(actual, description);
throw new CriteriaNotSatisfiedException(description.toString());
}
... potentially other helper methods ...CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
if (doesUrlBarHaveFocus(urlBar) != active) {
updateFailureReason(
"URL Bar did not have expected focus: " + active);
return false;
}
updateFailureReason(
"The keyboard did not reach the expected active state: "
+ active);
return isKeyboardActiveForView(urlBar) == active;
}
});
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(“URL Bar did not have expected focus”,
doesUrlBarHaveFocus(urlBar), Matchers.is(active));
Criteria.checkThat(
"The keyboard did not reach the expected active state",
isKeyboardActiveForView(urlBar), Matchers.is(active));
});
This proposal sounds good to me!Similar to the open question, do we keep the Callable<Boolean> variation for ease of use? I guess we only need to slightly revise toAssertionRunnable() to fit the new exception.
On Fri, May 29, 2020 at 8:59 AM Bo Liu <bo...@chromium.org> wrote:So the major difference from the existing refactoring is using CriteriaNotSatisfiedException rather than AssertionError to indicate that the criteria is not satisfied.
--
You received this message because you are subscribed to the Google Groups "java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/java/CAFs4gPq_4uyaUUFtMe5Ak5NpzJOx9RxSc2VcZVq0nzVgo_vOVw%40mail.gmail.com.