|
25 | 25 | import static org.junit.Assert.assertArrayEquals; |
26 | 26 | import static org.junit.Assert.assertEquals; |
27 | 27 | import static org.junit.Assert.assertFalse; |
| 28 | +import static org.junit.Assert.assertNotEquals; |
28 | 29 | import static org.junit.Assert.assertNull; |
29 | 30 | import static org.junit.Assert.assertTrue; |
30 | 31 | import static org.junit.Assert.fail; |
@@ -327,6 +328,31 @@ public void testMultipleIPV6ServersWithPorts() { |
327 | 328 | assertEquals("[2010:836B:4179::836B:4179]:2000", u.getHosts().get(1)); |
328 | 329 | } |
329 | 330 |
|
| 331 | + @Test |
| 332 | + public void testEqualsAndHashCode() { |
| 333 | + MongoClientURI uris[] = new MongoClientURI[] { |
| 334 | + new MongoClientURI("mongodb://user:pass@[2010:836B:4179::836B:4179]"), |
| 335 | + new MongoClientURI("mongodb://localhost/?readPreference=secondaryPreferred"), |
| 336 | + new MongoClientURI("mongodb://[::1]:1000,[2010:836B:4179::836B:4179]:2000"), |
| 337 | + new MongoClientURI("mongodb://localhost/?" + |
| 338 | + "maxPoolSize=10;waitQueueMultiple=5;waitQueueTimeoutMS=150;" + |
| 339 | + "minPoolSize=7;maxIdleTimeMS=1000;maxLifeTimeMS=2000;" + |
| 340 | + "replicaSet=test;" + |
| 341 | + "connectTimeoutMS=2500;socketTimeoutMS=5500;autoConnectRetry=true;" + |
| 342 | + "slaveOk=true;safe=false;w=1;wtimeout=2500;fsync=true") |
| 343 | + }; |
| 344 | + for (MongoClientURI uri : uris) { |
| 345 | + assertEquals(uri, uri); |
| 346 | + MongoClientURI reinstantiatedUri = new MongoClientURI(uri.getURI()); |
| 347 | + assertEquals(uri, reinstantiatedUri); |
| 348 | + assertEquals(uri.hashCode(), reinstantiatedUri.hashCode()); |
| 349 | + for (MongoClientURI anotherURI : uris) { |
| 350 | + if (uri == anotherURI) continue; |
| 351 | + assertNotEquals(uri, anotherURI); |
| 352 | + } |
| 353 | + } |
| 354 | + } |
| 355 | + |
330 | 356 | @SuppressWarnings("deprecation") |
331 | 357 | private void assertOnOptions(MongoClientOptions options) { |
332 | 358 | assertEquals(10, options.getConnectionsPerHost(), 10); |
|
0 commit comments