Skip to content

Commit

Permalink
Fix checked double supplier attempt test.
Browse files Browse the repository at this point in the history
  • Loading branch information
RezzedUp committed Feb 3, 2022
1 parent 2133d2b commit 8fec4a8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/test/java/com/rezzedup/util/exceptional/AttemptTests.java
Expand Up @@ -85,12 +85,14 @@ private void test(Attempt attempt, Function<Class<? extends Throwable>, Consumer
maybe.assertIfResultExists(optional -> assertTrue(optional.isEmpty()));
}

// Test a checked long supplier that throws an ArithmeticException (divides by zero)
// Test a checked long supplier that throws an ArithmeticException
{
Result<OptionalDouble> maybe = new Result<>();

assertions.apply(ArithmeticException.class).accept(() ->
maybe.result = attempt.getAsDouble(() -> 1.0 / 0) // can't use 0.0 otherwise we end up with Infinity
// The exception must be thrown manually because apparently
// division by zero is perfectly legal in floating-point land...
maybe.result = attempt.getAsDouble(() -> { throw new ArithmeticException(); })
);

maybe.assertIfResultExists(optional -> assertTrue(optional.isEmpty()));
Expand Down

0 comments on commit 8fec4a8

Please sign in to comment.