Skip to content

Commit

Permalink
Extend AssertJThrowingCallableRules Refaster rule collection
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed May 3, 2023
1 parent 3405962 commit 9f21c5a
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 0 deletions.
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);
}

@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

0 comments on commit 9f21c5a

Please sign in to comment.