Skip to content

Commit 7b72f07

Browse files
Issue #2971 display names (#3055)
* Added DisplayName to DnDCharacterTest * Added DisplayName to SimpleLinkedListTest * Added DisplayName to RobotTest * Added DisplayName to PokerTest * Added DisplayName to PiecingItTogetherTest * Added DisplayName to PhoneNumberTest * Added DisplayName to NaturalNumberTest * Added DisplayName to PascalsTriangleGeneratorTest * Added DisplayName to ParallelLetterFrequencyTest * Added DisplayName to MazeGeneratorTest * Added DisplayName to ErrorHandlingTest * Added DisplayName to BracketCheckerTest * Added DisplayName to HangmanTest * Added DisplayName to MarkdownTest * Changes done as per canonical-data.json * Add suggestion to ErrorHandlingTest * Add suggestion to HangmanTest * Add suggestion to MazeGeneratorTest * Add suggestion to ParallelLetterFrequencyTest * Add suggestion to RobotTest * Add suggestion to SimpleLinkedListTest * Changing orders of tests to keep similar tests together --------- Co-authored-by: Jagdish Prajapati <[email protected]> [no important files changed]
1 parent 8419c95 commit 7b72f07

File tree

14 files changed

+273
-52
lines changed

14 files changed

+273
-52
lines changed

exercises/practice/dnd-character/src/test/java/DnDCharacterTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.junit.jupiter.api.Disabled;
2+
import org.junit.jupiter.api.DisplayName;
23
import org.junit.jupiter.api.Test;
34

