Skip to content

Commit 45f3fb2

Browse files
sciencesakuraVanRoy
authored andcommitted
Add 'IsNotEqualTo' of JSR-310 value
1 parent f307db7 commit 45f3fb2

File tree

6 files changed

+399
-0
lines changed

6 files changed

+399
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,24 @@ public E isNotEqualTo(TimeValue expected) {
293293
return AssertionsOnValueInequality.isNotEqualTo(myself, info, value, expected);
294294
}
295295

296+
/** {@inheritDoc} */
297+
@Override
298+
public E isNotEqualTo(LocalDate expected) {
299+
return isNotEqualTo(DateValue.from(expected));
300+
}
301+
302+
/** {@inheritDoc} */
303+
@Override
304+
public E isNotEqualTo(LocalTime expected) {
305+
return isNotEqualTo(TimeValue.from(expected));
306+
}
307+
308+
/** {@inheritDoc} */
309+
@Override
310+
public E isNotEqualTo(LocalDateTime expected) {
311+
return isNotEqualTo(DateTimeValue.from(expected));
312+
}
313+
296314
/** {@inheritDoc} */
297315
@Override
298316
public E isBefore(DateValue date) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,24 @@ public V isNotEqualTo(TimeValue expected) {
311311
return AssertionsOnValueInequality.isNotEqualTo(myself, info, value, expected);
312312
}
313313

