Skip to content

Commit

Permalink
Refactor exception-message assertions to use ThrowableSubject.hasMess…
Browse files Browse the repository at this point in the history
…ageThat(). This replaces assertions of the form assertThat(e).hasMessage(...) and assertThat(e.getMessage()) with assertThat(e).hasMessageThat().

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=239181584
  • Loading branch information
dimo414 authored and ronshapiro committed Mar 22, 2019
1 parent 643eda4 commit 282a3a7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ class TestValueArrayWithBlahFoo {}
try {
AnnotationMirrors.getAnnotationValue(annotationOn(TestClassBlah.class), "a");
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"@com.google.auto.common.AnnotationMirrorsTest.Outer does not define an element a()");
assertThat(e)
.hasMessageThat()
.isEqualTo(
"@com.google.auto.common.AnnotationMirrorsTest.Outer does not define an element a()");
return;
}
fail("Should have thrown.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,13 @@ public void testBuilderWithUnprefixedGetter() {
builder.list();
fail("Attempt to retrieve unset list property should have failed");
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Property \"list\" has not been set");
assertThat(e).hasMessageThat().isEqualTo("Property \"list\" has not been set");
}
try {
builder.ints();
fail("Attempt to retrieve unset ints property should have failed");
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Property \"ints\" has not been set");
assertThat(e).hasMessageThat().isEqualTo("Property \"ints\" has not been set");
}

builder.setList(names);
Expand Down Expand Up @@ -599,7 +599,7 @@ public void testBuilderWithPrefixedGetter() {
builder.getList();
fail("Attempt to retrieve unset list property should have failed");
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Property \"list\" has not been set");
assertThat(e).hasMessageThat().isEqualTo("Property \"list\" has not been set");
}

builder.setList(names);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ public void testBuilderWithUnprefixedGetter() {
if (omitIdentifiers) {
assertThat(e).hasMessageThat().isNull();
} else {
assertThat(e).hasMessage("Property \"list\" has not been set");
assertThat(e).hasMessageThat().isEqualTo("Property \"list\" has not been set");
}
}
try {
Expand All @@ -1933,7 +1933,7 @@ public void testBuilderWithUnprefixedGetter() {
if (omitIdentifiers) {
assertThat(e).hasMessageThat().isNull();
} else {
assertThat(e).hasMessage("Property \"ints\" has not been set");
assertThat(e).hasMessageThat().isEqualTo("Property \"ints\" has not been set");
}
}

Expand Down Expand Up @@ -2014,7 +2014,7 @@ public void testBuilderWithPrefixedGetter() {
if (omitIdentifiers) {
assertThat(e).hasMessageThat().isNull();
} else {
assertThat(e).hasMessage("Property \"list\" has not been set");
assertThat(e).hasMessageThat().isEqualTo("Property \"list\" has not been set");
}
}

Expand Down Expand Up @@ -2307,7 +2307,7 @@ public void testBuilderAndSetterCannotSetAfterBuilder() {
if (omitIdentifiers) {
assertThat(e).hasMessageThat().isNull();
} else {
assertThat(e).hasMessage("Cannot set things after calling thingsBuilder()");
assertThat(e).hasMessageThat().isEqualTo("Cannot set things after calling thingsBuilder()");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ public void notNullableButReturnsNull() {
value.notNullableButReturnsNull();
fail();
} catch (NullPointerException expected) {
assertThat(expected).hasMessage("notNullableButReturnsNull() cannot return null");
assertThat(expected)
.hasMessageThat()
.isEqualTo("notNullableButReturnsNull() cannot return null");
}
assertThat(value.notNullableButReturnsNullCount).isEqualTo(1);
}
Expand Down

0 comments on commit 282a3a7

Please sign in to comment.