Skip to content

Commit c531f37

Browse files
author
xiangying
committed
improve test
1 parent 44386f2 commit c531f37

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerEntryMetadataE2ETest.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package org.apache.pulsar.broker.service;
2020

2121
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;
2323

2424
import java.time.Duration;
2525
import java.util.ArrayList;
@@ -46,7 +46,6 @@
4646
import org.apache.pulsar.common.util.FutureUtil;
4747
import org.assertj.core.util.Sets;
4848
import org.awaitility.Awaitility;
49-
import org.junit.jupiter.api.Assertions;
5049
import org.junit.jupiter.api.function.Executable;
5150
import org.testng.Assert;
5251
import org.testng.annotations.AfterClass;
@@ -472,10 +471,8 @@ public void testGetMessageIdByIndex() throws Exception {
472471
(MessageIdImpl) admin.topics().getMessageIdByIndex(partitionedTopicName, index2);
473472
Assert.assertEquals(messageIdByIndex2, messageId2);
474473
// 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);
479476

480477
// 3. test invalid index
481478
assertThrowsWithCause(() -> admin.topics().getMessageIdByIndex(topicName, -1),
@@ -510,26 +507,13 @@ public void testGetMessageIdByIndexOutOfIndex() throws PulsarAdminException, Pul
510507
PulsarAdminException.class, NotFoundException.class);
511508
}
512509

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-
528510
private void assertThrowsWithCause(Executable executable,
529511
Class<? extends Throwable> expectedException,
530512
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); }
534518

535519
}

0 commit comments

Comments
 (0)