45
import java.util.List;
@@ -10,150 +11,175 @@ public class DnDCharacterTest {
1011
private DnDCharacter dndCharacter = new DnDCharacter();
1112

1213
@Test
14+
@DisplayName("ability modifier for score 3 is -4")
1315
public void testAbilityModifierForScore3IsNegative4() {
1416
assertThat(dndCharacter.modifier(3)).isEqualTo(-4);
1517
}
1618

1719
@Disabled("Remove to run test")
1820
@Test
21+
@DisplayName("ability modifier for score 4 is -3")
1922
public void testAbilityModifierForScore4IsNegative3() {
2023
assertThat(dndCharacter.modifier(4)).isEqualTo(-3);
2124
}
2225

2326
@Disabled("Remove to run test")
2427
@Test
28+
@DisplayName("ability modifier for score 5 is -3")
2529
public void testAbilityModifierForScore5IsNegative3() {
2630
assertThat(dndCharacter.modifier(5)).isEqualTo(-3);
2731
}
2832

2933
@Disabled("Remove to run test")
3034
@Test
35+
@DisplayName("ability modifier for score 6 is -2")
3136
public void testAbilityModifierForScore6IsNegative2() {
3237
assertThat(dndCharacter.modifier(6)).isEqualTo(-2);
3338
}
3439

3540
@Disabled("Remove to run test")
3641
@Test
42+
@DisplayName("ability modifier for score 7 is -2")
3743
public void testAbilityModifierForScore7IsNegative2() {
3844
assertThat(dndCharacter.modifier(7)).isEqualTo(-2);
3945
}
4046

4147
@Disabled("Remove to run test")
4248
@Test
49+
@DisplayName("ability modifier for score 8 is -1")
4350
public void testAbilityModifierForScore8IsNegative1() {
4451
assertThat(dndCharacter.modifier(8)).isEqualTo(-1);
4552
}
4653

4754
@Disabled("Remove to run test")
4855
@Test
56+
@DisplayName("ability modifier for score 9 is -1")
4957
public void testAbilityModifierForScore9IsNegative1() {
5058
assertThat(dndCharacter.modifier(9)).isEqualTo(-1);
5159
}
5260

5361
@Disabled("Remove to run test")
5462
@Test
63+
@DisplayName("ability modifier for score 10 is 0")
5564
public void testAbilityModifierForScore10Is0() {
5665
assertThat(dndCharacter.modifier(10)).isEqualTo(0);
5766
}
5867

5968
@Disabled("Remove to run test")
6069
@Test
70+
@DisplayName("ability modifier for score 11 is 0")
6171
public void testAbilityModifierForScore11Is0() {
6272
assertThat(dndCharacter.modifier(11)).isEqualTo(0);
6373
}
6474

6575
@Disabled("Remove to run test")
6676
@Test
77+
@DisplayName("ability modifier for score 12 is +1")
6778
public void testAbilityModifierForScore12Is1() {
6879
assertThat(dndCharacter.modifier(12)).isEqualTo(1);
6980
}
7081

7182
@Disabled("Remove to run test")
7283
@Test
84+
@DisplayName("ability modifier for score 13 is +1")
7385
public void testAbilityModifierForScore13Is1() {
7486
assertThat(dndCharacter.modifier(13)).isEqualTo(1);
7587
}
7688

7789
@Disabled("Remove to run test")
7890
@Test
91+
@DisplayName("ability modifier for score 14 is +2")
7992
public void testAbilityModifierForScore14Is2() {
8093
assertThat(dndCharacter.modifier(14)).isEqualTo(2);
8194
}
8295

8396
@Disabled("Remove to run test")
8497
@Test
98+
@DisplayName("ability modifier for score 15 is +2")
8599
public void testAbilityModifierForScore15Is2() {
86100
assertThat(dndCharacter.modifier(15)).isEqualTo(2);
87101
}
88102

89103
@Disabled("Remove to run test")
90104
@Test
105+
@DisplayName("ability modifier for score 16 is +3")
91106
public void testAbilityModifierForScore16Is3() {
92107
assertThat(dndCharacter.modifier(16)).isEqualTo(3);
93108
}
94109

95110
@Disabled("Remove to run test")
96111
@Test
112+
@DisplayName("ability modifier for score 17 is +3")
97113
public void testAbilityModifierForScore17Is3() {
98114
assertThat(dndCharacter.modifier(17)).isEqualTo(3);
99115
}
100116

101117
@Disabled("Remove to run test")
102118
@Test
119+
@DisplayName("ability modifier for score 18 is +4")
103120
public void testAbilityModifierForScore18Is4() {
104121
assertThat(dndCharacter.modifier(18)).isEqualTo(4);
105122
}
106123

107124
@Disabled("Remove to run test")
108125
@Test
126+
@DisplayName("Rolling uses 4 dice")
109127
public void test4DiceWereUsedForRollingScores() {
110128
assertThat(dndCharacter.rollDice().size()).isEqualTo(4);
111129
}
112130

113131
@Disabled("Remove to run test")
114132
@Test
133+
@DisplayName("Dice values are between 1 and 6 inclusive")
115134
public void testDiceValuesBetween1And6() {
116135
assertThat(dndCharacter.rollDice()).allMatch(d -> d >= 1 && d <= 6);
117136
}
118137

119138
@Disabled("Remove to run test")
120139
@Test
140+
@DisplayName("Ability uses 3 largest numbers from scores in descending order")
121141
public void testAbilityCalculationsUses3LargestNumbersFromScoresInDescendingOrder() {
122142
assertThat(dndCharacter.ability(List.of(4, 3, 2, 1))).isEqualTo(9);
123143
}
124144

125145
@Disabled("Remove to run test")
126146
@Test
147+
@DisplayName("Ability uses 3 largest numbers from scores in ascending order")
127148
public void testAbilityCalculationsUses3LargestNumbersFromFromScoresInAscendingOrder() {
128149
assertThat(dndCharacter.ability(List.of(1, 2, 3, 4))).isEqualTo(9);
129150
}
130151

131152
@Disabled("Remove to run test")
132153
@Test
154+
@DisplayName("Ability uses 3 largest numbers from scores in random order")
133155
public void testAbilityCalculationsUses3LargestNumbersFromScoresInRandomOrder() {
134156
assertThat(dndCharacter.ability(List.of(2, 4, 3, 1))).isEqualTo(9);
135157
}
136158

137159
@Disabled("Remove to run test")
138160
@Test
161+
@DisplayName("Ability with all lowest equal numbers yields 3")
139162
public void testAbilityCalculationsWithLowestEqualNumbers() {
140163
assertThat(dndCharacter.ability(List.of(1, 1, 1, 1))).isEqualTo(3);
141164
}
142165

143166
@Disabled("Remove to run test")
144167
@Test
168+
@DisplayName("Ability with all highest equal numbers yields 18")
145169
public void testAbilityCalculationsWithHighestEqualNumbers() {
146170
assertThat(dndCharacter.ability(List.of(6, 6, 6, 6))).isEqualTo(18);
147171
}
148172

149173
@Disabled("Remove to run test")
150174
@Test
175+
@DisplayName("Ability calculation with two lowest numbers")
151176
public void testAbilityCalculationsWithTwoLowestNumbers() {
152177
assertThat(dndCharacter.ability(List.of(3, 5, 3, 4))).isEqualTo(12);
153178
}
154179

155180
@Disabled("Remove to run test")
156181
@Test
182+
@DisplayName("Ability calculation does not mutate input scores")
157183
public void testAbilityCalculationDoesNotChangeInputScores() {
158184
List<Integer> scores = List.of(1, 2, 3, 4);
159185
dndCharacter.ability(scores);
@@ -164,6 +190,7 @@ public void testAbilityCalculationDoesNotChangeInputScores() {
164190

165191
@Disabled("Remove to run test")
166192
@Test
193+
@DisplayName("random character is valid")
167194
public void testRandomCharacterIsValid() {
168195
for (int i = 0; i < 1000; i++) {
169196
DnDCharacter character = new DnDCharacter();
@@ -179,6 +206,7 @@ public void testRandomCharacterIsValid() {
179206

180207
@Disabled("Remove to run test")
181208
@Test
209+
@DisplayName("each ability is only calculated once")
182210
public void testEachAbilityIsOnlyCalculatedOnce() {
183211
assertThat(dndCharacter.getStrength()).isEqualTo(dndCharacter.getStrength());
184212
assertThat(dndCharacter.getDexterity()).isEqualTo(dndCharacter.getDexterity());
@@ -190,6 +218,7 @@ public void testEachAbilityIsOnlyCalculatedOnce() {
190218

191219
@Disabled("Remove to run test")
192220
@Test
221+
@DisplayName("Each randomly created character should be unique in attributes")
193222
public void testUniqueCharacterIsCreated() {
194223
DnDCharacter uniqueDnDCharacter = new DnDCharacter();
195224
for (int i = 0; i < 1000; i++) {

exercises/practice/error-handling/src/test/java/ErrorHandlingTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
import static org.assertj.core.api.Assertions.assertThat;
2-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3-
41
import org.junit.jupiter.api.Disabled;
2+
import org.junit.jupiter.api.DisplayName;
53
import org.junit.jupiter.api.Test;
64

75
import java.util.Optional;
86

7+
import static org.assertj.core.api.Assertions.assertThat;
8+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
9+
910
public class ErrorHandlingTest {
1011

1112
private ErrorHandling errorHandling = new ErrorHandling();
1213

1314
@Test
15+
@DisplayName("Throws IllegalArgumentException")
1416
public void testThrowIllegalArgumentException() {
1517
assertThatExceptionOfType(Exception.class)
1618
.isThrownBy(() -> errorHandling.handleErrorByThrowingIllegalArgumentException());
1719
}
1820

1921
@Disabled("Remove to run test")
2022
@Test
23+
@DisplayName("Throws IllegalArgumentException with provided detail message")
2124
public void testThrowIllegalArgumentExceptionWithDetailMessage() {
2225
assertThatExceptionOfType(IllegalArgumentException.class)
2326
.isThrownBy(() -> errorHandling.handleErrorByThrowingIllegalArgumentExceptionWithDetailMessage(
@@ -27,6 +30,7 @@ public void testThrowIllegalArgumentExceptionWithDetailMessage() {
2730

2831
@Disabled("Remove to run test")
2932
@Test
33+
@DisplayName("Throws any checked exception")
3034
public void testThrowAnyCheckedException() {
3135
assertThatExceptionOfType(Exception.class)
3236
.isThrownBy(() -> errorHandling.handleErrorByThrowingAnyCheckedException())
@@ -35,6 +39,7 @@ public void testThrowAnyCheckedException() {
3539

3640
@Disabled("Remove to run test")
3741
@Test
42+
@DisplayName("Throws any checked exception with provided detail message")
3843
public void testThrowAnyCheckedExceptionWithDetailMessage() {
3944
assertThatExceptionOfType(Exception.class)
4045
.isThrownBy(() -> errorHandling.handleErrorByThrowingAnyCheckedExceptionWithDetailMessage(
@@ -45,13 +50,15 @@ public void testThrowAnyCheckedExceptionWithDetailMessage() {
4550

4651
@Disabled("Remove to run test")
4752
@Test
53+
@DisplayName("Throws any unchecked exception")
4854
public void testThrowAnyUncheckedException() {
4955
assertThatExceptionOfType(RuntimeException.class)
5056
.isThrownBy(() -> errorHandling.handleErrorByThrowingAnyUncheckedException());
5157
}
5258

5359
@Disabled("Remove to run test")
5460
@Test
61+
@DisplayName("Throws any unchecked exception with provided detail message")
5562
public void testThrowAnyUncheckedExceptionWithDetailMessage() {
5663
assertThatExceptionOfType(RuntimeException.class)
5764
.isThrownBy(() -> errorHandling.handleErrorByThrowingAnyUncheckedExceptionWithDetailMessage(
@@ -61,13 +68,15 @@ public void testThrowAnyUncheckedExceptionWithDetailMessage() {
6168

6269
@Disabled("Remove to run test")
6370
@Test
71+
@DisplayName("Throws custom checked exception")
6472
public void testThrowCustomCheckedException() {
6573
assertThatExceptionOfType(CustomCheckedException.class)
6674
.isThrownBy(() -> errorHandling.handleErrorByThrowingCustomCheckedException());
6775
}
6876

6977
@Disabled("Remove to run test")
7078
@Test
79+
@DisplayName("Throws custom checked exception with provided detail message")
7180
public void testThrowCustomCheckedExceptionWithDetailMessage() {
7281
assertThatExceptionOfType(CustomCheckedException.class)
7382
.isThrownBy(() -> errorHandling.handleErrorByThrowingCustomCheckedExceptionWithDetailMessage(
@@ -77,13 +86,15 @@ public void testThrowCustomCheckedExceptionWithDetailMessage() {
7786

7887
@Disabled("Remove to run test")
7988
@Test
89+
@DisplayName("Throws custom unchecked exception")
8090
public void testThrowCustomUncheckedException() {
8191
assertThatExceptionOfType(CustomUncheckedException.class)
8292
.isThrownBy(() -> errorHandling.handleErrorByThrowingCustomUncheckedException());
8393
}
8494

8595
@Disabled("Remove to run test")
8696
@Test
97+
@DisplayName("Throws custom unchecked exception with provided detail message")
8798
public void testThrowCustomUncheckedExceptionWithDetailMessage() {
8899
assertThatExceptionOfType(CustomUncheckedException.class)
89100
.isThrownBy(() -> errorHandling.handleErrorByThrowingCustomUncheckedExceptionWithDetailMessage(
@@ -93,6 +104,7 @@ public void testThrowCustomUncheckedExceptionWithDetailMessage() {
93104

94105
@Disabled("Remove to run test")
95106
@Test
107+
@DisplayName("Handles error by throwing Optional instance")
96108
public void testReturnOptionalInstance() {
97109
Optional<Integer> successfulResult = errorHandling.handleErrorByReturningOptionalInstance("1");
98110
assertThat(successfulResult).isPresent().hasValue(1);

exercises/practice/hangman/src/test/java/HangmanTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import io.reactivex.Observable;
22
import io.reactivex.ObservableEmitter;
33
import io.reactivex.disposables.Disposable;
4+
45
import org.junit.jupiter.api.BeforeEach;
56
import org.junit.jupiter.api.Disabled;
7+
import org.junit.jupiter.api.DisplayName;
68
import org.junit.jupiter.api.Test;
79

810
import java.util.ArrayList;
@@ -22,6 +24,7 @@ public void init() {
2224
}
2325

2426
@Test
27+
@DisplayName("Initial game state is set correctly")
2528
public void initialization() {
2629
Observable<Output> result = hangman.play(
2730
Observable.fromArray("secret"),
@@ -39,6 +42,7 @@ public void initialization() {
3942

4043
@Disabled("Remove to run test")
4144
@Test
45+
@DisplayName("First correct guess updates discovered and guess lists")
4246
public void firstGuess() {
4347
Observable<Output> result = hangman.play(
4448
Observable.fromArray("secret"),
@@ -54,6 +58,7 @@ public void firstGuess() {
5458

5559
@Disabled("Remove to run test")
5660
@Test
61+
@DisplayName("First incorrect guess registers a miss and adds a part")
5762
public void firstMiss() {
5863
Observable<Output> result = hangman.play(
5964
Observable.fromArray("secret"),
@@ -69,6 +74,7 @@ public void firstMiss() {
6974

7075
@Disabled("Remove to run test")
7176
@Test
77+
@DisplayName("Game in progress accumulates guesses, misses and parts correctly")
7278
public void gameInProgress() {
7379
Observable<Output> result = hangman.play(
7480
Observable.fromArray("secret"),
@@ -84,6 +90,7 @@ public void gameInProgress() {
8490

8591
@Disabled("Remove to run test")
8692
@Test
93+
@DisplayName("Winning the game results in WIN status")
8794
public void wonGame() {
8895
Observable<Output> result = hangman.play(
8996
Observable.fromArray("secret"),
@@ -97,6 +104,7 @@ public void wonGame() {
97104

98105
@Disabled("Remove to run test")
99106
@Test
107+
@DisplayName("Losing the game results in LOSS status")
100108
public void lostGame() {
101109
Observable<Output> result = hangman.play(
102110
Observable.fromArray("secret"),
@@ -118,6 +126,7 @@ public void lostGame() {
118126

119127
@Disabled("Remove to run test")
120128
@Test
129+
@DisplayName("Handles consecutive games correctly with ordered emissions")
121130
public void consecutiveGames() {
122131
// This test setup is more complex because we have to order the emission of values in the
123132
// different observers.
@@ -189,6 +198,7 @@ Observable createLetterObservable(ObservableEmitter[] emitters, Runnable emit) {
189198

190199
@Disabled("Remove to run test")
191200
@Test
201+
@DisplayName("Cannot play the same guess twice")
192202
public void cannotPlayAGuessTwice() {
193203
Observable<Output> result = hangman.play(
194204
Observable.fromArray("secret"),
@@ -201,6 +211,7 @@ public void cannotPlayAGuessTwice() {
201211

202212
@Disabled("Remove to run test")
203213
@Test
214+
@DisplayName("Cannot play the same miss twice")
204215
public void cannotPlayAMissTwice() {
205216
Observable<Output> result = hangman.play(
206217
Observable.fromArray("secret"),

0 commit comments

Comments
 (0)