Skip to content

Commit d5daac9

Browse files
Use Cleaner to destroy TemporaryDb in tests:
Register the database in the cleaner to simplify the teardown operation and make it more reliable.
1 parent 752f7a6 commit d5daac9

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

exonum-java-binding/core/src/test/java/com/exonum/binding/core/blockchain/BlockchainDataIntegrationTest.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,19 @@
4242
@Disabled("ECR-4169")
4343
class BlockchainDataIntegrationTest {
4444

45-
TemporaryDb db;
4645
Cleaner cleaner;
46+
TemporaryDb db;
4747

4848
@BeforeEach
4949
void setUp() {
50-
db = TemporaryDb.newInstance();
5150
cleaner = new Cleaner();
51+
db = TemporaryDb.newInstance();
52+
cleaner.add(db::close);
5253
}
5354

5455
@AfterEach
5556
void tearDown() throws CloseFailuresException {
56-
if (cleaner != null) {
57-
cleaner.close();
58-
}
59-
if (db != null) {
60-
db.close();
61-
}
57+
cleaner.close();
6258
}
6359

6460
@Test

exonum-java-binding/core/src/test/java/com/exonum/binding/core/storage/database/PrefixedIntegrationTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ class PrefixedIntegrationTest {
3838
class WithIndex {
3939
final String namespace = "test-namespace";
4040
final String entryName = "test-index";
41-
TemporaryDb db;
4241
Cleaner cleaner;
42+
TemporaryDb db;
4343

4444
@BeforeEach
4545
void initializeDatabase(TestInfo info) throws CloseFailuresException {
4646
// Create the database
47-
db = TemporaryDb.newInstance();
4847
cleaner = new Cleaner(info.getDisplayName());
48+
db = TemporaryDb.newInstance();
49+
cleaner.add(db::close);
4950

5051
// Initialize the test index
5152
try (Cleaner initCleaner = new Cleaner()) {
@@ -144,11 +145,7 @@ void baseCleanerInvalidatesIndexesFromPrefixed() throws CloseFailuresException {
144145

145146
@AfterEach
146147
void dropDatabase() throws CloseFailuresException {
147-
try {
148-
cleaner.close();
149-
} finally {
150-
db.close();
151-
}
148+
cleaner.close();
152149
}
153150
}
154151
}

exonum-java-binding/core/src/test/java/com/exonum/binding/core/storage/database/ReadonlyForkIntegrationTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,19 @@
3232
@Disabled("ECR-4167")
3333
class ReadonlyForkIntegrationTest {
3434

35-
private TemporaryDb db;
3635
private Cleaner cleaner;
36+
private TemporaryDb db;
3737

3838
@BeforeEach
3939
void setupDb() {
40-
db = TemporaryDb.newInstance();
4140
cleaner = new Cleaner();
41+
db = TemporaryDb.newInstance();
42+
cleaner.add(db::close);
4243
}
4344

4445
@AfterEach
4546
void tearDown() throws CloseFailuresException {
46-
try {
47-
if (cleaner != null) {
48-
cleaner.close();
49-
}
50-
} finally {
51-
db.close();
52-
}
47+
cleaner.close();
5348
}
5449

5550
@Test

0 commit comments

Comments
 (0)