Skip to content

Commit ebf544f

Browse files
committed
Replace assertEquals with assertSame when comparing exceptions in RetryStateTest
1 parent f6db95e commit ebf544f

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

driver-core/src/test/unit/com/mongodb/internal/async/function/RetryStateTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.junit.jupiter.api.Assertions.assertFalse;
3939
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4040
import static org.junit.jupiter.api.Assertions.assertNull;
41+
import static org.junit.jupiter.api.Assertions.assertSame;
4142
import static org.junit.jupiter.api.Assertions.assertThrows;
4243
import static org.junit.jupiter.api.Assertions.assertTrue;
4344
import static org.junit.jupiter.api.Assertions.fail;
@@ -171,7 +172,7 @@ void breakAndThrowIfRetryIfPredicateThrows(final TimeoutContext timeoutContext)
171172
RetryState retryState = new RetryState(timeoutContext);
172173
advance(retryState);
173174
RuntimeException exception = new RuntimeException();
174-
assertEquals(
175+
assertSame(
175176
exception,
176177
assertThrows(exception.getClass(), () -> retryState.breakAndThrowIfRetryAnd(() -> {
177178
throw exception;
@@ -222,7 +223,7 @@ void breakAndCompleteIfRetryAndPredicateThrows(final TimeoutContext timeoutConte
222223
assertTrue(retryState.breakAndCompleteIfRetryAnd(() -> {
223224
throw exception;
224225
}, callback));
225-
assertEquals(
226+
assertSame(
226227
exception,
227228
assertThrows(exception.getClass(), callback::get));
228229
assertAdvanceOrThrowDoesNotThrow(retryState, exception);
@@ -266,7 +267,7 @@ void advanceThrowTimeoutExceptionWhenTransformerSwallowOriginalTimeoutException(
266267

267268
assertNotEquals(latestAttemptException, actualTimeoutException);
268269
assertEquals(EXPECTED_TIMEOUT_MESSAGE, actualTimeoutException.getMessage());
269-
assertEquals(previousAttemptException, actualTimeoutException.getCause(),
270+
assertSame(previousAttemptException, actualTimeoutException.getCause(),
270271
"Retry timeout exception should have a cause if transformer returned non-timeout exception.");
271272
}
272273

@@ -305,7 +306,7 @@ void advanceOrThrowPredicateThrowsAfterFirstAttempt(final TimeoutContext timeout
305306
(e1, e2) -> e2,
306307
(rs, e) -> {
307308
assertTrue(rs.isFirstAttempt());
308-
assertEquals(attemptException, e);
309+
assertSame(attemptException, e);
309310
throw predicateException;
310311
});
311312
}
@@ -318,7 +319,7 @@ void advanceOrThrowPredicateThrowsTimeoutAfterFirstAttempt() {
318319
MongoOperationTimeoutException mongoOperationTimeoutException = assertThrows(MongoOperationTimeoutException.class,
319320
() -> retryState.advanceOrThrow(attemptException, (e1, e2) -> e2, (rs, e) -> {
320321
assertTrue(rs.isFirstAttempt());
321-
assertEquals(attemptException, e);
322+
assertSame(attemptException, e);
322323
throw predicateException;
323324
}));
324325

@@ -338,7 +339,7 @@ void advanceOrThrowPredicateThrows(final TimeoutContext timeoutContext) {
338339
(e1, e2) -> e2,
339340
(rs, e) -> {
340341
assertEquals(1, rs.attempt());
341-
assertEquals(secondAttemptException, e);
342+
assertSame(secondAttemptException, e);
342343
throw predicateException;
343344
});
344345
}
@@ -378,11 +379,11 @@ void advanceOrThrowTransformAfterFirstAttempt(final TimeoutContext timeoutContex
378379
assertAdvanceOrThrowThrows(transformerResult, retryState, attemptException,
379380
(e1, e2) -> {
380381
assertNull(e1);
381-
assertEquals(attemptException, e2);
382+
assertSame(attemptException, e2);
382383
return transformerResult;
383384
},
384385
(rs, e) -> {
385-
assertEquals(attemptException, e);
386+
assertSame(attemptException, e);
386387
return false;
387388
});
388389
}
@@ -398,16 +399,16 @@ void advanceOrThrowTransformThrowsTimeoutExceptionAfterFirstAttempt() {
398399
assertThrows(MongoOperationTimeoutException.class, () -> retryState.advanceOrThrow(attemptException,
399400
(e1, e2) -> {
400401
assertNull(e1);
401-
assertEquals(attemptException, e2);
402+
assertSame(attemptException, e2);
402403
return transformerResult;
403404
},
404405
(rs, e) -> {
405-
assertEquals(attemptException, e);
406+
assertSame(attemptException, e);
406407
return false;
407408
}));
408409

409410
assertEquals(EXPECTED_TIMEOUT_MESSAGE, mongoOperationTimeoutException.getMessage());
410-
assertEquals(transformerResult, mongoOperationTimeoutException.getCause());
411+
assertSame(transformerResult, mongoOperationTimeoutException.getCause());
411412
}
412413

413414
@ParameterizedTest
@@ -420,12 +421,12 @@ void advanceOrThrowTransform(final TimeoutContext timeoutContext) {
420421
RuntimeException transformerResult = new RuntimeException();
421422
assertAdvanceOrThrowThrows(transformerResult, retryState, secondAttemptException,
422423
(e1, e2) -> {
423-
assertEquals(firstAttemptException, e1);
424-
assertEquals(secondAttemptException, e2);
424+
assertSame(firstAttemptException, e1);
425+
assertSame(secondAttemptException, e2);
425426
return transformerResult;
426427
},
427428
(rs, e) -> {
428-
assertEquals(secondAttemptException, e);
429+
assertSame(secondAttemptException, e);
429430
return false;
430431
});
431432
}
@@ -483,7 +484,7 @@ private static void assertAdvanceOrThrowThrows(
483484
final BinaryOperator<Throwable> onAttemptFailureOperator,
484485
final BiPredicate<RetryState, Throwable> retryPredicate) {
485486
com.mongodb.assertions.Assertions.assertNotNull(expectedException);
486-
assertEquals(
487+
assertSame(
487488
expectedException,
488489
assertThrows(expectedException.getClass(), () ->
489490
retryState.advanceOrThrow(attemptException, onAttemptFailureOperator, retryPredicate)));

0 commit comments

Comments
 (0)