@@ -165,28 +165,28 @@ public void testTransactionReset() {
165
165
transaction .abort ();
166
166
}
167
167
168
- @ Test ( expected = IllegalStateException . class )
168
+ @ Test
169
169
public void testCreateCursorAfterAbortException () {
170
170
Transaction tx = store .beginReadTx ();
171
171
tx .abort ();
172
- tx .createKeyValueCursor ();
172
+ IllegalStateException ex = assertThrows (IllegalStateException .class , tx ::createKeyValueCursor );
173
+ assertTrue (ex .getMessage ().contains ("TX is not active anymore" ));
173
174
}
174
175
175
- @ Test ( expected = IllegalStateException . class )
176
+ @ Test
176
177
public void testCommitAfterAbortException () {
177
178
Transaction tx = store .beginTx ();
178
179
tx .abort ();
179
- tx .commit ();
180
+ IllegalStateException ex = assertThrows (IllegalStateException .class , tx ::commit );
181
+ assertTrue (ex .getMessage ().contains ("TX is not active anymore" ));
180
182
}
181
183
182
- @ Test ( expected = IllegalStateException . class )
184
+ @ Test
183
185
public void testCommitReadTxException () {
184
186
Transaction tx = store .beginReadTx ();
185
- try {
186
- tx .commit ();
187
- } finally {
188
- tx .abort ();
189
- }
187
+ IllegalStateException ex = assertThrows (IllegalStateException .class , tx ::commit );
188
+ assertEquals ("Read transactions may not be committed - use abort instead" , ex .getMessage ());
189
+ tx .abort ();
190
190
}
191
191
192
192
@ Test
@@ -195,18 +195,19 @@ public void testCommitReadTxException_exceptionListener() {
195
195
DbExceptionListener exceptionListener = e -> exs [0 ] = e ;
196
196
Transaction tx = store .beginReadTx ();
197
197
store .setDbExceptionListener (exceptionListener );
198
- try {
199
- tx .commit ();
200
- fail ("Should have thrown" );
201
- } catch (IllegalStateException e ) {
202
- tx .abort ();
203
- assertSame (e , exs [0 ]);
204
- }
198
+ IllegalStateException e = assertThrows (IllegalStateException .class , tx ::commit );
199
+ tx .abort ();
200
+ assertSame (e , exs [0 ]);
205
201
}
206
202
207
- @ Test ( expected = IllegalStateException . class )
203
+ @ Test
208
204
public void testCancelExceptionOutsideDbExceptionListener () {
209
- DbExceptionListener .cancelCurrentException ();
205
+ IllegalStateException e = assertThrows (
206
+ IllegalStateException .class ,
207
+ DbExceptionListener ::cancelCurrentException
208
+ );
209
+ assertEquals ("Canceling Java exceptions can only be done from inside exception listeners" ,
210
+ e .getMessage ());
210
211
}
211
212
212
213
@ Test
@@ -388,9 +389,13 @@ public void testRunInReadTx_recursiveWriteTxFails() {
388
389
});
389
390
}
390
391
391
- @ Test ( expected = DbException . class )
392
+ @ Test
392
393
public void testRunInReadTx_putFails () {
393
- store .runInReadTx (() -> getTestEntityBox ().put (new TestEntity ()));
394
+ DbException e = assertThrows (
395
+ DbException .class ,
396
+ () -> store .runInReadTx (() -> getTestEntityBox ().put (new TestEntity ()))
397
+ );
398
+ assertEquals ("Cannot put in read transaction" , e .getMessage ());
394
399
}
395
400
396
401
@ Test
0 commit comments