public final class ExpectFailure extends Object implements org.junit.rules.TestRule
Subject
fail when they should.
Usage:
AssertionError failure =
expectFailure(whenTesting -> whenTesting.that(cancelButton).isVisible());
assertThat(failure).hasMessageThat().contains("visible");
...
private static AssertionError expectFailure(
ExpectFailure.SimpleSubjectBuilderCallback<UiElementSubject, UiElement> assertionCallback) {
return ExpectFailure.expectFailureAbout(uiElements(), assertionCallback);
}
Or, if you can't use lambdas:
@Rule public final ExpectFailure expectFailure = new ExpectFailure();
... expectFailure.whenTesting().about(uiElements()).that(cancelButton).isVisible(); assertThat(expectFailure.getFailure()).hasMessageThat().contains("visible");
Modifier and Type | Class and Description |
---|---|
static interface |
ExpectFailure.AssertionCallback<B extends TestVerb>
Deprecated.
Implement
ExpectFailure.StandardSubjectBuilderCallback , which is identical except that
its parameter is a StandardSubjectBuilder , the new name of TestVerb . |
static interface |
ExpectFailure.DelegatedAssertionCallback<S extends Subject<S,D>,D>
Deprecated.
Implement
ExpectFailure.SimpleSubjectBuilderCallback , which is identical except that its
parameter is of SimpleSubjectBuilder , the new name of AbstractVerb.DelegatedVerb . |
static interface |
ExpectFailure.SimpleSubjectBuilderCallback<S extends Subject<S,A>,A>
A "functional interface" for
expectFailureAbout() to invoke and
capture failures. |
static interface |
ExpectFailure.StandardSubjectBuilderCallback
A "functional interface" for
expectFailure() to invoke and capture
failures. |
Constructor and Description |
---|
ExpectFailure() |
Modifier and Type | Method and Description |
---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
static AssertionError |
expectFailure(ExpectFailure.AssertionCallback assertionCallback)
Deprecated.
Switch to the overload
of this method that accepts a
ExpectFailure.StandardSubjectBuilderCallback . |
static AssertionError |
expectFailure(ExpectFailure.StandardSubjectBuilderCallback assertionCallback)
Static alternative that directly returns the triggered failure.
|
static <S extends Subject<S,A>,A> |
expectFailureAbout(SubjectFactory<S,A> factory,
ExpectFailure.SimpleSubjectBuilderCallback<S,A> assertionCallback)
Static alternative that directly returns the triggered failure.
|
static <S extends Subject<S,D>,D> |
expectFailureAbout(SubjectFactory<S,D> factory,
ExpectFailure.DelegatedAssertionCallback<S,D> assertionCallback)
Deprecated.
Switch to the overload
of this method that accepts a
ExpectFailure.SimpleSubjectBuilderCallback . |
AssertionError |
getFailure()
Returns the captured failure, if one occurred.
|
StandardSubjectBuilder |
whenTesting()
Returns a test verb that expects the chained assertion to fail, and makes the failure available
via
getFailure() . |
public StandardSubjectBuilder whenTesting()
getFailure()
.
An instance of ExpectFailure
supports only one whenTesting
call per test
method. The static expectFailure(com.google.common.truth.ExpectFailure.AssertionCallback)
method, by contrast, does not have this limitation.
public AssertionError getFailure()
@Deprecated public static AssertionError expectFailure(ExpectFailure.AssertionCallback assertionCallback)
ExpectFailure.StandardSubjectBuilderCallback
.expectThrows()
:
AssertionError failure = expectFailure(whenTesting ->
whenTesting.that(4).isNotEqualTo(4));
public static AssertionError expectFailure(ExpectFailure.StandardSubjectBuilderCallback assertionCallback)
expectThrows()
:
AssertionError failure = expectFailure(whenTesting ->
whenTesting.that(4).isNotEqualTo(4));
@Deprecated public static <S extends Subject<S,D>,D> AssertionError expectFailureAbout(SubjectFactory<S,D> factory, ExpectFailure.DelegatedAssertionCallback<S,D> assertionCallback)
ExpectFailure.SimpleSubjectBuilderCallback
.expectThrows()
:
AssertionError failure = expectFailureAbout(myTypes(), whenTesting ->
whenTesting.that(myType).hasProperty());
public static <S extends Subject<S,A>,A> AssertionError expectFailureAbout(SubjectFactory<S,A> factory, ExpectFailure.SimpleSubjectBuilderCallback<S,A> assertionCallback)
expectThrows()
:
AssertionError failure = expectFailureAbout(myTypes(), whenTesting ->
whenTesting.that(myType).hasProperty());
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
apply
in interface org.junit.rules.TestRule
Copyright © 2017. All rights reserved.