Skip to content

Commit

Permalink
that() records exceptions instead of throwing them immediately.
Browse files Browse the repository at this point in the history
  • Loading branch information
cowwoc committed Sep 9, 2024
1 parent d95a21d commit a850deb
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 207 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public final class Cake
public int eat()
{
++bitesTaken;
assert that(bitesTaken, "bitesTaken").isNotNegative();
assert that(bitesTaken, "bitesTaken").isNotNegative().elseThrow();

piecesLeft -= ThreadLocalRandom.current().nextInt(5);

assert that(piecesLeft, "piecesLeft").isNotNegative();
assert that(piecesLeft, "piecesLeft").isNotNegative().elseThrow();
return piecesLeft;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public static <K, V, T extends Multimap<K, V>> MultimapValidator<T, K, V> requir
/**
* Validates the state of a {@code Multimap}.
* <p>
* The returned validator throws an exception immediately if a validation fails. This exception is then
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
* <p>
* This method is intended to be used with the {@code assert} keyword, like so:
* {@code assert that(value, name)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public interface GuavaAssertThat
/**
* Validates the state of a {@code Multimap}.
* <p>
* The returned validator throws an exception immediately if a validation fails. This exception is then
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
* <p>
* This method is intended to be used with the {@code assert} keyword, like so:
* {@code assert that(value, name)}.
Expand All @@ -31,8 +32,9 @@ public interface GuavaAssertThat
/**
* Validates the state of a {@code Multimap}.
* <p>
* The returned validator throws an exception immediately if a validation fails. This exception is then
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
* <p>
* This method is intended to be used with the {@code assert} keyword, like so:
* {@code assert that(value, name)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public static <T extends JsonNode> JsonNodeValidator<T> requireThat(T value, Str
/**
* Validates the state of a {@code JsonNode}.
* <p>
* The returned validator throws an exception immediately if a validation fails. This exception is then
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
* <p>
* This method is intended to be used with the {@code assert} keyword, like so:
* {@code assert that(value, name)}.
Expand All @@ -78,8 +79,9 @@ public static <T extends JsonNode> JsonNodeValidator<T> that(T value, String nam
/**
* Validates the state of a {@code JsonNode}.
* <p>
* The returned validator throws an exception immediately if a validation fails. This exception is then
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
* <p>
* This method is intended to be used with the {@code assert} keyword, like so:
* {@code assert that(value, name)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public interface JacksonAssertThat
/**
* Validates the state of a {@code JsonNode}.
* <p>
* The returned validator throws an exception immediately if a validation fails. This exception is then
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
* <p>
* This method is intended to be used with the {@code assert} keyword, like so:
* {@code assert that(value, name)}.
Expand All @@ -30,8 +31,9 @@ public interface JacksonAssertThat
/**
* Validates the state of a {@code JsonNode}.
* <p>
* The returned validator throws an exception immediately if a validation fails. This exception is then
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
* <p>
* This method is intended to be used with the {@code assert} keyword, like so:
* {@code assert that(value, name)}.
Expand Down
Loading

0 comments on commit a850deb

Please sign in to comment.