Skip to content

Commit

Permalink
test UserIndicatedErrors matching with "cause" being the matching class
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Sep 6, 2021
1 parent 1a9073b commit d2a06ac
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
*/
public final class UserIndicatedErrorsTest {

private static final IllegalArgumentException MATCHING_EXCEPTION =
new IllegalArgumentException("This exception should match.");
private static final IllegalArgumentException NON_MATCHING_EXCEPTION =
new IllegalArgumentException("This exception should not match.");
private static final IllegalArgumentException NON_MATCHING_EXCEPTION_WITH_MATCHING_CAUSE =
new IllegalArgumentException("This exception should not match.", MATCHING_EXCEPTION);
private static final IllegalArgumentException NON_MATCHING_EXCEPTION_WITH_NESTED_MATCHING_CAUSE =
new IllegalArgumentException("This is not a problem at all.", NON_MATCHING_EXCEPTION_WITH_MATCHING_CAUSE);

private UserIndicatedErrors underTest;

@Before
Expand All @@ -40,12 +49,22 @@ public void illegalStateExceptionMatches() {

@Test
public void illegalArgumentExceptionWithCorrectMessageMatches() {
assertThat(underTest.matches(new IllegalArgumentException("This exception should match."))).isTrue();
assertThat(underTest.matches(MATCHING_EXCEPTION)).isTrue();
}

@Test
public void illegalArgumentExceptionWithWrongMessageDoesNotMatch() {
assertThat(underTest.matches(new IllegalArgumentException("This exception should not match."))).isFalse();
assertThat(underTest.matches(NON_MATCHING_EXCEPTION)).isFalse();
}

@Test
public void illegalArgumentExceptionWithCauseCorrectMessageMatches() {
assertThat(underTest.matches(NON_MATCHING_EXCEPTION_WITH_MATCHING_CAUSE)).isTrue();
}

@Test
public void illegalArgumentExceptionWithNestedCauseCorrectMessageMatches() {
assertThat(underTest.matches(NON_MATCHING_EXCEPTION_WITH_NESTED_MATCHING_CAUSE)).isTrue();
}

/**
Expand All @@ -63,9 +82,9 @@ public void configurationEnvironmentVariableParsesStringObjects() {

final Config config = ConfigFactory.load("user-indicated-errors-via-env");
final UserIndicatedErrors withEnvInjectedConfig = UserIndicatedErrors.of(config);
assertThat(withEnvInjectedConfig.matches(new IllegalArgumentException("This exception should match.")))
assertThat(withEnvInjectedConfig.matches(MATCHING_EXCEPTION))
.isTrue();
assertThat(withEnvInjectedConfig.matches(new IllegalArgumentException("This exception should not match.")))
assertThat(withEnvInjectedConfig.matches(NON_MATCHING_EXCEPTION))
.isFalse();
assertThat(withEnvInjectedConfig.matches(new ArithmeticException("Some hickup here, nevermind")))
.isTrue();
Expand Down

0 comments on commit d2a06ac

Please sign in to comment.