|
19 | 19 | package org.apache.pulsar.broker.service;
|
20 | 20 |
|
21 | 21 | import static org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo;
|
22 |
| -import static org.testng.AssertJUnit.fail; |
| 22 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; |
23 | 23 |
|
24 | 24 | import java.time.Duration;
|
25 | 25 | import java.util.ArrayList;
|
|
46 | 46 | import org.apache.pulsar.common.util.FutureUtil;
|
47 | 47 | import org.assertj.core.util.Sets;
|
48 | 48 | import org.awaitility.Awaitility;
|
49 |
| -import org.junit.jupiter.api.Assertions; |
50 | 49 | import org.junit.jupiter.api.function.Executable;
|
51 | 50 | import org.testng.Assert;
|
52 | 51 | import org.testng.annotations.AfterClass;
|
@@ -472,10 +471,8 @@ public void testGetMessageIdByIndex() throws Exception {
|
472 | 471 | (MessageIdImpl) admin.topics().getMessageIdByIndex(partitionedTopicName, index2);
|
473 | 472 | Assert.assertEquals(messageIdByIndex2, messageId2);
|
474 | 473 | // 2.2 test partitioned topic name without partition index
|
475 |
| - PulsarAdminException e = Assertions.assertThrows(PulsarAdminException.class, () -> |
476 |
| - admin.topics().getMessageIdByIndex(topicName2, index2) |
477 |
| - ); |
478 |
| - assertExceptionChainContains(e, NotAllowedException.class); |
| 474 | + assertThrowsWithCause(() -> admin.topics().getMessageIdByIndex(topicName2, index2), |
| 475 | + PulsarAdminException.class, NotAllowedException.class); |
479 | 476 |
|
480 | 477 | // 3. test invalid index
|
481 | 478 | assertThrowsWithCause(() -> admin.topics().getMessageIdByIndex(topicName, -1),
|
@@ -510,26 +507,13 @@ public void testGetMessageIdByIndexOutOfIndex() throws PulsarAdminException, Pul
|
510 | 507 | PulsarAdminException.class, NotFoundException.class);
|
511 | 508 | }
|
512 | 509 |
|
513 |
| - private void assertExceptionChainContains(Throwable thrown, Class<? extends Throwable> expectedCauseType) { |
514 |
| - Throwable cause = thrown; |
515 |
| - boolean found = false; |
516 |
| - |
517 |
| - while (cause != null) { |
518 |
| - if (expectedCauseType.isInstance(cause)) { |
519 |
| - found = true; |
520 |
| - break; |
521 |
| - } |
522 |
| - cause = cause.getCause(); |
523 |
| - } |
524 |
| - |
525 |
| - Assert.assertTrue(found); |
526 |
| - } |
527 |
| - |
528 | 510 | private void assertThrowsWithCause(Executable executable,
|
529 | 511 | Class<? extends Throwable> expectedException,
|
530 | 512 | Class<? extends Throwable> expectedCause) {
|
531 |
| - Throwable thrown = Assertions.assertThrows(expectedException, executable); |
532 |
| - assertExceptionChainContains(thrown, expectedCause); |
533 |
| - } |
| 513 | + assertThatThrownBy(executable::execute) |
| 514 | + .isInstanceOf(expectedException) |
| 515 | + .getCause() |
| 516 | + .getCause() |
| 517 | + .isInstanceOf(expectedCause); } |
534 | 518 |
|
535 | 519 | }
|
0 commit comments