|
16 | 16 |
|
17 | 17 | package io.objectbox.query;
|
18 | 18 |
|
| 19 | +import org.junit.Test; |
| 20 | + |
| 21 | +import java.util.Arrays; |
| 22 | +import java.util.List; |
| 23 | + |
19 | 24 | import io.objectbox.TestEntity;
|
20 | 25 | import io.objectbox.TestEntityCursor;
|
21 | 26 | import io.objectbox.exception.DbException;
|
22 | 27 | import io.objectbox.exception.NumericOverflowException;
|
23 | 28 | import io.objectbox.query.QueryBuilder.StringOrder;
|
24 |
| -import org.junit.Rule; |
25 |
| -import org.junit.Test; |
26 |
| -import org.junit.rules.ExpectedException; |
27 | 29 |
|
28 |
| -import java.util.Arrays; |
29 |
| -import java.util.List; |
30 | 30 |
|
31 |
| -import static io.objectbox.TestEntity_.*; |
32 |
| -import static org.junit.Assert.*; |
| 31 | +import static io.objectbox.TestEntity_.simpleBoolean; |
| 32 | +import static io.objectbox.TestEntity_.simpleByte; |
| 33 | +import static io.objectbox.TestEntity_.simpleByteArray; |
| 34 | +import static io.objectbox.TestEntity_.simpleDouble; |
| 35 | +import static io.objectbox.TestEntity_.simpleFloat; |
| 36 | +import static io.objectbox.TestEntity_.simpleInt; |
| 37 | +import static io.objectbox.TestEntity_.simpleIntU; |
| 38 | +import static io.objectbox.TestEntity_.simpleLong; |
| 39 | +import static io.objectbox.TestEntity_.simpleLongU; |
| 40 | +import static io.objectbox.TestEntity_.simpleShort; |
| 41 | +import static io.objectbox.TestEntity_.simpleShortU; |
| 42 | +import static io.objectbox.TestEntity_.simpleString; |
| 43 | +import static org.junit.Assert.assertEquals; |
| 44 | +import static org.junit.Assert.assertFalse; |
| 45 | +import static org.junit.Assert.assertNull; |
| 46 | +import static org.junit.Assert.assertThrows; |
| 47 | +import static org.junit.Assert.assertTrue; |
| 48 | +import static org.junit.Assert.fail; |
33 | 49 |
|
34 | 50 | public class PropertyQueryTest extends AbstractQueryTest {
|
35 | 51 |
|
36 |
| - @Rule |
37 |
| - public ExpectedException exceptionRule = ExpectedException.none(); |
38 |
| - |
39 | 52 | private void putTestEntityInteger(byte vByte, short vShort, int vInt, long vLong) {
|
40 | 53 | TestEntity entity = new TestEntity();
|
41 | 54 | entity.setSimpleByte(vByte);
|
@@ -753,35 +766,35 @@ public void sum_unsignedShortIntOverflow() {
|
753 | 766 |
|
754 | 767 | @Test
|
755 | 768 | public void sum_longOverflow_exception() {
|
756 |
| - exceptionRule.expect(NumericOverflowException.class); |
757 |
| - exceptionRule.expectMessage("Numeric overflow"); |
758 |
| - |
759 | 769 | putTestEntityInteger((byte) 0, (short) 0, 0, Long.MAX_VALUE);
|
760 | 770 | putTestEntityInteger((byte) 0, (short) 0, 0, 1);
|
761 | 771 |
|
762 |
| - box.query().build().property(simpleLong).sum(); |
| 772 | + NumericOverflowException exception = assertThrows(NumericOverflowException.class, () -> |
| 773 | + box.query().build().property(simpleLong).sum() |
| 774 | + ); |
| 775 | + assertTrue(exception.getMessage().contains("Numeric overflow")); |
763 | 776 | }
|
764 | 777 |
|
765 | 778 | @Test
|
766 | 779 | public void sum_longUnderflow_exception() {
|
767 |
| - exceptionRule.expect(NumericOverflowException.class); |
768 |
| - exceptionRule.expectMessage("Numeric overflow"); |
769 |
| - |
770 | 780 | putTestEntityInteger((byte) 0, (short) 0, 0, Long.MIN_VALUE);
|
771 | 781 | putTestEntityInteger((byte) 0, (short) 0, 0, -1);
|
772 | 782 |
|
773 |
| - box.query().build().property(simpleLong).sum(); |
| 783 | + NumericOverflowException exception = assertThrows(NumericOverflowException.class, () -> |
| 784 | + box.query().build().property(simpleLong).sum() |
| 785 | + ); |
| 786 | + assertTrue(exception.getMessage().contains("Numeric overflow")); |
774 | 787 | }
|
775 | 788 |
|
776 | 789 | @Test
|
777 | 790 | public void sum_unsignedLongOverflow_exception() {
|
778 |
| - exceptionRule.expect(NumericOverflowException.class); |
779 |
| - exceptionRule.expectMessage("Numeric overflow"); |
780 |
| - |
781 | 791 | putTestEntityUnsignedInteger((short) 0, 0, -1);
|
782 | 792 | putTestEntityUnsignedInteger((short) 0, 0, 1);
|
783 | 793 |
|
784 |
| - box.query().build().property(simpleLongU).sum(); |
| 794 | + NumericOverflowException exception = assertThrows(NumericOverflowException.class, () -> |
| 795 | + box.query().build().property(simpleLongU).sum() |
| 796 | + ); |
| 797 | + assertTrue(exception.getMessage().contains("Numeric overflow")); |
785 | 798 | }
|
786 | 799 |
|
787 | 800 | @Test
|
|
0 commit comments