@@ -867,14 +867,27 @@ public void testOr() { |
867 | 867 | assertEquals(2007, entities.get(1).getSimpleInt()); |
868 | 868 | } |
869 | 869 |
|
870 | | - @Test(expected = IllegalStateException.class) |
| 870 | + @Test |
871 | 871 | 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()); |
873 | 879 | } |
874 | 880 |
|
875 | | - @Test(expected = IllegalStateException.class) |
| 881 | + @SuppressWarnings("resource") // Throws RuntimeException, so not closing Builder/Query is fine. |
| 882 | + @Test |
876 | 883 | 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()); |
878 | 891 | } |
879 | 892 |
|
880 | 893 | @Test |
@@ -887,24 +900,42 @@ public void testAnd() { |
887 | 900 | assertEquals(2008, entities.get(0).getSimpleInt()); |
888 | 901 | } |
889 | 902 |
|
890 | | - @Test(expected = IllegalStateException.class) |
| 903 | + @Test |
891 | 904 | public void testAnd_bad1() { |
892 | | - box.query().and(); |
| 905 | + assertNoPreviousCondition(() -> box.query().and()); |
893 | 906 | } |
894 | 907 |
|
895 | | - @Test(expected = IllegalStateException.class) |
| 908 | + @SuppressWarnings("resource") // Throws RuntimeException, so not closing Builder/Query is fine. |
| 909 | + @Test |
896 | 910 | public void testAnd_bad2() { |
897 | | - box.query().equal(simpleInt, 1).and().build(); |
| 911 | + assertIncompleteLogicCondition(() -> box.query().equal(simpleInt, 1).and().build()); |
898 | 912 | } |
899 | 913 |
|
900 | | - @Test(expected = IllegalStateException.class) |
| 914 | + @SuppressWarnings("resource") // Throws RuntimeException, so not closing Builder/Query is fine. |
| 915 | + @Test |
901 | 916 | 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()); |
903 | 923 | } |
904 | 924 |
|
905 | | - @Test(expected = IllegalStateException.class) |
| 925 | + @SuppressWarnings("resource") // Throws RuntimeException, so not closing Builder/Query is fine. |
| 926 | + @Test |
906 | 927 | 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()); |
908 | 939 | } |
909 | 940 |
|
910 | 941 | @Test |
|