1+ import java .time .LocalDate ;
2+ import java .util .List ;
3+
14import org .junit .jupiter .api .Disabled ;
25import org .junit .jupiter .api .DisplayName ;
36import org .junit .jupiter .api .Test ;
47
8+ import static java .time .Month .APRIL ;
9+ import static java .time .Month .AUGUST ;
10+ import static java .time .Month .DECEMBER ;
11+ import static java .time .Month .FEBRUARY ;
12+ import static java .time .Month .JANUARY ;
13+ import static java .time .Month .JULY ;
14+ import static java .time .Month .MAY ;
15+ import static java .time .Month .NOVEMBER ;
16+ import static java .time .Month .OCTOBER ;
517import static org .assertj .core .api .Assertions .assertThat ;
618import static org .assertj .core .data .Offset .offset ;
719
8- import java .time .LocalDate ;
9- import java .util .HashSet ;
10- import java .util .List ;
11- import java .util .Set ;
12-
1320public class BafflingBirthdaysTest {
1421 private BafflingBirthdays birthdays = new BafflingBirthdays ();
1522
1623 @ Test
1724 @ DisplayName ("one birthdate" )
1825 public void oneBirthdateTest () {
19- assertThat (birthdays .sharedBirthday (List .of ("2000-01-01" ))).isFalse ();
26+ assertThat (birthdays .sharedBirthday (List .of (
27+ LocalDate .of (2000 , JANUARY , 1 )
28+ ))).isFalse ();
2029 }
2130
2231 @ Disabled ("Remove to run test" )
2332 @ Test
2433 @ DisplayName ("two birthdates with same year, month, and day" )
2534 public void twoBirthdatesWithSameYearMonthAndDayTest () {
26- assertThat (birthdays .sharedBirthday (List .of ("2000-01-01" , "2000-01-01" ))).isTrue ();
35+ assertThat (birthdays .sharedBirthday (List .of (
36+ LocalDate .of (2000 , JANUARY , 1 ),
37+ LocalDate .of (2000 , JANUARY , 1 )
38+ ))).isTrue ();
2739 }
2840
2941 @ Disabled ("Remove to run test" )
3042 @ Test
3143 @ DisplayName ("two birthdates with same year and month, but different day" )
3244 public void twoBirthdatesWithSameYearAndMonthButDifferentDayTest () {
33- assertThat (birthdays .sharedBirthday (List .of ("2012-05-09" , "2012-05-17" ))).isFalse ();
45+ assertThat (birthdays .sharedBirthday (List .of (
46+ LocalDate .of (2012 , MAY , 9 ),
47+ LocalDate .of (2012 , MAY , 17 )
48+ ))).isFalse ();
3449 }
3550
3651 @ Disabled ("Remove to run test" )
3752 @ Test
3853 @ DisplayName ("two birthdates with same month and day, but different year" )
3954 public void twoBirthdatesWithSameMonthAndDayButDifferentYearTest () {
40- assertThat (birthdays .sharedBirthday (List .of ("1999-10-23" , "1988-10-23" ))).isTrue ();
55+ assertThat (birthdays .sharedBirthday (List .of (
56+ LocalDate .of (1999 , OCTOBER , 23 ),
57+ LocalDate .of (1988 , OCTOBER , 23 )
58+ ))).isTrue ();
4159 }
4260
4361 @ Disabled ("Remove to run test" )
4462 @ Test
4563 @ DisplayName ("two birthdates with same year, but different month and day" )
4664 public void twoBirthdatesWithSameYearButDifferentMonthAndDayTest () {
47- assertThat (birthdays .sharedBirthday (List .of ("2007-12-19" , "2007-04-27" ))).isFalse ();
65+ assertThat (birthdays .sharedBirthday (List .of (
66+ LocalDate .of (2007 , DECEMBER , 19 ),
67+ LocalDate .of (2007 , APRIL , 27 )
68+ ))).isFalse ();
4869 }
4970
5071 @ Disabled ("Remove to run test" )
5172 @ Test
5273 @ DisplayName ("two birthdates with different year, month, and day" )
5374 public void twoBirthdatesWithDifferentYearMonthAndDayTest () {
54- assertThat (birthdays .sharedBirthday (List .of ("1997-08-04" , "1963-11-23" ))).isFalse ();
75+ assertThat (birthdays .sharedBirthday (List .of (
76+ LocalDate .of (1997 , AUGUST , 4 ),
77+ LocalDate .of (1963 , NOVEMBER , 23 )
78+ ))).isFalse ();
5579 }
5680
5781 @ Disabled ("Remove to run test" )
5882 @ Test
5983 @ DisplayName ("multiple birthdates without shared birthday" )
6084 public void multipleBirthdatesWithoutSharedBirthdayTest () {
61- assertThat (birthdays .sharedBirthday (List .of ("1966-07-29" , "1977-02-12" , "2001-12-25" , "1980-11-10" ))).isFalse ();
85+ assertThat (birthdays .sharedBirthday (List .of (
86+ LocalDate .of (1966 , AUGUST , 29 ),
87+ LocalDate .of (1977 , FEBRUARY , 12 ),
88+ LocalDate .of (2001 , DECEMBER , 25 ),
89+ LocalDate .of (1980 , NOVEMBER , 10 )
90+ ))).isFalse ();
6291 }
6392
6493 @ Disabled ("Remove to run test" )
6594 @ Test
6695 @ DisplayName ("multiple birthdates with one shared birthday" )
6796 public void multipleBirthdatesWithOneSharedBirthdayTest () {
68- assertThat (birthdays .sharedBirthday (List .of ("1966-07-29" , "1977-02-12" , "2001-07-29" , "1980-11-10" ))).isTrue ();
97+ assertThat (birthdays .sharedBirthday (List .of (
98+ LocalDate .of (1966 , AUGUST , 29 ),
99+ LocalDate .of (1977 , FEBRUARY , 12 ),
100+ LocalDate .of (2001 , AUGUST , 29 ),
101+ LocalDate .of (1980 , NOVEMBER , 10 )
102+ ))).isTrue ();
69103 }
70104
71105 @ Disabled ("Remove to run test" )
72106 @ Test
73107 @ DisplayName ("multiple birthdates with more than one shared birthday" )
74108 public void multipleBirthdatesWithMoreThanOneSharedBirthdayTest () {
75109 assertThat (birthdays .sharedBirthday (List .of (
76- " 1966-07-29" ,
77- " 1977-02-12" ,
78- " 2001-12-25" ,
79- " 1980-07-29" ,
80- " 2019-02-12"
110+ LocalDate . of ( 1966 , JULY , 29 ) ,
111+ LocalDate . of ( 1977 , FEBRUARY , 12 ) ,
112+ LocalDate . of ( 2001 , DECEMBER , 25 ) ,
113+ LocalDate . of ( 1980 , JULY , 29 ) ,
114+ LocalDate . of ( 2019 , FEBRUARY , 12 )
81115 ))).isTrue ();
82116 }
83117
@@ -93,41 +127,23 @@ public void generateRequestedNumberOfBirthdatesTest() {
93127 @ Test
94128 @ DisplayName ("years are not leap years" )
95129 public void yearsAreNotLeapYearsTest () {
96- for (String birthdate : birthdays .randomBirthdates (100 )) {
97- LocalDate date = LocalDate .parse (birthdate );
98- assertThat (date .isLeapYear ()).isFalse ();
99- assertThat (date .getMonthValue () == 2 && date .getDayOfMonth () == 29 ).isFalse ();
100- }
130+ assertThat (birthdays .randomBirthdates (100 )).noneMatch (LocalDate ::isLeapYear );
101131 }
102132
103133 @ Disabled ("Remove to run test" )
104134 @ Test
105135 @ DisplayName ("months are random" )
106136 public void monthsAreRandomTest () {
107- Set <Integer > months = new HashSet <>();
108- for (String birthdate : birthdays .randomBirthdates (500 )) {
109- LocalDate date = LocalDate .parse (birthdate );
110- months .add (date .getMonthValue ());
111- if (months .size () >= 7 ) {
112- break ;
113- }
114- }
115- assertThat (months ).hasSizeGreaterThanOrEqualTo (7 );
137+ assertThat (birthdays .randomBirthdates (500 ).stream ().map (LocalDate ::getMonth ).distinct ())
138+ .hasSizeGreaterThanOrEqualTo (7 );
116139 }
117140
118141 @ Disabled ("Remove to run test" )
119142 @ Test
120143 @ DisplayName ("days are random" )
121144 public void daysAreRandomTest () {
122- Set <Integer > days = new HashSet <>();
123- for (String birthdate : birthdays .randomBirthdates (500 )) {
124- LocalDate date = LocalDate .parse (birthdate );
125- days .add (date .getDayOfMonth ());
126- if (days .size () >= 11 ) {
127- break ;
128- }
129- }
130- assertThat (days ).hasSizeGreaterThanOrEqualTo (11 );
145+ assertThat (birthdays .randomBirthdates (500 ).stream ().map (LocalDate ::getDayOfMonth ).distinct ())
146+ .hasSizeGreaterThanOrEqualTo (11 );
131147 }
132148
133149 @ Disabled ("Remove to run test" )
0 commit comments