GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Transaction: test it throws after close (objectbox#818) · pxunever/objectbox-java@b139e6a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests/objectbox-java-test/src/test/java/io/objectbox
    • TransactionTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tests/objectbox-java-test/src/test/java/io/objectbox/TransactionTest.java‎

Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/TransactionTest.java
+18-6Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.objectbox.exception.DbMaxReadersExceededException;
2222
import org.junit.Ignore;
2323
import org.junit.Test;
24+
import org.junit.function.ThrowingRunnable;
2425

2526
import java.util.ArrayList;
2627
import java.util.concurrent.Callable;
@@ -39,6 +40,7 @@
3940
import static org.junit.Assert.assertNotNull;
4041
import static org.junit.Assert.assertNotSame;
4142
import static org.junit.Assert.assertSame;
43+
import static org.junit.Assert.assertThrows;
4244
import static org.junit.Assert.assertTrue;
4345
import static org.junit.Assert.fail;
4446

@@ -293,12 +295,22 @@ public void testClose() {
293295
// Double close should be fine
294296
tx.close();
295297

296-
try {
297-
tx.reset();
298-
fail("Should have thrown");
299-
} catch (IllegalStateException e) {
300-
// OK
301-
}
298+
// Calling other methods should throw.
299+
assertThrowsTxClosed(tx::commit);
300+
assertThrowsTxClosed(tx::commitAndClose);
301+
assertThrowsTxClosed(tx::abort);
302+
assertThrowsTxClosed(tx::reset);
303+
assertThrowsTxClosed(tx::recycle);
304+
assertThrowsTxClosed(tx::renew);
305+
assertThrowsTxClosed(tx::createKeyValueCursor);
306+
assertThrowsTxClosed(() -> tx.createCursor(TestEntity.class));
307+
assertThrowsTxClosed(tx::isActive);
308+
assertThrowsTxClosed(tx::isRecycled);
309+
}
310+
311+
private void assertThrowsTxClosed(ThrowingRunnable runnable) {
312+
IllegalStateException ex = assertThrows(IllegalStateException.class, runnable);
313+
assertEquals("Transaction is closed", ex.getMessage());
302314
}
303315

304316
@Test

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.