Skip to content

Commit 2aec28d

Browse files
authored
Converting Clock tests to use AssertJ (exercism#2016)
1 parent 29286f6 commit 2aec28d

File tree

3 files changed

+87
-56
lines changed

3 files changed

+87
-56
lines changed
Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.junit.Ignore;
22
import org.junit.Test;
33

4-
import static org.junit.Assert.assertEquals;
4+
import static org.assertj.core.api.Assertions.assertThat;
55

66
public class ClockAddTest {
77

@@ -10,126 +10,142 @@ public class ClockAddTest {
1010
public void addMinutes() {
1111
Clock clock = new Clock(10, 0);
1212
clock.add(3);
13-
assertEquals("10:03", clock.toString());
13+
14+
assertThat(clock.toString()).isEqualTo("10:03");
1415
}
1516

1617
@Ignore("Remove to run test")
1718
@Test
1819
public void addNoMinutes() {
1920
Clock clock = new Clock(6, 41);
2021
clock.add(0);
21-
assertEquals("06:41", clock.toString());
22+
23+
assertThat(clock.toString()).isEqualTo("06:41");
2224
}
2325

2426
@Ignore("Remove to run test")
2527
@Test
2628
public void addToNextHour() {
2729
Clock clock = new Clock(0, 45);
2830
clock.add(40);
29-
assertEquals("01:25", clock.toString());
31+
32+
assertThat(clock.toString()).isEqualTo("01:25");
3033
}
3134

3235
@Ignore("Remove to run test")
3336
@Test
3437
public void addMoreThanOneHour() {
3538
Clock clock = new Clock(10, 0);
3639
clock.add(61);
37-
assertEquals("11:01", clock.toString());
40+
41+
assertThat(clock.toString()).isEqualTo("11:01");
3842
}
3943

4044
@Ignore("Remove to run test")
4145
@Test
4246
public void addMoreThanTwoHoursWithCarry() {
4347
Clock clock = new Clock(0, 45);
4448
clock.add(160);
45-
assertEquals("03:25", clock.toString());
49+
50+
assertThat(clock.toString()).isEqualTo("03:25");
4651
}
4752

4853
@Ignore("Remove to run test")
4954
@Test
5055
public void addAcrossMidnight() {
5156
Clock clock = new Clock(23, 59);
5257
clock.add(2);
53-
assertEquals("00:01", clock.toString());
58+
59+
assertThat(clock.toString()).isEqualTo("00:01");
5460
}
5561

5662
@Ignore("Remove to run test")
5763
@Test
5864
public void addMoreThanOneDay() {
5965
Clock clock = new Clock(5, 32);
6066
clock.add(1500);
61-
assertEquals("06:32", clock.toString());
67+
68+
assertThat(clock.toString()).isEqualTo("06:32");
6269
}
6370

6471
@Ignore("Remove to run test")
6572
@Test
6673
public void addMoreThanTwoDays() {
6774
Clock clock = new Clock(1, 1);
6875
clock.add(3500);
69-
assertEquals("11:21", clock.toString());
76+
77+
assertThat(clock.toString()).isEqualTo("11:21");
7078
}
7179

7280
@Ignore("Remove to run test")
7381
@Test
7482
public void subtractMinutes() {
7583
Clock clock = new Clock(10, 3);
7684
clock.add(-3);
77-
assertEquals("10:00", clock.toString());
85+
86+
assertThat(clock.toString()).isEqualTo("10:00");
7887
}
7988

8089
@Ignore("Remove to run test")
8190
@Test
8291
public void subtractToPreviousHour() {
8392
Clock clock = new Clock(10, 3);
8493
clock.add(-30);
85-
assertEquals("09:33", clock.toString());
94+
95+
assertThat(clock.toString()).isEqualTo("09:33");
8696
}
8797

8898
@Ignore("Remove to run test")
8999
@Test
90100
public void subtractMoreThanAnHour() {
91101
Clock clock = new Clock(10, 3);
92102
clock.add(-70);
93-
assertEquals("08:53", clock.toString());
103+
104+
assertThat(clock.toString()).isEqualTo("08:53");
94105
}
95106

96107
@Ignore("Remove to run test")
97108
@Test
98109
public void subtractAcrossMidnight() {
99110
Clock clock = new Clock(0, 3);
100111
clock.add(-4);
101-
assertEquals("23:59", clock.toString());
112+
113+
assertThat(clock.toString()).isEqualTo("23:59");
102114
}
103115

104116
@Ignore("Remove to run test")
105117
@Test
106118
public void subtractMoreThanTwoHours() {
107119
Clock clock = new Clock(0, 0);
108120
clock.add(-160);
109-
assertEquals("21:20", clock.toString());
121+
122+
assertThat(clock.toString()).isEqualTo("21:20");
110123
}
111124

112125
@Ignore("Remove to run test")
113126
@Test
114127
public void subtractMoreThanTwoHoursWithBorrow() {
115128
Clock clock = new Clock(6, 15);
116129
clock.add(-160);
117-
assertEquals("03:35", clock.toString());
130+
131+
assertThat(clock.toString()).isEqualTo("03:35");
118132
}
119133

120134
@Ignore("Remove to run test")
121135
@Test
122136
public void subtractMoreThanOneDay() {
123137
Clock clock = new Clock(5, 32);
124138
clock.add(-1500);
125-
assertEquals("04:32", clock.toString());
139+
140+
assertThat(clock.toString()).isEqualTo("04:32");
126141
}
127142

128143
@Ignore("Remove to run test")
129144
@Test
130145
public void subtractMoreThanTwoDays() {
131146
Clock clock = new Clock(2, 20);
132147
clock.add(-3000);
133-
assertEquals("00:20", clock.toString());
148+
149+
assertThat(clock.toString()).isEqualTo("00:20");
134150
}
135151
}
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,126 @@
11
import org.junit.Ignore;
22
import org.junit.Test;
33

4-
import static org.junit.Assert.assertEquals;
4+
import static org.assertj.core.api.Assertions.assertThat;
55

66
public class ClockCreationTest {
77

88
@Test
99
public void canPrintTimeOnTheHour() {
10-
assertEquals("08:00", new Clock(8, 0).toString());
10+
assertThat(new Clock(8, 0).toString()).isEqualTo("08:00");
1111
}
1212

1313
@Ignore("Remove to run test")
1414
@Test
1515
public void canPrintTimeWithMinutes() {
16-
assertEquals("11:09", new Clock(11, 9).toString());
16+
assertThat(new Clock(11, 9).toString()).isEqualTo("11:09");
1717
}
1818

1919
@Ignore("Remove to run test")
2020
@Test
2121
public void midnightPrintsAsZero() {
22-
assertEquals("00:00", new Clock(24, 0).toString());
22+
assertThat(new Clock(24, 0).toString()).isEqualTo("00:00");
2323
}
2424

2525
@Ignore("Remove to run test")
2626
@Test
2727
public void hourRollsOver() {
28-
assertEquals("01:00", new Clock(25, 0).toString());
28+
assertThat(new Clock(25, 0).toString()).isEqualTo("01:00");
2929
}
3030

3131
@Ignore("Remove to run test")
3232
@Test
3333
public void hourRollsOverContinuously() {
34-
assertEquals("04:00", new Clock(100, 0).toString());
34+
assertThat(new Clock(100, 0).toString()).isEqualTo("04:00");
3535
}
3636

3737
@Ignore("Remove to run test")
3838
@Test
3939
public void sixtyMinutesIsNextHour() {
40-
assertEquals("02:00", new Clock(1, 60).toString());
40+
assertThat(new Clock(1, 60).toString()).isEqualTo("02:00");
4141
}
4242

4343
@Ignore("Remove to run test")
4444
@Test
4545
public void minutesRollOver() {
46-
assertEquals("02:40", new Clock(0, 160).toString());
46+
assertThat(new Clock(0, 160).toString()).isEqualTo("02:40");
4747
}
4848

4949
@Ignore("Remove to run test")
5050
@Test
5151
public void minutesRollOverContinuously() {
52-
assertEquals("04:43", new Clock(0, 1723).toString());
52+
assertThat(new Clock(0, 1723).toString()).isEqualTo("04:43");
5353
}
5454

5555
@Ignore("Remove to run test")
5656
@Test
5757
public void hourAndMinutesRollOver() {
58-
assertEquals("03:40", new Clock(25, 160).toString());
58+
assertThat(new Clock(25, 160).toString()).isEqualTo("03:40");
5959
}
6060

6161
@Ignore("Remove to run test")
6262
@Test
6363
public void hourAndMinutesRollOverContinuously() {
64-
assertEquals("11:01", new Clock(201, 3001).toString());
64+
assertThat(new Clock(201, 3001).toString()).isEqualTo("11:01");
6565
}
6666

6767
@Ignore("Remove to run test")
6868
@Test
6969
public void hourAndMinutesRollOverToExactlyMidnight() {
70-
assertEquals("00:00", new Clock(72, 8640).toString());
70+
assertThat(new Clock(72, 8640).toString()).isEqualTo("00:00");
7171
}
7272

7373
@Ignore("Remove to run test")
7474
@Test
7575
public void negativeHour() {
76-
assertEquals("23:15", new Clock(-1, 15).toString());
76+
assertThat(new Clock(-1, 15).toString()).isEqualTo("23:15");
7777
}
7878

7979
@Ignore("Remove to run test")
8080
@Test
8181
public void negativeHourRollsOver() {
82-
assertEquals("23:00", new Clock(-25, 0).toString());
82+
assertThat(new Clock(-25, 0).toString()).isEqualTo("23:00");
8383
}
8484

8585
@Ignore("Remove to run test")
8686
@Test
8787
public void negativeHourRollsOverContinuously() {
88-
assertEquals("05:00", new Clock(-91, 0).toString());
88+
assertThat(new Clock(-91, 0).toString()).isEqualTo("05:00");
8989
}
9090

9191
@Ignore("Remove to run test")
9292
@Test
9393
public void negativeMinutes() {
94-
assertEquals("00:20", new Clock(1, -40).toString());
94+
assertThat(new Clock(1, -40).toString()).isEqualTo("00:20");
9595
}
9696

9797
@Ignore("Remove to run test")
9898
@Test
9999
public void negativeMinutesRollOver() {
100-
assertEquals("22:20", new Clock(1, -160).toString());
100+
assertThat(new Clock(1, -160).toString()).isEqualTo("22:20");
101101
}
102102

103103
@Ignore("Remove to run test")
104104
@Test
105105
public void negativeMinutesRollOverContinuously() {
106-
assertEquals("16:40", new Clock(1, -4820).toString());
106+
assertThat(new Clock(1, -4820).toString()).isEqualTo("16:40");
107107
}
108108

109109
@Ignore("Remove to run test")
110110
@Test
111111
public void negativeSixtyMinutesIsPreviousHour() {
112-
assertEquals("01:00", new Clock(2, -60).toString());
112+
assertThat(new Clock(2, -60).toString()).isEqualTo("01:00");
113113
}
114114

115115
@Ignore("Remove to run test")
116116
@Test
117117
public void negativeHourAndMinutesBothRollOver() {
118-
assertEquals("20:20", new Clock(-25, -160).toString());
118+
assertThat(new Clock(-25, -160).toString()).isEqualTo("20:20");
119119
}
120120

121121
@Ignore("Remove to run test")
122122
@Test
123123
public void negativeHourAndMinutesBothRollOverContinuously() {
124-
assertEquals("22:10", new Clock(-121, -5810).toString());
124+
assertThat(new Clock(-121, -5810).toString()).isEqualTo("22:10");
125125
}
126126
}

0 commit comments

Comments
 (0)