1212 */
1313package org .assertj .core .api .date ;
1414
15- import static java .time .Instant .parse ;
15+ import static java .time .ZoneId .systemDefault ;
16+ import static java .util .stream .IntStream .range ;
1617import static org .assertj .core .api .Assertions .assertThat ;
1718import static org .assertj .core .api .BDDAssertions .then ;
1819import static org .assertj .core .util .AssertionsUtil .expectAssertionError ;
2122
2223import java .sql .Timestamp ;
2324import java .time .Instant ;
25+ import java .time .LocalDate ;
2426import java .util .Date ;
25-
27+ import java . util . stream . Stream ;
2628import org .junit .jupiter .api .Nested ;
29+ import org .junit .jupiter .api .Test ;
2730import org .junit .jupiter .api .TestInstance ;
2831import org .junit .jupiter .params .ParameterizedTest ;
2932import org .junit .jupiter .params .provider .Arguments ;
3235
3336/**
3437 * @author Joel Costigliola
38+ * @author Niklas Keller
3539 */
3640class DateAssert_isEqualTo_Test {
3741
@@ -46,13 +50,11 @@ void should_pass(Date actual, Object expected) {
4650 assertThat (actual ).isEqualTo (expected );
4751 }
4852
49- Arguments [] should_pass () {
50- return new Arguments [] {
51- arguments (Date .from (parse ("1970-01-01T00:00:00.000000001Z" )),
52- Date .from (parse ("1970-01-01T00:00:00.000000001Z" ))),
53- arguments (Date .from (parse ("1970-01-01T00:00:00.000000001Z" )),
54- Timestamp .from (parse ("1970-01-01T00:00:00.000000001Z" )))
55- };
53+ Stream <Arguments > should_pass () {
54+ return Stream .of (arguments (Date .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" )),
55+ Date .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" ))),
56+ arguments (Date .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" )),
57+ Timestamp .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" ))));
5658 }
5759
5860 @ ParameterizedTest
@@ -64,11 +66,9 @@ void should_fail(Date actual, Object expected) {
6466 then (error ).isInstanceOf (AssertionFailedError .class );
6567 }
6668
67- Arguments [] should_fail () {
68- return new Arguments [] {
69- arguments (Timestamp .from (parse ("1970-01-01T00:00:00.000000001Z" )),
70- Date .from (parse ("1970-01-01T00:00:00.000000001Z" )))
71- };
69+ Stream <Arguments > should_fail () {
70+ return Stream .of (arguments (Timestamp .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" )),
71+ Date .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" ))));
7272 }
7373
7474 }
@@ -84,13 +84,11 @@ void should_pass(Date actual, Instant expected) {
8484 assertThat (actual ).isEqualTo (expected );
8585 }
8686
87- Arguments [] should_pass () {
88- return new Arguments [] {
89- arguments (Date .from (parse ("1970-01-01T00:00:00.000000001Z" )),
90- parse ("1970-01-01T00:00:00.000000001Z" )),
91- arguments (Timestamp .from (parse ("1970-01-01T00:00:00.000000001Z" )),
92- parse ("1970-01-01T00:00:00.000000001Z" ))
93- };
87+ Stream <Arguments > should_pass () {
88+ return Stream .of (arguments (Date .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" )),
89+ Instant .parse ("1970-01-01T00:00:00.000000001Z" )),
90+ arguments (Timestamp .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" )),
91+ Instant .parse ("1970-01-01T00:00:00.000000001Z" )));
9492 }
9593
9694 }
@@ -106,11 +104,8 @@ void should_pass(Date actual, String expected) {
106104 assertThat (actual ).isEqualTo (expected );
107105 }
108106
109- Arguments [] should_pass () {
110- return new Arguments [] {
111- arguments (Date .from (parse ("1970-01-01T00:00:00.000000001Z" )),
112- "1970-01-01T00:00:00.000Z" )
113- };
107+ Stream <Arguments > should_pass () {
108+ return Stream .of (arguments (Date .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" )), "1970-01-01T00:00:00.000Z" ));
114109 }
115110
116111 @ ParameterizedTest
@@ -122,13 +117,20 @@ void should_fail(Date actual, String expected) {
122117 then (error ).isInstanceOf (AssertionFailedError .class );
123118 }
124119
125- Arguments [] should_fail () {
126- return new Arguments [] {
127- arguments (Date .from (parse ("1970-01-01T00:00:00.000000001Z" )),
128- "1970-01-01T00:00:00.000000001Z" ),
129- arguments (Timestamp .from (parse ("1970-01-01T00:00:00.000000001Z" )),
130- "1970-01-01T00:00:00.000000001Z" )
131- };
120+ Stream <Arguments > should_fail () {
121+ return Stream .of (arguments (Date .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" )),
122+ "1970-01-01T00:00:00.000000001Z" ),
123+ arguments (Timestamp .from (Instant .parse ("1970-01-01T00:00:00.000000001Z" )),
124+ "1970-01-01T00:00:00.000000001Z" ));
125+ }
126+
127+ // https://github.com/assertj/assertj/issues/3873
128+ @ Test
129+ void should_pass_concurrently () {
130+ // GIVEN
131+ Date actual = Date .from (LocalDate .parse ("1970-01-01" ).atStartOfDay (systemDefault ()).toInstant ());
132+ // WHEN/THEN
133+ range (0 , 1000 ).parallel ().forEach (i -> assertThat (actual ).isEqualTo ("1970-01-01" ));
132134 }
133135
134136 }
0 commit comments