314+
/** {@inheritDoc} */
315+
@Override
316+
public V isNotEqualTo(LocalDate expected) {
317+
return isNotEqualTo(DateValue.from(expected));
318+
}
319+
320+
/** {@inheritDoc} */
321+
@Override
322+
public V isNotEqualTo(LocalTime expected) {
323+
return isNotEqualTo(TimeValue.from(expected));
324+
}
325+
326+
/** {@inheritDoc} */
327+
@Override
328+
public V isNotEqualTo(LocalDateTime expected) {
329+
return isNotEqualTo(DateTimeValue.from(expected));
330+
}
331+
314332
/** {@inheritDoc} */
315333
@Override
316334
public V isBefore(DateValue date) {

src/main/java/org/assertj/db/api/assertions/AssertOnValueInequality.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
/**
@@ -343,6 +346,99 @@ public interface AssertOnValueInequality<T extends AssertOnValueInequality<T>> {
343346
*/
344347
T isNotEqualTo(TimeValue expected);
345348

349+
/**
350+
* Verifies that the value is not equal to a date value.
351+
* <p>
352+
* Example where the assertion verifies that the value in the first {@code Column} of the first {@code Row} of the
353+
* {@code Table} is not equal to a date value :
354+
* </p>
355+
*
356+
* <pre>
357+
* <code class='java'>
358+
* assertThat(table).row().value().isNotEqualTo(LocalDate.of(2014, 7, 7));
359+
* </code>
360+
* </pre>
361+
* <p>
362+
* Example where the assertion verifies that the value in the first {@code Column} of the {@code Row} at end point
363+
* of the first {@code Change} is not equal to a date value :
364+
* </p>
365+
*
366+
* <pre>
367+
* <code class='java'>
368+
* assertThat(changes).change().rowAtEndPoint().value().isNotEqualTo(LocalDate.of(2014, 7, 7));
369+
* </code>
370+
* </pre>
371+
*
372+
* @param expected The expected date value.
373+
* @return {@code this} assertion object.
374+
* @throws AssertionError If the value is equal to the date value in parameter.
375+
* @see org.assertj.db.api.AbstractValueAssert#isNotEqualTo(LocalDate)
376+
* @see org.assertj.db.api.AbstractAssertWithValues#isNotEqualTo(LocalDate)
377+
*/
378+
T isNotEqualTo(LocalDate expected);
379+
380+
/**
381+
* Verifies that the value is not equal to a time value.
382+
* <p>
383+
* Example where the assertion verifies that the value in the first {@code Column} of the first {@code Row} of the
384+
* {@code Table} is not equal to a time value :
385+
* </p>
386+
*
387+
* <pre>
388+
* <code class='java'>
389+
* assertThat(table).row().value().isNotEqualTo(LocalTime.of(21, 29, 30));
390+
* </code>
391+
* </pre>
392+
* <p>
393+
* Example where the assertion verifies that the value in the first {@code Column} of the {@code Row} at end point
394+
* of the first {@code Change} is not equal to a time value :
395+
* </p>
396+
*
397+
* <pre>
398+
* <code class='java'>
399+
* assertThat(changes).change().rowAtEndPoint().value().isNotEqualTo(LocalTime.of(21, 29, 30));
400+
* </code>
401+
* </pre>
402+
*
403+
* @param expected The expected time value.
404+
* @return {@code this} assertion object.
405+
* @throws AssertionError If the value is equal to the time value in parameter.
406+
* @see org.assertj.db.api.AbstractValueAssert#isNotEqualTo(LocalTime)
407+
* @see org.assertj.db.api.AbstractAssertWithValues#isNotEqualTo(LocalTime)
408+
*/
409+
T isNotEqualTo(LocalTime expected);
410+
411+
/**
412+
* Verifies that the value is not equal to a date/time value.
413+
* <p>
414+
* Example where the assertion verifies that the value in the first {@code Column} of the first {@code Row} of the
415+
* {@code Table} is not equal to a date/time value :
416+
* </p>
417+
*
418+
* <pre>
419+
* <code class='java'>
420+
* assertThat(table).row().value().isNotEqualTo(LocalDateTime.of(2014, 7, 7, 21, 29));
421+
* </code>
422+
* </pre>
423+
* <p>
424+
* Example where the assertion verifies that the value in the first {@code Column} of the {@code Row} at end point
425+
* of the first {@code Change} is not equal to a date/time value :
426+
* </p>
427+
*
428+
* <pre>
429+
* <code class='java'>
430+
* assertThat(changes).change().rowAtEndPoint().value().isNotEqualTo(LocalDateTime.of(2014, 7, 7, 21, 29));
431+
* </code>
432+
* </pre>
433+
*
434+
* @param expected The expected date/time value.
435+
* @return {@code this} assertion object.
436+
* @throws AssertionError If the value is equal to the date/time value in parameter.
437+
* @see org.assertj.db.api.AbstractValueAssert#isNotEqualTo(LocalDateTime)
438+
* @see org.assertj.db.api.AbstractAssertWithValues#isNotEqualTo(LocalDateTime)
439+
*/
440+
T isNotEqualTo(LocalDateTime expected);
441+
346442
/**
347443
* Verifies that the value is not equal to zero.
348444
* <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.AssertOnValueInequality} class :
31+
* {@link org.assertj.db.api.assertions.AssertOnValueInequality#isNotEqualTo(java.time.LocalDateTime)} method.
32+
*
33+
* @author Yosuke Nishikawa
34+
*/
35+
public class AssertOnValueInequality_IsNotEqualTo_LocalDateTime_Test extends AbstractTest {
36+
37+
/**
38+
* This method tests the {@code isNotEqualTo} assertion method.
39+
*/
40+
@Test
41+
@NeedReload
42+
public void test_is_not_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.isNotEqualTo(LocalDateTime.of(2014, 5, 24, 9, 46, 31));
50+
Assertions.assertThat(changeColumnValueAssert).isSameAs(changeColumnValueAssert2);
51+
52+
TableColumnValueAssert tableColumnValueAssert = assertThat(table).column("var10").value();
53+
TableColumnValueAssert tableColumnValueAssert2 = tableColumnValueAssert.isNotEqualTo(LocalDateTime.of(2014, 5, 24, 9, 46, 31));
54+
Assertions.assertThat(tableColumnValueAssert).isSameAs(tableColumnValueAssert2);
55+
}
56+
57+
/**
58+
* This method should fail because the value is equal to.
59+
*/
60+
@Test
61+
@NeedReload
62+
public void should_fail_because_value_is_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().isNotEqualTo(LocalDateTime.of(2014, 5, 24, 9, 46, 30));
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+
+ "not to be equal to: %n"
76+
+ " <2014-05-24T09:46:30.000000000>"));
77+
}
78+
try {
79+
assertThat(table).column("var10").value().isNotEqualTo(LocalDateTime.of(2014, 5, 24, 9, 46, 30));
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+
+ "not to be equal to: %n"
86+
+ " <2014-05-24T09:46:30.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.AssertOnValueInequality} class :
31+
* {@link org.assertj.db.api.assertions.AssertOnValueInequality#isNotEqualTo(java.time.LocalDate)} method.
32+
*
33+
* @author Yosuke Nishikawa
34+
*/
35+
public class AssertOnValueInequality_IsNotEqualTo_LocalDate_Test extends AbstractTest {
36+
37+
/**
38+
* This method tests the {@code isNotEqualTo} assertion method.
39+
*/
40+
@Test
41+
@NeedReload
42+
public void test_is_not_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.isNotEqualTo(LocalDate.of(2007, 12, 23));
50+
Assertions.assertThat(changeColumnValueAssert).isSameAs(changeColumnValueAssert2);
51+
52+
TableColumnValueAssert tableColumnValueAssert = assertThat(table).column("var9").value();
53+
TableColumnValueAssert tableColumnValueAssert2 = tableColumnValueAssert.isNotEqualTo(LocalDate.of(2007, 12, 23));
54+
Assertions.assertThat(tableColumnValueAssert).isSameAs(tableColumnValueAssert2);
55+
}
56+
57+
/**
58+
* This method should fail because the value is greater than or equal to.
59+
*/
60+
@Test
61+
@NeedReload
62+
public void should_fail_because_value_is_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().isNotEqualTo(LocalDate.of(2014, 5, 24));
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+
+ "not to be equal to: %n"
76+
+ " <2014-05-24>"));
77+
}
78+
try {
79+
assertThat(table).column("var9").value().isNotEqualTo(LocalDate.of(2014, 5, 24));
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+
+ "not to be equal to: %n"
86+
+ " <2014-05-24>"));
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)