File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
tests/objectbox-java-test/src/test/java/io/objectbox Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,26 @@ public void testCommitReadTxException_exceptionListener() {
192192 }
193193 }
194194
195+ @ Test (expected = IllegalStateException .class )
196+ public void testCancelExceptionOutsideDbExceptionListener () {
197+ DbExceptionListener .cancelCurrentException ();
198+ }
199+
200+ @ Test
201+ public void testCommitReadTxException_cancelException () {
202+ final Exception [] exs = {null };
203+ DbExceptionListener exceptionListener = e -> {
204+ if (exs [0 ] != null ) throw new RuntimeException ("Called more than once" );
205+ exs [0 ] = e ;
206+ DbExceptionListener .cancelCurrentException ();
207+ };
208+ Transaction tx = store .beginReadTx ();
209+ store .setDbExceptionListener (exceptionListener );
210+ tx .commit ();
211+ tx .abort ();
212+ assertNotNull (exs [0 ]);
213+ }
214+
195215 /*
196216 @Test
197217 public void testTransactionUsingAfterStoreClosed() {
Original file line number Diff line number Diff line change @@ -702,6 +702,24 @@ public void testFailedUnique_exceptionListener() {
702702 }
703703 }
704704
705+ @ Test
706+ public void testFailedUnique_cancelException () {
707+ final Exception [] exs = {null };
708+ DbExceptionListener exceptionListener = e -> {
709+ if (exs [0 ] != null ) throw new RuntimeException ("Called more than once" );
710+ exs [0 ] = e ;
711+ DbExceptionListener .cancelCurrentException ();
712+ };
713+ putTestEntitiesStrings ();
714+ Query <TestEntity > query = box .query ().build ();
715+ store .setDbExceptionListener (exceptionListener );
716+
717+ TestEntity object = query .findUnique ();
718+ assertNull (object );
719+ assertNotNull (exs [0 ]);
720+ assertEquals (exs [0 ].getClass (), NonUniqueResultException .class );
721+ }
722+
705723 @ Test
706724 public void testDescribe () {
707725 // Note: description string correctness is fully asserted in core library.
You can’t perform that action at this time.
0 commit comments