Skip to content

Commit

Permalink
Rewrite more `ThrowableAssertAlternative#withMessage(String, Object..…
Browse files Browse the repository at this point in the history
….)` expressions (#185)
  • Loading branch information
rickie authored Aug 10, 2022
1 parent efbde93 commit ef562c1
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ static final class AssertThatThrownByIllegalArgumentExceptionHasMessage {
}
}

static final class AssertThatThrownByIllegalArgumentExceptionHasMessageParameters {
@BeforeTemplate
@SuppressWarnings(
"AssertThatThrownByIllegalArgumentException" /* Matches strictly more specific expressions. */)
AbstractObjectAssert<?, ?> before(
ThrowingCallable throwingCallable, String message, @Repeated Object parameters) {
return assertThatIllegalArgumentException()
.isThrownBy(throwingCallable)
.withMessage(message, parameters);
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
AbstractObjectAssert<?, ?> after(
ThrowingCallable throwingCallable, String message, @Repeated Object parameters) {
return assertThatThrownBy(throwingCallable)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(message, parameters);
}
}

static final class AssertThatThrownByIllegalArgumentExceptionHasMessageStartingWith {
@BeforeTemplate
@SuppressWarnings(
Expand Down Expand Up @@ -148,6 +169,27 @@ static final class AssertThatThrownByIllegalStateExceptionHasMessage {
}
}

static final class AssertThatThrownByIllegalStateExceptionHasMessageParameters {
@BeforeTemplate
@SuppressWarnings(
"AssertThatThrownByIllegalStateException" /* Matches strictly more specific expressions. */)
AbstractObjectAssert<?, ?> before(
ThrowingCallable throwingCallable, String message, @Repeated Object parameters) {
return assertThatIllegalStateException()
.isThrownBy(throwingCallable)
.withMessage(message, parameters);
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
AbstractObjectAssert<?, ?> after(
ThrowingCallable throwingCallable, String message, @Repeated Object parameters) {
return assertThatThrownBy(throwingCallable)
.isInstanceOf(IllegalStateException.class)
.hasMessage(message, parameters);
}
}

static final class AssertThatThrownByIllegalStateExceptionHasMessageStartingWith {
@BeforeTemplate
@SuppressWarnings(
Expand Down Expand Up @@ -235,6 +277,27 @@ static final class AssertThatThrownByNullPointerExceptionHasMessage {
}
}

static final class AssertThatThrownByNullPointerExceptionHasMessageParameters {
@BeforeTemplate
@SuppressWarnings(
"AssertThatThrownByNullPointerException" /* Matches strictly more specific expressions. */)
AbstractObjectAssert<?, ?> before(
ThrowingCallable throwingCallable, String message, @Repeated Object parameters) {
return assertThatNullPointerException()
.isThrownBy(throwingCallable)
.withMessage(message, parameters);
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
AbstractObjectAssert<?, ?> after(
ThrowingCallable throwingCallable, String message, @Repeated Object parameters) {
return assertThatThrownBy(throwingCallable)
.isInstanceOf(NullPointerException.class)
.hasMessage(message, parameters);
}
}

static final class AssertThatThrownByNullPointerExceptionHasMessageStartingWith {
@BeforeTemplate
@SuppressWarnings(
Expand Down Expand Up @@ -284,6 +347,25 @@ static final class AssertThatThrownByIOExceptionHasMessage {
}
}

static final class AssertThatThrownByIOExceptionHasMessageParameters {
@BeforeTemplate
@SuppressWarnings(
"AssertThatThrownByIOException" /* Matches strictly more specific expressions. */)
AbstractObjectAssert<?, ?> before(
ThrowingCallable throwingCallable, String message, @Repeated Object parameters) {
return assertThatIOException().isThrownBy(throwingCallable).withMessage(message, parameters);
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
AbstractObjectAssert<?, ?> after(
ThrowingCallable throwingCallable, String message, @Repeated Object parameters) {
return assertThatThrownBy(throwingCallable)
.isInstanceOf(IOException.class)
.hasMessage(message, parameters);
}
}

static final class AssertThatThrownBy {
@BeforeTemplate
AbstractObjectAssert<?, ?> before(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public ImmutableSet<?> elidedTypesAndStaticImports() {
return assertThatIllegalArgumentException().isThrownBy(() -> {}).withMessage("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalArgumentExceptionHasMessageParameters() {
return assertThatIllegalArgumentException().isThrownBy(() -> {}).withMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?>
testAssertThatThrownByIllegalArgumentExceptionHasMessageStartingWith() {
return assertThatIllegalArgumentException().isThrownBy(() -> {}).withMessageStartingWith("foo");
Expand All @@ -54,6 +58,10 @@ public ImmutableSet<?> elidedTypesAndStaticImports() {
return assertThatIllegalStateException().isThrownBy(() -> {}).withMessage("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalStateExceptionHasMessageParameters() {
return assertThatIllegalStateException().isThrownBy(() -> {}).withMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalStateExceptionHasMessageStartingWith() {
return assertThatIllegalStateException().isThrownBy(() -> {}).withMessageStartingWith("foo");
}
Expand All @@ -74,6 +82,10 @@ public ImmutableSet<?> elidedTypesAndStaticImports() {
return assertThatNullPointerException().isThrownBy(() -> {}).withMessage("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionHasMessageParameters() {
return assertThatNullPointerException().isThrownBy(() -> {}).withMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionHasMessageStartingWith() {
return assertThatNullPointerException().isThrownBy(() -> {}).withMessageStartingWith("foo");
}
Expand All @@ -86,6 +98,11 @@ public ImmutableSet<?> elidedTypesAndStaticImports() {
return assertThatIOException().isThrownBy(() -> {}).withMessage("foo");
}

@SuppressWarnings("AssertThatThrownByIOException")
AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionHasMessageParameters() {
return assertThatIOException().isThrownBy(() -> {}).withMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?> testAssertThatThrownBy() {
return assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public ImmutableSet<?> elidedTypesAndStaticImports() {
.hasMessage("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalArgumentExceptionHasMessageParameters() {
return assertThatThrownBy(() -> {})
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?>
testAssertThatThrownByIllegalArgumentExceptionHasMessageStartingWith() {
return assertThatThrownBy(() -> {})
Expand Down Expand Up @@ -61,6 +67,12 @@ public ImmutableSet<?> elidedTypesAndStaticImports() {
return assertThatThrownBy(() -> {}).isInstanceOf(IllegalStateException.class).hasMessage("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalStateExceptionHasMessageParameters() {
return assertThatThrownBy(() -> {})
.isInstanceOf(IllegalStateException.class)
.hasMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIllegalStateExceptionHasMessageStartingWith() {
return assertThatThrownBy(() -> {})
.isInstanceOf(IllegalStateException.class)
Expand All @@ -87,6 +99,12 @@ public ImmutableSet<?> elidedTypesAndStaticImports() {
return assertThatThrownBy(() -> {}).isInstanceOf(NullPointerException.class).hasMessage("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionHasMessageParameters() {
return assertThatThrownBy(() -> {})
.isInstanceOf(NullPointerException.class)
.hasMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionHasMessageStartingWith() {
return assertThatThrownBy(() -> {})
.isInstanceOf(NullPointerException.class)
Expand All @@ -101,6 +119,11 @@ public ImmutableSet<?> elidedTypesAndStaticImports() {
return assertThatThrownBy(() -> {}).isInstanceOf(IOException.class).hasMessage("foo");
}

@SuppressWarnings("AssertThatThrownByIOException")
AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionHasMessageParameters() {
return assertThatThrownBy(() -> {}).isInstanceOf(IOException.class).hasMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?> testAssertThatThrownBy() {
return assertThatThrownBy(() -> {}).isInstanceOf(IllegalArgumentException.class);
}
Expand Down

0 comments on commit ef562c1

Please sign in to comment.