Skip to content

Commit

Permalink
objectionary#3793 Add tests for Expect
Browse files Browse the repository at this point in the history
  • Loading branch information
asmirnov-backend committed Jan 8, 2025
1 parent c783fd2 commit e352c8a
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion eo-runtime/src/test/java/org/eolang/ExpectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,81 @@ void failsWithCorrectTrace() {
.it(),
"fails on check"
).getMessage(),
Matchers.containsString("negative")
Matchers.equalTo("a number (42) must be negative")
);
}

@Test
void failsWithCorrectTraceWithTwoErrors() {
MatcherAssert.assertThat(
"error message is correct",
Assertions.assertThrows(
ExFailure.class,
() -> new Expect<>("a number", () -> 42.2)
.must(i -> i < 0)
.otherwise("must be negative")
.must(i -> i % 1 == 0)
.otherwise("must be an integer")
.it(),
"fails for first 'must'"
).getMessage(),
Matchers.equalTo("a number (42.2) must be negative")
);
}

@Test
void failsWithCorrectTraceWithOneOkAndOneError() {
MatcherAssert.assertThat(
"error message is correct",
Assertions.assertThrows(
ExFailure.class,
() -> new Expect<>("a number", () -> 42.2)
.must(i -> i > 0)
.otherwise("must be positive")
.must(i -> i % 1 == 0)
.otherwise("must be an integer")
.it(),
"fails on checking integer"
).getMessage(),
Matchers.equalTo("a number (42.2) must be an integer")
);
}

@Test
void failsWithCorrectTraceWithOneErrorAndOneOk() {
MatcherAssert.assertThat(
"error message is correct",
Assertions.assertThrows(
ExFailure.class,
() -> new Expect<>("a number", () -> 42.2)
.must(i -> i % 1 == 0)
.otherwise("must be an integer")
.must(i -> i > 0)
.otherwise("must be positive")
.it(),
"fails on check integer"
).getMessage(),
Matchers.equalTo("a number (42.2) must be an integer")
);
}

@Test
void failsWithCorrectTraceWithExFailureInThat() {
MatcherAssert.assertThat(
"error message is correct",
Assertions.assertThrows(
ExFailure.class,
() -> new Expect<>("a number", () -> 42.2)
.must(i -> i > 0)
.otherwise("must be positive")
.that(i -> {
throw new ExFailure("some error");
})
.otherwise("something went wrong")
.it(),
"fails on check integer"
).getMessage(),
Matchers.equalTo("something went wrong")
);
}
}

0 comments on commit e352c8a

Please sign in to comment.