Skip to content

Commit 14d2eec

Browse files
cpovirksduskis
authored andcommitted
Migrate from assertThat(foo).named("foo") to assertWithMessage("foo").that(foo). (#5176)
named(...) is being removed. This CL may slightly modify the failure messages produced, but all the old information will still be present.
1 parent b36a621 commit 14d2eec

5 files changed

Lines changed: 16 additions & 11 deletions

File tree

google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractStructReaderTypesTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.cloud.spanner.Type.StructField;
2020
import static com.google.common.truth.Truth.assertThat;
21+
import static com.google.common.truth.Truth.assertWithMessage;
2122
import static org.junit.Assert.fail;
2223
import static org.junit.runners.Parameterized.Parameter;
2324

@@ -352,17 +353,17 @@ public void getterForIncorrectType() throws Exception {
352353
getterByIndex(method.getName(), columnIndex);
353354
fail("Expected ISE for " + method);
354355
} catch (IllegalStateException e) {
355-
assertThat(e.getMessage()).named("Exception for " + method).contains("was " + type);
356-
assertThat(e.getMessage())
357-
.named("Exception for " + method)
356+
assertWithMessage("Exception for " + method).that(e.getMessage()).contains("was " + type);
357+
assertWithMessage("Exception for " + method)
358+
.that(e.getMessage())
358359
.contains("Column " + columnIndex);
359360
}
360361
try {
361362
getterByName(method.getName(), "F1");
362363
fail("Expected ISE for " + method);
363364
} catch (IllegalStateException e) {
364-
assertThat(e.getMessage()).named("Exception for " + method).contains("was " + type);
365-
assertThat(e.getMessage()).named("Exception for " + method).contains("Column F1");
365+
assertWithMessage("Exception for " + method).that(e.getMessage()).contains("was " + type);
366+
assertWithMessage("Exception for " + method).that(e.getMessage()).contains("Column F1");
366367
}
367368
}
368369
}

google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TimestampBoundTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.testing.SerializableTester.reserializeAndAssert;
2020
import static com.google.common.truth.Truth.assertThat;
21+
import static com.google.common.truth.Truth.assertWithMessage;
2122

2223
import com.google.cloud.Timestamp;
2324
import com.google.cloud.spanner.TimestampBound.Mode;
@@ -110,8 +111,8 @@ public void stalenessSourceUnits() {
110111
long num = 7;
111112
for (TimeUnit units : TimeUnit.values()) {
112113
TimestampBound bound = TimestampBound.ofExactStaleness(num, units);
113-
assertThat(bound.getExactStaleness(TimeUnit.NANOSECONDS))
114-
.named(units.toString())
114+
assertWithMessage(units.toString())
115+
.that(bound.getExactStaleness(TimeUnit.NANOSECONDS))
115116
.isEqualTo(units.toNanos(num));
116117
}
117118
}

google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueBinderTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.spanner;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20+
import static com.google.common.truth.Truth.assertWithMessage;
2021

2122
import com.google.cloud.ByteArray;
2223
import com.google.cloud.Date;
@@ -54,7 +55,7 @@ public void reflection() throws InvocationTargetException, IllegalAccessExceptio
5455
continue;
5556
}
5657
Method binderMethod = findBinderMethod(method);
57-
assertThat(binderMethod).named("Binder for " + method.toString()).isNotNull();
58+
assertWithMessage("Binder for " + method.toString()).that(binderMethod).isNotNull();
5859

5960
if (method.getName().toLowerCase().contains("struct")) {
6061
// Struct / Array-of-struct binding methods.

google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.testing.SerializableTester.reserializeAndAssert;
2020
import static com.google.common.truth.Truth.assertThat;
21+
import static com.google.common.truth.Truth.assertWithMessage;
2122

2223
import com.google.cloud.ByteArray;
2324
import com.google.cloud.Date;
@@ -359,8 +360,8 @@ public void boolArrayFromPlainIterable() {
359360
}
360361
String name = "boolArray() of length " + i;
361362
Value v = Value.boolArray(plainIterable(data));
362-
assertThat(v.isNull()).named(name).isFalse();
363-
assertThat(v.getBoolArray()).named(name).containsExactly((Object[]) data).inOrder();
363+
assertWithMessage(name).that(v.isNull()).isFalse();
364+
assertWithMessage(name).that(v.getBoolArray()).containsExactly((Object[]) data).inOrder();
364365
}
365366
}
366367

google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITReadTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.cloud.spanner.SpannerMatchers.isSpannerException;
2020
import static com.google.cloud.spanner.Type.StructField;
2121
import static com.google.common.truth.Truth.assertThat;
22+
import static com.google.common.truth.Truth.assertWithMessage;
2223

2324
import com.google.cloud.spanner.Database;
2425
import com.google.cloud.spanner.DatabaseClient;
@@ -426,7 +427,7 @@ private void checkReadRange(Source source, KeySet keySet, long limit, int[] expe
426427
rows.put(resultSet.getString(0), resultSet.getString(1));
427428
}
428429

429-
assertThat(rows).named("read of " + keySet).isEqualTo(expected);
430+
assertWithMessage("read of " + keySet).that(rows).isEqualTo(expected);
430431
}
431432

432433
private void checkRange(Source source, KeyRange range, int... expectedRows) {

0 commit comments

Comments
 (0)