Skip to content

Commit 793507a

Browse files
committed
Add assertion context.
1 parent cb3e7d6 commit 793507a

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

driver-core/src/test/unit/com/mongodb/connection/ServerSelectionSelectionTest.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565

6666
import static com.mongodb.ClusterFixture.TIMEOUT_SETTINGS;
6767
import static com.mongodb.connection.ServerDescription.MIN_DRIVER_WIRE_VERSION;
68+
import static java.lang.String.format;
6869
import static org.junit.Assert.assertTrue;
6970
import static org.junit.Assert.fail;
7071
import static org.junit.Assume.assumeFalse;
@@ -111,21 +112,21 @@ public void shouldPassAllOutcomes() {
111112
try (BaseCluster cluster = createTestCluster(clusterDescription, serversSnapshot)) {
112113
serverTuple = cluster.selectServer(serverSelector, operationContext);
113114
if (error) {
114-
fail("Should have thrown exception");
115+
fail(format("Should have thrown exception"));
115116
}
116117
} catch (MongoConfigurationException e) {
117118
if (!error) {
118-
fail("Should not have thrown exception: " + e);
119+
fail(format("Should not have thrown exception: %s", e));
119120
}
120121
return;
121122
} catch (MongoTimeoutException mongoTimeoutException) {
122-
assertTrue("Expected emtpy but was " + inLatencyWindowServers.size() + " " + definition.toJson(
123-
JsonWriterSettings.builder()
124-
.indent(true).build()), inLatencyWindowServers.isEmpty());
123+
assertTrue(format("Expected empty but was %s", inLatencyWindowServers.size()),
124+
inLatencyWindowServers.isEmpty());
125125
return;
126126
}
127-
assertNotNull(serverTuple);
128-
assertTrue(inLatencyWindowServers.stream().anyMatch(s -> s.equals(serverTuple.getServerDescription())));
127+
assertNotNull(format("Server tuple should not be null"), serverTuple);
128+
assertTrue(format("Selected server should be in latency window"),
129+
inLatencyWindowServers.stream().anyMatch(s -> s.equals(serverTuple.getServerDescription())));
129130
}
130131

131132
@Parameterized.Parameters(name = "{0}")
@@ -354,4 +355,9 @@ public void onChange(final ServerDescriptionChangedEvent event) {
354355
fail();
355356
}
356357
}
358+
359+
private String format(final String messageFormat, final Object... args) {
360+
String message = String.format(messageFormat, args);
361+
return message + "\nTest Definition:\n" + definition.toJson(JsonWriterSettings.builder().indent(true).build());
362+
}
357363
}

0 commit comments

Comments
 (0)