Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend AssertJThrowingCallableRules Refaster rule collection #609

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,44 @@ static final class AssertThatThrownByNullPointerExceptionHasMessageStartingWith
}
}

static final class AssertThatThrownByNullPointerExceptionHasMessageContaining {
@BeforeTemplate
@SuppressWarnings(
"AssertThatThrownByNullPointerException" /* This is a more specific template. */)
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable, String message) {
return assertThatNullPointerException()
.isThrownBy(throwingCallable)
.withMessageContaining(message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also format string overloads 😬. (But at we're fast reaching the point where a bug checker becomes lighter.)

}

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

static final class AssertThatThrownByNullPointerExceptionHasMessageNotContaining {
@BeforeTemplate
@SuppressWarnings(
"AssertThatThrownByNullPointerException" /* This is a more specific template. */)
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable, String message) {
return assertThatNullPointerException()
.isThrownBy(throwingCallable)
.withMessageNotContaining(message);
}

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

static final class AssertThatThrownByIOException {
@BeforeTemplate
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable) {
Expand Down Expand Up @@ -366,6 +404,54 @@ static final class AssertThatThrownByIOExceptionHasMessageParameters {
}
}

static final class AssertThatThrownByIOExceptionHasMessageStartingWith {
@BeforeTemplate
@SuppressWarnings("AssertThatThrownByIOException" /* This is a more specific template. */)
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable, String message) {
return assertThatIOException().isThrownBy(throwingCallable).withMessageStartingWith(message);
}

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

static final class AssertThatThrownByIOExceptionHasMessageContaining {
@BeforeTemplate
@SuppressWarnings("AssertThatThrownByIOException" /* This is a more specific template. */)
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable, String message) {
return assertThatIOException().isThrownBy(throwingCallable).withMessageContaining(message);
}

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

static final class AssertThatThrownByIOExceptionHasMessageNotContaining {
@BeforeTemplate
@SuppressWarnings("AssertThatThrownByIOException" /* This is a more specific template. */)
AbstractObjectAssert<?, ?> before(ThrowingCallable throwingCallable, String message) {
return assertThatIOException().isThrownBy(throwingCallable).withMessageNotContaining(message);
}

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

static final class AssertThatThrownBy {
@BeforeTemplate
AbstractObjectAssert<?, ?> before(
Expand Down Expand Up @@ -429,6 +515,78 @@ static final class AssertThatThrownByHasMessageParameters {
}
}

static final class AssertThatThrownByHasMessageStartingWith {
@BeforeTemplate
@SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */)
AbstractObjectAssert<?, ?> before(
Class<? extends Throwable> exceptionType,
ThrowingCallable throwingCallable,
String message) {
return assertThatExceptionOfType(exceptionType)
.isThrownBy(throwingCallable)
.withMessageStartingWith(message);
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
AbstractObjectAssert<?, ?> after(
Class<? extends Throwable> exceptionType,
ThrowingCallable throwingCallable,
String message) {
return assertThatThrownBy(throwingCallable)
.isInstanceOf(exceptionType)
.hasMessageStartingWith(message);
}
}

static final class AssertThatThrownByHasMessageContaining {
@BeforeTemplate
@SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */)
AbstractObjectAssert<?, ?> before(
Class<? extends Throwable> exceptionType,
ThrowingCallable throwingCallable,
String message) {
return assertThatExceptionOfType(exceptionType)
.isThrownBy(throwingCallable)
.withMessageContaining(message);
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
AbstractObjectAssert<?, ?> after(
Class<? extends Throwable> exceptionType,
ThrowingCallable throwingCallable,
String message) {
return assertThatThrownBy(throwingCallable)
.isInstanceOf(exceptionType)
.hasMessageContaining(message);
}
}

static final class AssertThatThrownByHasMessageNotContaining {
@BeforeTemplate
@SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */)
AbstractObjectAssert<?, ?> before(
Class<? extends Throwable> exceptionType,
ThrowingCallable throwingCallable,
String message) {
return assertThatExceptionOfType(exceptionType)
.isThrownBy(throwingCallable)
.withMessageNotContaining(message);
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
AbstractObjectAssert<?, ?> after(
Class<? extends Throwable> exceptionType,
ThrowingCallable throwingCallable,
String message) {
return assertThatThrownBy(throwingCallable)
.isInstanceOf(exceptionType)
.hasMessageNotContaining(message);
}
}

// XXX: Drop this rule in favour of a generic Error Prone check that flags `String.format(...)`
// arguments to a wide range of format methods.
static final class AbstractThrowableAssertHasMessage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ public ImmutableSet<Object> elidedTypesAndStaticImports() {
return assertThatNullPointerException().isThrownBy(() -> {}).withMessageStartingWith("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionHasMessageContaining() {
return assertThatNullPointerException().isThrownBy(() -> {}).withMessageContaining("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionHasMessageNotContaining() {
return assertThatNullPointerException().isThrownBy(() -> {}).withMessageNotContaining("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIOException() {
return assertThatIOException().isThrownBy(() -> {});
}
Expand All @@ -103,6 +111,18 @@ public ImmutableSet<Object> elidedTypesAndStaticImports() {
return assertThatIOException().isThrownBy(() -> {}).withMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionHasMessageStartingWith() {
return assertThatIOException().isThrownBy(() -> {}).withMessageStartingWith("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionHasMessageContaining() {
return assertThatIOException().isThrownBy(() -> {}).withMessageContaining("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionHasMessageNotContaining() {
return assertThatIOException().isThrownBy(() -> {}).withMessageNotContaining("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownBy() {
return assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {});
}
Expand All @@ -119,6 +139,24 @@ public ImmutableSet<Object> elidedTypesAndStaticImports() {
.withMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByHasMessageStartingWith() {
return assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> {})
.withMessageStartingWith("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByHasMessageContaining() {
return assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> {})
.withMessageContaining("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByHasMessageNotContaining() {
return assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> {})
.withMessageNotContaining("foo");
}

ImmutableSet<AbstractThrowableAssert<?, ? extends Throwable>>
testAbstractThrowableAssertHasMessage() {
return ImmutableSet.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public ImmutableSet<Object> elidedTypesAndStaticImports() {
.hasMessageStartingWith("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionHasMessageContaining() {
return assertThatThrownBy(() -> {})
.isInstanceOf(NullPointerException.class)
.hasMessageContaining("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByNullPointerExceptionHasMessageNotContaining() {
return assertThatThrownBy(() -> {})
.isInstanceOf(NullPointerException.class)
.hasMessageNotContaining("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIOException() {
return assertThatThrownBy(() -> {}).isInstanceOf(IOException.class);
}
Expand All @@ -124,6 +136,22 @@ public ImmutableSet<Object> elidedTypesAndStaticImports() {
return assertThatThrownBy(() -> {}).isInstanceOf(IOException.class).hasMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionHasMessageStartingWith() {
return assertThatThrownBy(() -> {})
.isInstanceOf(IOException.class)
.hasMessageStartingWith("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionHasMessageContaining() {
return assertThatThrownBy(() -> {}).isInstanceOf(IOException.class).hasMessageContaining("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByIOExceptionHasMessageNotContaining() {
return assertThatThrownBy(() -> {})
.isInstanceOf(IOException.class)
.hasMessageNotContaining("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownBy() {
return assertThatThrownBy(() -> {}).isInstanceOf(IllegalArgumentException.class);
}
Expand All @@ -140,6 +168,24 @@ public ImmutableSet<Object> elidedTypesAndStaticImports() {
.hasMessage("foo %s", "bar");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByHasMessageStartingWith() {
return assertThatThrownBy(() -> {})
.isInstanceOf(IllegalArgumentException.class)
.hasMessageStartingWith("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByHasMessageContaining() {
return assertThatThrownBy(() -> {})
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("foo");
}

AbstractObjectAssert<?, ?> testAssertThatThrownByHasMessageNotContaining() {
return assertThatThrownBy(() -> {})
.isInstanceOf(IllegalArgumentException.class)
.hasMessageNotContaining("foo");
}

ImmutableSet<AbstractThrowableAssert<?, ? extends Throwable>>
testAbstractThrowableAssertHasMessage() {
return ImmutableSet.of(
Expand Down