|
21 | 21 | import io.objectbox.exception.DbMaxReadersExceededException;
|
22 | 22 | import org.junit.Ignore;
|
23 | 23 | import org.junit.Test;
|
| 24 | +import org.junit.function.ThrowingRunnable; |
24 | 25 |
|
25 | 26 | import java.util.ArrayList;
|
26 | 27 | import java.util.concurrent.Callable;
|
|
39 | 40 | import static org.junit.Assert.assertNotNull;
|
40 | 41 | import static org.junit.Assert.assertNotSame;
|
41 | 42 | import static org.junit.Assert.assertSame;
|
| 43 | +import static org.junit.Assert.assertThrows; |
42 | 44 | import static org.junit.Assert.assertTrue;
|
43 | 45 | import static org.junit.Assert.fail;
|
44 | 46 |
|
@@ -293,12 +295,22 @@ public void testClose() {
|
293 | 295 | // Double close should be fine
|
294 | 296 | tx.close();
|
295 | 297 |
|
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()); |
302 | 314 | }
|
303 | 315 |
|
304 | 316 | @Test
|
|
0 commit comments