Skip to content

Commit ce87912

Browse files
committed
test(framework): change iterator exception asserts
change RocksDB iterator exception checks to use Assert.assertThrows for clearer intent and stricter failure behavior when expected exceptions are not thrown.
1 parent 5f118df commit ce87912

1 file changed

Lines changed: 3 additions & 15 deletions

File tree

framework/src/test/java/org/tron/core/db/DBIteratorTest.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ public void testRocksDb() throws RocksDBException, IOException {
9595
Assert.assertArrayEquals("2".getBytes(StandardCharsets.UTF_8), iterator.next().getKey());
9696
Assert.assertFalse(iterator.hasNext());
9797

98-
try {
99-
iterator.seekToLast();
100-
} catch (Exception e) {
101-
Assert.assertTrue(e instanceof IllegalStateException);
102-
}
98+
Assert.assertThrows(IllegalStateException.class, iterator::seekToLast);
10399
}
104100
try (
105101
RockStoreIterator iterator =
@@ -112,16 +108,8 @@ public void testRocksDb() throws RocksDBException, IOException {
112108
iterator.next();
113109
}
114110
Assert.assertFalse(iterator.hasNext());
115-
try {
116-
iterator.getKey();
117-
} catch (Exception e) {
118-
Assert.assertTrue(e instanceof IllegalStateException);
119-
}
120-
try {
121-
iterator.getValue();
122-
} catch (Exception e) {
123-
Assert.assertTrue(e instanceof IllegalStateException);
124-
}
111+
Assert.assertThrows(IllegalStateException.class, iterator::getKey);
112+
Assert.assertThrows(IllegalStateException.class, iterator::getValue);
125113
thrown.expect(NoSuchElementException.class);
126114
iterator.next();
127115
}

0 commit comments

Comments
 (0)