|
65 | 65 |
|
66 | 66 | import static com.mongodb.ClusterFixture.TIMEOUT_SETTINGS; |
67 | 67 | import static com.mongodb.connection.ServerDescription.MIN_DRIVER_WIRE_VERSION; |
| 68 | +import static java.lang.String.format; |
68 | 69 | import static org.junit.Assert.assertTrue; |
69 | 70 | import static org.junit.Assert.fail; |
70 | 71 | import static org.junit.Assume.assumeFalse; |
@@ -111,21 +112,21 @@ public void shouldPassAllOutcomes() { |
111 | 112 | try (BaseCluster cluster = createTestCluster(clusterDescription, serversSnapshot)) { |
112 | 113 | serverTuple = cluster.selectServer(serverSelector, operationContext); |
113 | 114 | if (error) { |
114 | | - fail("Should have thrown exception"); |
| 115 | + fail(format("Should have thrown exception")); |
115 | 116 | } |
116 | 117 | } catch (MongoConfigurationException e) { |
117 | 118 | if (!error) { |
118 | | - fail("Should not have thrown exception: " + e); |
| 119 | + fail(format("Should not have thrown exception: %s", e)); |
119 | 120 | } |
120 | 121 | return; |
121 | 122 | } 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()); |
125 | 125 | return; |
126 | 126 | } |
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()))); |
129 | 130 | } |
130 | 131 |
|
131 | 132 | @Parameterized.Parameters(name = "{0}") |
@@ -354,4 +355,9 @@ public void onChange(final ServerDescriptionChangedEvent event) { |
354 | 355 | fail(); |
355 | 356 | } |
356 | 357 | } |
| 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 | + } |
357 | 363 | } |
0 commit comments