|
12 | 12 | */ |
13 | 13 | package org.assertj.db.util; |
14 | 14 |
|
15 | | -import static org.assertj.core.api.Assertions.assertThat; |
16 | | -import static org.assertj.db.api.Assertions.bytesContentFromClassPathOf; |
17 | | - |
18 | 15 | import java.math.BigDecimal; |
19 | 16 | import java.math.BigInteger; |
| 17 | +import java.sql.Array; |
20 | 18 | import java.sql.Date; |
| 19 | +import java.sql.SQLException; |
21 | 20 | import java.sql.Time; |
22 | 21 | import java.sql.Timestamp; |
23 | 22 | import java.time.LocalDate; |
|
27 | 26 | import java.util.concurrent.atomic.AtomicLong; |
28 | 27 |
|
29 | 28 | import org.assertj.db.common.AbstractTest; |
| 29 | +import org.assertj.db.common.SimpleArray; |
30 | 30 | import org.assertj.db.exception.AssertJDBException; |
31 | 31 | import org.assertj.db.type.DateTimeValue; |
32 | 32 | import org.assertj.db.type.DateValue; |
33 | 33 | import org.assertj.db.type.TimeValue; |
34 | 34 | import org.junit.Test; |
35 | 35 |
|
| 36 | +import static org.assertj.core.api.Assertions.assertThat; |
| 37 | +import static org.assertj.db.api.Assertions.bytesContentFromClassPathOf; |
| 38 | + |
36 | 39 | /** |
37 | 40 | * Tests on {@code areEqual} method for {@code Object}s. |
38 | 41 | * |
@@ -545,4 +548,30 @@ public void test_are_equal_for_datestimes() throws Exception { |
545 | 548 | public void should_fail_because_string_is_not_parseable_in_datetime() throws Exception { |
546 | 549 | Values.areEqual(getValue(null, Timestamp.valueOf("2007-12-23 09:01:06.000000003")), (Object) "***"); |
547 | 550 | } |
| 551 | + |
| 552 | + /** |
| 553 | + * This method tests the {@code areEqual} method for {@code java.sql.Array}s. |
| 554 | + */ |
| 555 | + @Test |
| 556 | + public void test_are_equal_for_arrays() throws Exception { |
| 557 | + assertThat(Values.areEqual(getValue(null, (Array) null), (Array) null)).isTrue(); |
| 558 | + assertThat(Values.areEqual(getValue(null, new SimpleArray(new String[]{"value1"})), (Array) null)).isFalse(); |
| 559 | + assertThat(Values.areEqual(getValue(null, new SimpleArray(new String[]{"value1"})), new SimpleArray(new String[]{"value2"}))).isFalse(); |
| 560 | + assertThat(Values.areEqual(getValue(null, new SimpleArray(new String[]{"value1"})), new SimpleArray(new String[]{"value1"}))).isTrue(); |
| 561 | + assertThat(Values.areEqual(getValue(null, new SimpleArray(new String[]{"value1"})), new SimpleArray(new String[]{"value1", "value2"}))).isFalse(); |
| 562 | + } |
| 563 | + |
| 564 | + /** |
| 565 | + * This method should fail because the object is already closed |
| 566 | + */ |
| 567 | + @Test(expected = AssertJDBException.class) |
| 568 | + public void should_fail_because_array_not_readable() throws Exception { |
| 569 | + Array array = new SimpleArray(null) { |
| 570 | + @Override |
| 571 | + public Object getArray() throws SQLException { |
| 572 | + throw new SQLException(); |
| 573 | + } |
| 574 | + }; |
| 575 | + Values.areEqual(getValue(null, (Array) array), array); |
| 576 | + } |
548 | 577 | } |
0 commit comments