Skip to content

Commit f307db7

Browse files
sciencesakuraVanRoy
authored andcommitted
Add 'IsEqualTo' of JSR-310 value
1 parent 4f42e47 commit f307db7

File tree

6 files changed

+405
-0
lines changed

6 files changed

+405
-0
lines changed

src/main/java/org/assertj/db/api/AbstractAssertWithValues.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import org.assertj.db.navigation.origin.OriginWithColumnsAndRowsFromChange;
2020
import org.assertj.db.type.*;
2121

22+
import java.time.LocalDate;
23+
import java.time.LocalDateTime;
24+
import java.time.LocalTime;
2225
import java.util.UUID;
2326

2427
/**
@@ -212,6 +215,24 @@ public E isEqualTo(DateTimeValue expected) {
212215
return AssertionsOnValueEquality.isEqualTo(myself, info, value, expected);
213216
}
214217

218+
/** {@inheritDoc} */
219+
@Override
220+
public E isEqualTo(LocalDate expected) {
221+
return isEqualTo(DateValue.from(expected));
222+
}
223+
224+
/** {@inheritDoc} */
225+
@Override
226+
public E isEqualTo(LocalTime expected) {
227+
return isEqualTo(TimeValue.from(expected));
228+
}
229+
230+
/** {@inheritDoc} */
231+
@Override
232+
public E isEqualTo(LocalDateTime expected) {
233+
return isEqualTo(DateTimeValue.from(expected));
234+
}
235+
215236
/** {@inheritDoc} */
216237
@Override
217238
public E isNotEqualTo(Object expected) {

src/main/java/org/assertj/db/api/AbstractValueAssert.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import org.assertj.db.navigation.element.ValueElement;
2020
import org.assertj.db.type.*;
2121

22+
import java.time.LocalDate;
23+
import java.time.LocalDateTime;
24+
import java.time.LocalTime;
2225
import java.util.UUID;
2326

2427
/**
@@ -230,6 +233,24 @@ public V isEqualTo(DateTimeValue expected) {
230233
return AssertionsOnValueEquality.isEqualTo(myself, info, value, expected);
231234
}
232235

236+
/** {@inheritDoc} */
237+
@Override
238+
public V isEqualTo(LocalDate expected) {
239+
return isEqualTo(DateValue.from(expected));
240+
}
241+
242+
/** {@inheritDoc} */
243+
@Override
244+
public V isEqualTo(LocalTime expected) {
245+
return isEqualTo(TimeValue.from(expected));
246+
}
247+
248+
/** {@inheritDoc} */
249+
@Override
250+
public V isEqualTo(LocalDateTime expected) {
251+
return isEqualTo(DateTimeValue.from(expected));
252+
}
253+
233254
/** {@inheritDoc} */
234255
@Override
235256
public V isNotEqualTo(Object expected) {

src/main/java/org/assertj/db/api/assertions/AssertOnValueEquality.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import org.assertj.db.type.DateValue;
1717
import org.assertj.db.type.TimeValue;
1818

19+
import java.time.LocalDate;
20+
import java.time.LocalDateTime;
21+
import java.time.LocalTime;
1922
import java.util.UUID;
2023

2124
/**
@@ -401,6 +404,99 @@ public interface AssertOnValueEquality<T extends AssertOnValueEquality<T>> {
401404
*/
402405
T isEqualTo(DateTimeValue expected);
403406

407+
/**
408+
* Verifies that the value is equal to a date value.
409+
* <p>
410+
* Example where the assertion verifies that the value in the first {@code Column} of the first {@code Row} of the
411+
* {@code Table} is equal to a date value :
412+
* </p>
413+
*
414+
* <pre>
415+
* <code class='java'>
416+
* assertThat(table).row().value().isEqualTo(LocalDate.of(2014, 7, 7));
417+
* </code>
418+
* </pre>
419+
* <p>
420+
* Example where the assertion verifies that the value in the first {@code Column} of the {@code Row} at end point
421+
* of the first {@code Change} is equal to a date value :
422+
* </p>
423+
*
424+
* <pre>
425+
* <code class='java'>
426+
* assertThat(changes).change().rowAtEndPoint().value().isEqualTo(LocalDate.of(2014, 7, 7));
427+
* </code>
428+
* </pre>
429+
*
430+
* @param expected The expected date value.
431+
* @return {@code this} assertion object.
432+
* @throws AssertionError If the value is not equal to the date value in parameter.
433+
* @see org.assertj.db.api.AbstractValueAssert#isEqualTo(LocalDate)
434+
* @see org.assertj.db.api.AbstractAssertWithValues#isEqualTo(LocalDate)
435+
*/
436+
T isEqualTo(LocalDate expected);
437+
438+
/**
439+
* Verifies that the value is equal to a time value.
440+
* <p>
441+
* Example where the assertion verifies that the value in the first {@code Column} of the first {@code Row} of the
442+
* {@code Table} is equal to a time value :
443+
* </p>
444+
*
445+
* <pre>
446+
* <code class='java'>
447+
* assertThat(table).row().value().isEqualTo(LocalTime.of(21, 29, 30));
448+
* </code>
449+
* </pre>
450+
* <p>
451+
* Example where the assertion verifies that the value in the first {@code Column} of the {@code Row} at end point
452+
* of the first {@code Change} is equal to a time value :
453+
* </p>
454+
*
455+
* <pre>
456+
* <code class='java'>
457+
* assertThat(changes).change().rowAtEndPoint().value().isEqualTo(LocalTime.of(21, 29, 30));
458+
* </code>
459+
* </pre>
460+
*
461+
* @param expected The expected time value.
462+
* @return {@code this} assertion object.
463+
* @throws AssertionError If the value is not equal to the time value in parameter.
464+
* @see org.assertj.db.api.AbstractValueAssert#isEqualTo(LocalTime)
465+
* @see org.assertj.db.api.AbstractAssertWithValues#isEqualTo(LocalTime)
466+
*/
467+
T isEqualTo(LocalTime expected);
468+
469+
/**
470+
* Verifies that the value is equal to a date/time value.
471+
* <p>
472+
* Example where the assertion verifies that the value in the first {@code Column} of the first {@code Row} of the
473+
* {@code Table} is equal to a date/time value :
474+
* </p>
475+
*
476+
* <pre>
477+
* <code class='java'>
478+
* assertThat(table).row().value().isEqualTo(LocalDateTime.of(2014, 7, 7, 21, 29));
479+
* </code>
480+
* </pre>
481+
* <p>
482+
* Example where the assertion verifies that the value in the first {@code Column} of the {@code Row} at end point
483+
* of the first {@code Change} is equal to a date/time value :
484+
* </p>
485+
*
486+
* <pre>
487+
* <code class='java'>
488+
* assertThat(changes).change().rowAtEndPoint().value().isEqualTo(LocalDateTime.of(2014, 7, 7, 21, 29));
489+
* </code>
490+
* </pre>
491+
*
492+
* @param expected The expected date/time value.
493+
* @return {@code this} assertion object.
494+
* @throws AssertionError If the value is not equal to the date/time value in parameter.
495+
* @see org.assertj.db.api.AbstractValueAssert#isEqualTo(LocalDateTime)
496+
* @see org.assertj.db.api.AbstractAssertWithValues#isEqualTo(LocalDateTime)
497+
*/
498+
T isEqualTo(LocalDateTime expected);
499+
404500
/**
405501
* Verifies that the value is equal to zero.
406502
* <p>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2015-2020 the original author or authors.
12+
*/
13+
package org.assertj.db.api.assertions;
14+
15+
import org.assertj.core.api.Assertions;
16+
import org.assertj.db.api.ChangeColumnValueAssert;
17+
import org.assertj.db.api.TableColumnValueAssert;
18+
import org.assertj.db.common.AbstractTest;
19+
import org.assertj.db.common.NeedReload;
20+
import org.assertj.db.type.Changes;
21+
import org.assertj.db.type.Table;
22+
import org.junit.Test;
23+
24+
import java.time.LocalDateTime;
25+
26+
import static org.assertj.db.api.Assertions.assertThat;
27+
import static org.junit.Assert.fail;
28+
29+
/**
30+
* Tests on {@link org.assertj.db.api.assertions.AssertOnValueEquality} class :
31+
* {@link org.assertj.db.api.assertions.AssertOnValueEquality#isEqualTo(java.time.LocalDateTime)} method.
32+
*
33+
* @author Yosuke Nishikawa
34+
*/
35+
public class AssertOnValueEquality_IsEqualTo_LocalDateTime_Test extends AbstractTest {
36+
37+
/**
38+
* This method tests the {@code isEqualTo} assertion method.
39+
*/
40+
@Test
41+
@NeedReload
42+
public void test_is_equal_to() {
43+
Table table = new Table(source, "test");
44+
Changes changes = new Changes(table).setStartPointNow();
45+
update("update test set var14 = 1 where var1 = 1");
46+
changes.setEndPointNow();
47+
48+
ChangeColumnValueAssert changeColumnValueAssert = assertThat(changes).change().column("var10").valueAtEndPoint();
49+
ChangeColumnValueAssert changeColumnValueAssert2 = changeColumnValueAssert.isEqualTo(LocalDateTime.of(2014, 5, 24, 9, 46, 30));
50+
Assertions.assertThat(changeColumnValueAssert).isSameAs(changeColumnValueAssert2);
51+
52+
TableColumnValueAssert tableColumnValueAssert = assertThat(table).column("var10").value();
53+
TableColumnValueAssert tableColumnValueAssert2 = tableColumnValueAssert.isEqualTo(LocalDateTime.of(2014, 5, 24, 9, 46, 30));
54+
Assertions.assertThat(tableColumnValueAssert).isSameAs(tableColumnValueAssert2);
55+
}
56+
57+
/**
58+
* This method should fail because the value is no equal to.
59+
*/
60+
@Test
61+
@NeedReload
62+
public void should_fail_because_value_is_not_equal_to() {
63+
Table table = new Table(source, "test");
64+
Changes changes = new Changes(table).setStartPointNow();
65+
update("update test set var14 = 1 where var1 = 1");
66+
changes.setEndPointNow();
67+
68+
try {
69+
assertThat(changes).change().column("var10").valueAtEndPoint().isEqualTo(LocalDateTime.of(2014, 5, 24, 9, 46, 31));
70+
fail("An exception must be raised");
71+
} catch (AssertionError e) {
72+
Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[Value at end point of Column at index 9 (column name : VAR10) of Change at index 0 (with primary key : [1]) of Changes on TEST table of 'sa/jdbc:h2:mem:test' source] %n"
73+
+ "Expecting:%n"
74+
+ " <2014-05-24T09:46:30.000000000>%n"
75+
+ "to be equal to: %n"
76+
+ " <2014-05-24T09:46:31.000000000>"));
77+
}
78+
try {
79+
assertThat(table).column("var10").value().isEqualTo(LocalDateTime.of(2014, 5, 24, 9, 46, 31));
80+
fail("An exception must be raised");
81+
} catch (AssertionError e) {
82+
Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[Value at index 0 of Column at index 9 (column name : VAR10) of TEST table] %n"
83+
+ "Expecting:%n"
84+
+ " <2014-05-24T09:46:30.000000000>%n"
85+
+ "to be equal to: %n"
86+
+ " <2014-05-24T09:46:31.000000000>"));
87+
}
88+
}
89+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2015-2020 the original author or authors.
12+
*/
13+
package org.assertj.db.api.assertions;
14+
15+
import org.assertj.core.api.Assertions;
16+
import org.assertj.db.api.ChangeColumnValueAssert;
17+
import org.assertj.db.api.TableColumnValueAssert;
18+
import org.assertj.db.common.AbstractTest;
19+
import org.assertj.db.common.NeedReload;
20+
import org.assertj.db.type.Changes;
21+
import org.assertj.db.type.Table;
22+
import org.junit.Test;
23+
24+
import java.time.LocalDate;
25+
26+
import static org.assertj.db.api.Assertions.assertThat;
27+
import static org.junit.Assert.fail;
28+
29+
/**
30+
* Tests on {@link org.assertj.db.api.assertions.AssertOnValueEquality} class :
31+
* {@link org.assertj.db.api.assertions.AssertOnValueEquality#isEqualTo(java.time.LocalDate)} method.
32+
*
33+
* @author Yosuke Nishikawa
34+
*/
35+
public class AssertOnValueEquality_IsEqualTo_LocalDate_Test extends AbstractTest {
36+
37+
/**
38+
* This method tests the {@code isEqualTo} assertion method.
39+
*/
40+
@Test
41+
@NeedReload
42+
public void test_is_equal_to() {
43+
Table table = new Table(source, "test");
44+
Changes changes = new Changes(table).setStartPointNow();
45+
update("update test set var14 = 1 where var1 = 1");
46+
changes.setEndPointNow();
47+
48+
ChangeColumnValueAssert changeColumnValueAssert = assertThat(changes).change().column("var9").valueAtEndPoint();
49+
ChangeColumnValueAssert changeColumnValueAssert2 = changeColumnValueAssert.isEqualTo(LocalDate.of(2014, 5, 24));
50+
Assertions.assertThat(changeColumnValueAssert).isSameAs(changeColumnValueAssert2);
51+
52+
TableColumnValueAssert tableColumnValueAssert = assertThat(table).column("var9").value();
53+
TableColumnValueAssert tableColumnValueAssert2 = tableColumnValueAssert.isEqualTo(LocalDate.of(2014, 5, 24));
54+
Assertions.assertThat(tableColumnValueAssert).isSameAs(tableColumnValueAssert2);
55+
}
56+
57+
/**
58+
* This method should fail because the value is no equal to.
59+
*/
60+
@Test
61+
@NeedReload
62+
public void should_fail_because_value_is_not_equal_to() {
63+
Table table = new Table(source, "test");
64+
Changes changes = new Changes(table).setStartPointNow();
65+
update("update test set var14 = 1 where var1 = 1");
66+
changes.setEndPointNow();
67+
68+
try {
69+
assertThat(changes).change().column("var9").valueAtEndPoint().isEqualTo(LocalDate.of(2014, 5, 23));
70+
fail("An exception must be raised");
71+
} catch (AssertionError e) {
72+
Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[Value at end point of Column at index 8 (column name : VAR9) of Change at index 0 (with primary key : [1]) of Changes on TEST table of 'sa/jdbc:h2:mem:test' source] %n"
73+
+ "Expecting:%n"
74+
+ " <2014-05-24>%n"
75+
+ "to be equal to: %n"
76+
+ " <2014-05-23>"));
77+
}
78+
try {
79+
assertThat(table).column("var9").value().isEqualTo(LocalDate.of(2014, 5, 23));
80+
fail("An exception must be raised");
81+
} catch (AssertionError e) {
82+
Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[Value at index 0 of Column at index 8 (column name : VAR9) of TEST table] %n"
83+
+ "Expecting:%n"
84+
+ " <2014-05-24>%n"
85+
+ "to be equal to: %n"
86+
+ " <2014-05-23>"));
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)