Skip to content

Commit 0ffaadc

Browse files
authored
Fix say exercise (exercism#2006)
* Upgrade junit version * Move assertions to assertj
1 parent a682dbc commit 0ffaadc

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

exercises/practice/say/build.gradle

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ apply plugin: "java"
22
apply plugin: "eclipse"
33
apply plugin: "idea"
44

5+
// set default encoding to UTF-8
6+
compileJava.options.encoding = "UTF-8"
7+
compileTestJava.options.encoding = "UTF-8"
8+
59
repositories {
610
mavenCentral()
711
}
812

913
dependencies {
10-
testImplementation "junit:junit:4.12"
14+
testImplementation "junit:junit:4.13"
15+
testImplementation "org.assertj:assertj-core:3.15.0"
1116
}
1217

1318
test {
1419
testLogging {
15-
exceptionFormat = 'full'
20+
exceptionFormat = 'short'
21+
showStandardStreams = true
1622
events = ["passed", "failed", "skipped"]
1723
}
1824
}

exercises/practice/say/src/test/java/SayTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,89 @@
11
import org.junit.Test;
22
import org.junit.Ignore;
33

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

66
public class SayTest {
77

88
private Say say = new Say();
99

1010
@Test
1111
public void zero() {
12-
assertEquals("zero", say.say(0));
12+
assertThat(say.say(0)).isEqualTo("zero");
1313
}
1414

1515
@Ignore("Remove to run test")
1616
@Test
1717
public void one() {
18-
assertEquals("one", say.say(1));
18+
assertThat(say.say(1)).isEqualTo("one");
1919
}
2020

2121
@Ignore("Remove to run test")
2222
@Test
2323
public void fourteen() {
24-
assertEquals("fourteen", say.say(14));
24+
assertThat(say.say(14)).isEqualTo("fourteen");
2525
}
2626

2727
@Ignore("Remove to run test")
2828
@Test
2929
public void twenty() {
30-
assertEquals("twenty", say.say(20));
30+
assertThat(say.say(20)).isEqualTo("twenty");
3131
}
3232

3333
@Ignore("Remove to run test")
3434
@Test
3535
public void twentyTwo() {
36-
assertEquals("twenty-two", say.say(22));
36+
assertThat(say.say(22)).isEqualTo("twenty-two");
3737
}
3838

3939
@Ignore("Remove to run test")
4040
@Test
4141
public void oneHundred() {
42-
assertEquals("one hundred", say.say(100));
42+
assertThat(say.say(100)).isEqualTo("one hundred");
4343
}
4444

4545
@Ignore("Remove to run test")
4646
@Test
4747
public void oneHundredTwentyThree() {
48-
assertEquals("one hundred twenty-three", say.say(123));
48+
assertThat(say.say(123)).isEqualTo("one hundred twenty-three");
4949
}
5050

5151
@Ignore("Remove to run test")
5252
@Test
5353
public void oneThousand() {
54-
assertEquals("one thousand", say.say(1_000));
54+
assertThat(say.say(1_000)).isEqualTo("one thousand");
5555
}
5656

5757
@Ignore("Remove to run test")
5858
@Test
5959
public void oneThousandTwoHundredThirtyFour() {
60-
assertEquals("one thousand two hundred thirty-four", say.say(1_234));
60+
assertThat(say.say(1_234)).isEqualTo("one thousand two hundred thirty-four");
6161
}
6262

6363
@Ignore("Remove to run test")
6464
@Test
6565
public void oneMillion() {
66-
assertEquals("one million", say.say(1_000_000));
66+
assertThat(say.say(1_000_000)).isEqualTo("one million");
6767
}
6868

6969
@Ignore("Remove to run test")
7070
@Test
7171
public void oneMillionTwoThousandThreeHundredFortyFive() {
72-
assertEquals("one million two thousand three hundred forty-five", say.say(1_002_345));
72+
assertThat(say.say(1_002_345)).isEqualTo("one million two thousand three hundred forty-five");
7373
}
7474

7575
@Ignore("Remove to run test")
7676
@Test
7777
public void oneBillion() {
78-
assertEquals("one billion", say.say(1_000_000_000));
78+
assertThat(say.say(1_000_000_000)).isEqualTo("one billion");
7979
}
8080

8181
@Ignore("Remove to run test")
8282
@Test
8383
public void nineHundredEightySevenBillionSixHundredFiftyFourThreeHundredTwentyOneThousandOneHundredTwentyThree() {
84-
assertEquals("nine hundred eighty-seven billion six hundred fifty-four million" +
85-
" three hundred twenty-one thousand one hundred twenty-three", say.say(987_654_321_123L));
84+
assertThat(say.say(987_654_321_123L))
85+
.isEqualTo("nine hundred eighty-seven billion six hundred fifty-four million" +
86+
" three hundred twenty-one thousand one hundred twenty-three");
8687
}
8788

8889
@Ignore("Remove to run test")

0 commit comments

Comments
 (0)