From c6ded0227dd972d4ed92a70ea6c08cb40fd2b2d4 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Wed, 3 Aug 2011 21:01:37 +0100 Subject: [PATCH] Unit test for database exception handling. --- test/net/sf/briar/db/H2DatabaseTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/net/sf/briar/db/H2DatabaseTest.java b/test/net/sf/briar/db/H2DatabaseTest.java index 9966684da..c1879b656 100644 --- a/test/net/sf/briar/db/H2DatabaseTest.java +++ b/test/net/sf/briar/db/H2DatabaseTest.java @@ -1112,6 +1112,22 @@ public class H2DatabaseTest extends TestCase { assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId)); } + @Test + public void testExceptionHandling() throws DbException { + Database db = open(false); + Connection txn = db.startTransaction(); + try { + // Ask for a nonexistent message - an exception should be thrown + db.getMessage(txn, messageId); + assertTrue(false); + } catch(DbException expected) { + // It should be possible to abort the transaction without error + db.abortTransaction(txn); + } + // It should be possible to close the database cleanly + db.close(); + } + private Database open(boolean resume) throws DbException { Database db = new H2Database(testDir, password, MAX_SIZE, groupFactory);