Skip to content

Commit a850deb

Browse files
committed
that() records exceptions instead of throwing them immediately.
1 parent d95a21d commit a850deb

File tree

9 files changed

+309
-207
lines changed

9 files changed

+309
-207
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public final class Cake
5050
public int eat()
5151
{
5252
++bitesTaken;
53-
assert that(bitesTaken, "bitesTaken").isNotNegative();
53+
assert that(bitesTaken, "bitesTaken").isNotNegative().elseThrow();
5454

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

57-
assert that(piecesLeft, "piecesLeft").isNotNegative();
57+
assert that(piecesLeft, "piecesLeft").isNotNegative().elseThrow();
5858
return piecesLeft;
5959
}
6060

guava/src/main/java/com/github/cowwoc/requirements10/guava/DefaultGuavaValidators.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ public static <K, V, T extends Multimap<K, V>> MultimapValidator<T, K, V> requir
5858
/**
5959
* Validates the state of a {@code Multimap}.
6060
* <p>
61-
* The returned validator throws an exception immediately if a validation fails. This exception is then
62-
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
61+
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
62+
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
63+
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
6364
* <p>
6465
* This method is intended to be used with the {@code assert} keyword, like so:
6566
* {@code assert that(value, name)}.

guava/src/main/java/com/github/cowwoc/requirements10/guava/GuavaAssertThat.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ public interface GuavaAssertThat
1111
/**
1212
* Validates the state of a {@code Multimap}.
1313
* <p>
14-
* The returned validator throws an exception immediately if a validation fails. This exception is then
15-
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
14+
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
15+
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
16+
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
1617
* <p>
1718
* This method is intended to be used with the {@code assert} keyword, like so:
1819
* {@code assert that(value, name)}.
@@ -31,8 +32,9 @@ public interface GuavaAssertThat
3132
/**
3233
* Validates the state of a {@code Multimap}.
3334
* <p>
34-
* The returned validator throws an exception immediately if a validation fails. This exception is then
35-
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
35+
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
36+
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
37+
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
3638
* <p>
3739
* This method is intended to be used with the {@code assert} keyword, like so:
3840
* {@code assert that(value, name)}.

jackson/src/main/java/com/github/cowwoc/requirements10/jackson/DefaultJacksonValidators.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ public static <T extends JsonNode> JsonNodeValidator<T> requireThat(T value, Str
5757
/**
5858
* Validates the state of a {@code JsonNode}.
5959
* <p>
60-
* The returned validator throws an exception immediately if a validation fails. This exception is then
61-
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
60+
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
61+
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
62+
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
6263
* <p>
6364
* This method is intended to be used with the {@code assert} keyword, like so:
6465
* {@code assert that(value, name)}.
@@ -78,8 +79,9 @@ public static <T extends JsonNode> JsonNodeValidator<T> that(T value, String nam
7879
/**
7980
* Validates the state of a {@code JsonNode}.
8081
* <p>
81-
* The returned validator throws an exception immediately if a validation fails. This exception is then
82-
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
82+
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
83+
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
84+
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
8385
* <p>
8486
* This method is intended to be used with the {@code assert} keyword, like so:
8587
* {@code assert that(value, name)}.

jackson/src/main/java/com/github/cowwoc/requirements10/jackson/JacksonAssertThat.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ public interface JacksonAssertThat
1212
/**
1313
* Validates the state of a {@code JsonNode}.
1414
* <p>
15-
* The returned validator throws an exception immediately if a validation fails. This exception is then
16-
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
15+
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
16+
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
17+
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
1718
* <p>
1819
* This method is intended to be used with the {@code assert} keyword, like so:
1920
* {@code assert that(value, name)}.
@@ -30,8 +31,9 @@ public interface JacksonAssertThat
3031
/**
3132
* Validates the state of a {@code JsonNode}.
3233
* <p>
33-
* The returned validator throws an exception immediately if a validation fails. This exception is then
34-
* converted into an {@link AssertionError}. Exceptions unrelated to validation failures are not converted.
34+
* The returned validator captures exceptions on validation failure rather than throwing them immediately.
35+
* The exceptions are converted into an {@link AssertionError} and can be retrieved or thrown once the
36+
* validation completes. Exceptions unrelated to validation failures are thrown immediately.
3537
* <p>
3638
* This method is intended to be used with the {@code assert} keyword, like so:
3739
* {@code assert that(value, name)}.

0 commit comments

Comments
 (0)