@@ -867,14 +867,27 @@ public void testOr() {
867867 assertEquals (2007 , entities .get (1 ).getSimpleInt ());
868868 }
869869
870- @ Test ( expected = IllegalStateException . class )
870+ @ Test
871871 public void testOr_bad1 () {
872- box .query ().or ();
872+ assertNoPreviousCondition (() -> box .query ().or ());
873+ }
874+
875+ private void assertNoPreviousCondition (ThrowingRunnable runnable ) {
876+ IllegalStateException ex = assertThrows (IllegalStateException .class , runnable );
877+ assertEquals ("No previous condition. Use operators like and() and or() only between two conditions." ,
878+ ex .getMessage ());
873879 }
874880
875- @ Test (expected = IllegalStateException .class )
881+ @ SuppressWarnings ("resource" ) // Throws RuntimeException, so not closing Builder/Query is fine.
882+ @ Test
876883 public void testOr_bad2 () {
877- box .query ().equal (simpleInt , 1 ).or ().build ();
884+ assertIncompleteLogicCondition (() -> box .query ().equal (simpleInt , 1 ).or ().build ());
885+ }
886+
887+ private void assertIncompleteLogicCondition (ThrowingRunnable runnable ) {
888+ IllegalStateException ex = assertThrows (IllegalStateException .class , runnable );
889+ assertEquals ("Incomplete logic condition. Use or()/and() between two conditions only." ,
890+ ex .getMessage ());
878891 }
879892
880893 @ Test
@@ -887,24 +900,42 @@ public void testAnd() {
887900 assertEquals (2008 , entities .get (0 ).getSimpleInt ());
888901 }
889902
890- @ Test ( expected = IllegalStateException . class )
903+ @ Test
891904 public void testAnd_bad1 () {
892- box .query ().and ();
905+ assertNoPreviousCondition (() -> box .query ().and () );
893906 }
894907
895- @ Test (expected = IllegalStateException .class )
908+ @ SuppressWarnings ("resource" ) // Throws RuntimeException, so not closing Builder/Query is fine.
909+ @ Test
896910 public void testAnd_bad2 () {
897- box .query ().equal (simpleInt , 1 ).and ().build ();
911+ assertIncompleteLogicCondition (() -> box .query ().equal (simpleInt , 1 ).and ().build () );
898912 }
899913
900- @ Test (expected = IllegalStateException .class )
914+ @ SuppressWarnings ("resource" ) // Throws RuntimeException, so not closing Builder/Query is fine.
915+ @ Test
901916 public void testOrAfterAnd () {
902- box .query ().equal (simpleInt , 1 ).and ().or ().equal (simpleInt , 2 ).build ();
917+ assertOperatorIsPending (() -> box .query ()
918+ .equal (simpleInt , 1 )
919+ .and ()
920+ .or ()
921+ .equal (simpleInt , 2 )
922+ .build ());
903923 }
904924
905- @ Test (expected = IllegalStateException .class )
925+ @ SuppressWarnings ("resource" ) // Throws RuntimeException, so not closing Builder/Query is fine.
926+ @ Test
906927 public void testOrderAfterAnd () {
907- box .query ().equal (simpleInt , 1 ).and ().order (simpleInt ).equal (simpleInt , 2 ).build ();
928+ assertOperatorIsPending (() -> box .query ()
929+ .equal (simpleInt , 1 )
930+ .and ().order (simpleInt )
931+ .equal (simpleInt , 2 )
932+ .build ());
933+ }
934+
935+ private void assertOperatorIsPending (ThrowingRunnable runnable ) {
936+ IllegalStateException ex = assertThrows (IllegalStateException .class , runnable );
937+ assertEquals ("Another operator is pending. Use operators like and() and or() only between two conditions." ,
938+ ex .getMessage ());
908939 }
909940
910941 @ Test
0 commit comments