Skip to content

Commit 7bd3373

Browse files
Little-Peonyclaude
andcommitted
test(framework): replace Assert.fail with throws Exception in test methods
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e11fce0 commit 7bd3373

3 files changed

Lines changed: 27 additions & 55 deletions

File tree

framework/src/test/java/org/tron/common/utils/PropUtilTest.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
package org.tron.common.utils;
22

33
import java.io.File;
4-
import java.io.IOException;
54
import org.junit.Assert;
65
import org.junit.Test;
76

87
public class PropUtilTest {
98

109
@Test
11-
public void testWriteProperty() {
10+
public void testWriteProperty() throws Exception {
1211
String filename = "test_prop.properties";
1312
File file = new File(filename);
14-
try {
15-
file.createNewFile();
16-
} catch (IOException e) {
17-
Assert.fail(e.getMessage());
18-
}
13+
file.createNewFile();
1914
PropUtil.writeProperty(filename, "key", "value");
2015
Assert.assertTrue("value".equals(PropUtil.readProperty(filename, "key")));
2116
PropUtil.writeProperty(filename, "key", "value2");
@@ -24,14 +19,10 @@ public void testWriteProperty() {
2419
}
2520

2621
@Test
27-
public void testReadProperty() {
22+
public void testReadProperty() throws Exception {
2823
String filename = "test_prop.properties";
2924
File file = new File(filename);
30-
try {
31-
file.createNewFile();
32-
} catch (IOException e) {
33-
Assert.fail(e.getMessage());
34-
}
25+
file.createNewFile();
3526
PropUtil.writeProperty(filename, "key", "value");
3627
Assert.assertTrue("value".equals(PropUtil.readProperty(filename, "key")));
3728
file.delete();

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

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import org.tron.common.utils.Sha256Hash;
1111
import org.tron.core.capsule.BlockCapsule;
1212
import org.tron.core.config.args.Args;
13-
import org.tron.core.exception.BadItemException;
14-
import org.tron.core.exception.ItemNotFoundException;
1513

1614

1715
@Slf4j
@@ -35,56 +33,43 @@ public void testCreateBlockStore() {
3533
}
3634

3735
@Test
38-
public void testPut() {
36+
public void testPut() throws Exception {
3937
long number = 1;
4038
BlockCapsule blockCapsule = getBlockCapsule(number);
4139

4240
byte[] blockId = blockCapsule.getBlockId().getBytes();
4341
blockStore.put(blockId, blockCapsule);
44-
try {
45-
BlockCapsule blockCapsule1 = blockStore.get(blockId);
46-
Assert.assertNotNull(blockCapsule1);
47-
Assert.assertEquals(number, blockCapsule1.getNum());
48-
} catch (ItemNotFoundException | BadItemException e) {
49-
Assert.fail(e.getMessage());
50-
}
42+
BlockCapsule blockCapsule1 = blockStore.get(blockId);
43+
Assert.assertNotNull(blockCapsule1);
44+
Assert.assertEquals(number, blockCapsule1.getNum());
5145
}
5246

5347
@Test
54-
public void testGet() {
48+
public void testGet() throws Exception {
5549
long number = 2;
5650
BlockCapsule blockCapsule = getBlockCapsule(number);
5751
byte[] blockId = blockCapsule.getBlockId().getBytes();
5852
blockStore.put(blockId, blockCapsule);
59-
try {
60-
boolean has = blockStore.has(blockId);
61-
Assert.assertTrue(has);
62-
BlockCapsule blockCapsule1 = blockStore.get(blockId);
63-
64-
Assert.assertEquals(number, blockCapsule1.getNum());
65-
} catch (ItemNotFoundException | BadItemException e) {
66-
Assert.fail(e.getMessage());
67-
}
53+
boolean has = blockStore.has(blockId);
54+
Assert.assertTrue(has);
55+
BlockCapsule blockCapsule1 = blockStore.get(blockId);
56+
Assert.assertEquals(number, blockCapsule1.getNum());
6857
}
6958

7059
@Test
71-
public void testDelete() {
60+
public void testDelete() throws Exception {
7261
long number = 1;
7362
BlockCapsule blockCapsule = getBlockCapsule(number);
7463

7564
byte[] blockId = blockCapsule.getBlockId().getBytes();
7665
blockStore.put(blockId, blockCapsule);
77-
try {
78-
BlockCapsule blockCapsule1 = blockStore.get(blockId);
79-
Assert.assertNotNull(blockCapsule1);
80-
Assert.assertEquals(number, blockCapsule1.getNum());
66+
BlockCapsule blockCapsule1 = blockStore.get(blockId);
67+
Assert.assertNotNull(blockCapsule1);
68+
Assert.assertEquals(number, blockCapsule1.getNum());
8169

82-
blockStore.delete(blockId);
83-
BlockCapsule blockCapsule2 = blockStore.getUnchecked(blockId);
84-
Assert.assertNull(blockCapsule2);
85-
} catch (ItemNotFoundException | BadItemException e) {
86-
Assert.fail(e.getMessage());
87-
}
70+
blockStore.delete(blockId);
71+
BlockCapsule blockCapsule2 = blockStore.getUnchecked(blockId);
72+
Assert.assertNull(blockCapsule2);
8873
}
8974

9075
}

framework/src/test/java/org/tron/core/db2/SnapshotImplTest.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected void beforeDestroy() {
3838
* from: get key1 or key2, traverse 0 times
3939
*/
4040
@Test
41-
public void testMergeRoot() {
41+
public void testMergeRoot() throws Exception {
4242
// linklist is: from -> root
4343
SnapshotRoot root = new SnapshotRoot(tronDatabase.getDb());
4444
//root.setOptimized(true);
@@ -68,7 +68,7 @@ public void testMergeRoot() {
6868
*
6969
*/
7070
@Test
71-
public void testMergeAhead() {
71+
public void testMergeAhead() throws Exception {
7272

7373
// linklist is: from2 -> from -> root
7474
SnapshotRoot root = new SnapshotRoot(tronDatabase.getDb());
@@ -136,7 +136,7 @@ public void testMergeAhead() {
136136
* from2: key1=>value1, key2=>value2, key3=>value32, key4=>value4
137137
*/
138138
@Test
139-
public void testMergeOverride() {
139+
public void testMergeOverride() throws Exception {
140140
// linklist is: from2 -> from -> root
141141
SnapshotRoot root = new SnapshotRoot(tronDatabase.getDb());
142142
SnapshotImpl from = getSnapshotImplIns(root);
@@ -165,15 +165,11 @@ public void testMergeOverride() {
165165
* The constructor of SnapshotImpl is not public
166166
* so reflection is used to construct the object here.
167167
*/
168-
private SnapshotImpl getSnapshotImplIns(Snapshot snapshot) {
168+
private SnapshotImpl getSnapshotImplIns(Snapshot snapshot) throws Exception {
169169
Class clazz = SnapshotImpl.class;
170-
try {
171-
Constructor constructor = clazz.getDeclaredConstructor(Snapshot.class);
172-
constructor.setAccessible(true);
173-
return (SnapshotImpl) constructor.newInstance(snapshot);
174-
} catch (Exception e) {
175-
throw new AssertionError(e);
176-
}
170+
Constructor constructor = clazz.getDeclaredConstructor(Snapshot.class);
171+
constructor.setAccessible(true);
172+
return (SnapshotImpl) constructor.newInstance(snapshot);
177173
}
178174

179175
}

0 commit comments

Comments
 (0)