Skip to content

Commit 206bc9a

Browse files
authored
Update wizards and warriors to use test runner v3 features (#2499)
1 parent eeea1c3 commit 206bc9a

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

exercises/concept/wizards-and-warriors/build.gradle

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
apply plugin: "java"
2-
apply plugin: "eclipse"
3-
apply plugin: "idea"
1+
plugins {
2+
id "java"
3+
}
44

55
repositories {
66
mavenCentral()
77
}
88

99
dependencies {
10-
testImplementation "junit:junit:4.13"
10+
testImplementation platform("org.junit:junit-bom:5.10.0")
11+
testImplementation "org.junit.jupiter:junit-jupiter"
1112
testImplementation "org.assertj:assertj-core:3.15.0"
1213
}
1314

1415
test {
16+
useJUnitPlatform()
17+
1518
testLogging {
16-
exceptionFormat = 'full'
19+
exceptionFormat = "full"
1720
showStandardStreams = true
1821
events = ["passed", "failed", "skipped"]
1922
}

exercises/concept/wizards-and-warriors/src/test/java/FighterTest.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,86 @@
1-
import org.junit.Test;
1+
import org.junit.jupiter.api.DisplayName;
2+
import org.junit.jupiter.api.Tag;
3+
import org.junit.jupiter.api.Test;
24

3-
import static org.assertj.core.api.Assertions.assertThat;
5+
import static org.assertj.core.api.Assertions.*;
46

57
public class FighterTest {
68

79
@Test
10+
@Tag("task:1")
11+
@DisplayName("The toString method of the Warrior returns the correct description of the fighter")
812
public void testWarriorToString() {
913
Fighter warrior = new Warrior();
1014
assertThat(warrior.toString()).isEqualTo("Fighter is a Warrior");
1115
}
1216

1317
@Test
18+
@Tag("task:1")
19+
@DisplayName("The toString method of the Wizard returns the correct description of the fighter")
1420
public void testWizardToString() {
1521
Wizard wizard = new Wizard();
1622
assertThat(wizard.toString()).isEqualTo("Fighter is a Wizard");
1723
}
1824

1925
@Test
20-
public void testFighterVulnerableByDefault() {
26+
@Tag("task:2")
27+
@DisplayName("The isVulnerable method of the Warrior returns false by default")
28+
public void testFighterNotVulnerableByDefault() {
2129
Fighter warrior = new Warrior();
2230
assertThat(warrior.isVulnerable()).isFalse();
2331
}
2432

2533
@Test
34+
@Tag("task:3")
35+
@DisplayName("The prepareSpell method makes the Wizard not vulnerable")
2636
public void testWizardVulnerable() {
2737
Wizard wizard = new Wizard();
28-
assertThat(wizard.isVulnerable()).isTrue();
2938
wizard.prepareSpell();
3039
assertThat(wizard.isVulnerable()).isFalse();
3140
}
3241

3342
@Test
43+
@Tag("task:4")
44+
@DisplayName("The isVulnerable method of the Wizard returns true by default")
45+
public void testWizardVulnerableByDefault() {
46+
Wizard wizard = new Wizard();
47+
assertThat(wizard.isVulnerable()).isTrue();
48+
}
49+
50+
@Test
51+
@Tag("task:4")
52+
@DisplayName("The damagePoints method of the Wizard returns 3 when spell has not been prepared")
3453
public void testWizardsDamagePoints() {
3554
Wizard wizard = new Wizard();
3655
Warrior warrior = new Warrior();
3756
assertThat(wizard.damagePoints(warrior)).isEqualTo(3);
57+
}
58+
59+
@Test
60+
@Tag("task:4")
61+
@DisplayName("The damagePoints method of the Wizard returns 12 after a spell has been prepared")
62+
public void testWizardsDamagePointsAfterPreparingSpell() {
63+
Wizard wizard = new Wizard();
64+
Warrior warrior = new Warrior();
3865
wizard.prepareSpell();
3966
assertThat(wizard.damagePoints(warrior)).isEqualTo(12);
4067
}
4168

4269
@Test
43-
public void testWarriorsDamagePoints() {
70+
@Tag("task:5")
71+
@DisplayName("The damagePoints method of the Warrior returns 10 when target is vulnerable")
72+
public void testWarriorsDamagePointsWhenTargetVulnerable() {
4473
Warrior warrior = new Warrior();
4574
Wizard wizard = new Wizard();
4675
assertThat(warrior.damagePoints(wizard)).isEqualTo(10);
76+
}
77+
78+
@Test
79+
@Tag("task:5")
80+
@DisplayName("The damagePoints method of the Warrior returns 6 when target is not vulnerable")
81+
public void testWarriorsDamagePointsWhenTargetNotVulnerable() {
82+
Warrior warrior = new Warrior();
83+
Wizard wizard = new Wizard();
4784
wizard.prepareSpell();
4885
assertThat(warrior.damagePoints(wizard)).isEqualTo(6);
4986
}

0 commit comments

Comments
 (0)