Skip to content

Commit c1787cc

Browse files
author
Nguyen Nam Thai
committed
Change the test method names
1 parent 08d53a2 commit c1787cc

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

‎core-java/src/test/java/com/baeldung/java/list/CustomListUnitTest.java‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ public void whenRetainAll_thenExceptionIsThrown() {
6565
}
6666

6767
@Test
68-
public void whenSize_thenNumberOfElementsIsReturned() {
68+
public void givenEmptyList_whenSize_thenZeroIsReturned() {
6969
List<Object> list = new CustomList<>();
7070

7171
assertEquals(0, list.size());
7272
}
7373

7474
@Test
75-
public void whenIsEmpty_thenWhetherListIsEmptyIsReturned() {
75+
public void givenEmptyList_whenIsEmpty_thenTrueIsReturned() {
7676
List<Object> list = new CustomList<>();
7777

7878
assertTrue(list.isEmpty());
7979
}
8080

8181
@Test
82-
public void whenAddToTheEndAndGet_thenAddedElementIsReturned() {
82+
public void givenEmptyList_whenElementIsAdded_thenGetReturnsThatElement() {
8383
List<Object> list = new CustomList<>();
8484
boolean succeeded = list.add("baeldung");
8585
Object element = list.get(0);
@@ -89,7 +89,7 @@ public void whenAddToTheEndAndGet_thenAddedElementIsReturned() {
8989
}
9090

9191
@Test
92-
public void whenAddToTheEndAndGet_thenAddedElemenetsAreReturned() {
92+
public void givenListWithAnElement_whenAnotherIsAdded_thenGetReturnsBoth() {
9393
List<Object> list = new CustomList<>();
9494
boolean succeeded1 = list.add("baeldung");
9595
boolean succeeded2 = list.add(".com");
@@ -103,22 +103,22 @@ public void whenAddToTheEndAndGet_thenAddedElemenetsAreReturned() {
103103
}
104104

105105
@Test
106-
public void whenContains_thenFalseIsReturned() {
106+
public void givenEmptyList_whenContains_thenFalseIsReturned() {
107107
List<Object> list = new CustomList<>();
108108

109-
assertFalse(list.contains("baeldung"));
109+
assertFalse(list.contains(null));
110110
}
111111

112112
@Test
113-
public void whenContains_thenTrueIsReturned() {
113+
public void givenListWithAnElement_whenContains_thenTrueIsReturned() {
114114
List<Object> list = new CustomList<>();
115115
list.add("baeldung");
116116

117117
assertTrue(list.contains("baeldung"));
118118
}
119119

120120
@Test
121-
public void whenContainsAll_thenTrueIsReturned() {
121+
public void givenListWithAnElement_whenContainsAll_thenTrueIsReturned() {
122122
Collection<Object> collection = new ArrayList<>();
123123
collection.add("baeldung");
124124
List<Object> list = new CustomList<>();
@@ -128,7 +128,7 @@ public void whenContainsAll_thenTrueIsReturned() {
128128
}
129129

130130
@Test
131-
public void whenContainsAll_thenEitherTrueOfFalseIsReturned() {
131+
public void givenList_whenContainsAll_thenEitherTrueOrFalseIsReturned() {
132132
Collection<Object> collection1 = new ArrayList<>();
133133
collection1.add("baeldung");
134134
collection1.add(".com");
@@ -143,7 +143,7 @@ public void whenContainsAll_thenEitherTrueOfFalseIsReturned() {
143143
}
144144

145145
@Test
146-
public void whenSet_thenOldElementIsReturned() {
146+
public void givenList_whenSet_thenOldElementIsReturned() {
147147
List<Object> list = new CustomList<>();
148148
list.add("baeldung");
149149
Object element = list.set(0, null);
@@ -153,7 +153,7 @@ public void whenSet_thenOldElementIsReturned() {
153153
}
154154

155155
@Test
156-
public void whenClear_thenAllElementsAreRemoved() {
156+
public void givenList_whenClear_thenAllElementsAreRemoved() {
157157
List<Object> list = new CustomList<>();
158158
list.add("baeldung");
159159
list.clear();
@@ -162,15 +162,15 @@ public void whenClear_thenAllElementsAreRemoved() {
162162
}
163163

164164
@Test
165-
public void whenIndexOf_thenIndexZeroIsReturned() {
165+
public void givenList_whenIndexOf_thenIndexZeroIsReturned() {
166166
List<Object> list = new CustomList<>();
167167
list.add("baeldung");
168168

169169
assertEquals(0, list.indexOf("baeldung"));
170170
}
171171

172172
@Test
173-
public void whenIndexOf_thenPositiveOrNegativeIndexIsReturned() {
173+
public void givenList_whenIndexOf_thenPositiveIndexOrMinusOneIsReturned() {
174174
List<Object> list = new CustomList<>();
175175
list.add("baeldung");
176176
list.add(".com");
@@ -189,7 +189,7 @@ public void whenLastIndexOf_thenIndexZeroIsReturned() {
189189
}
190190

191191
@Test
192-
public void whenLastIndexOf_thenPositiveOrNegativeIndexIsReturned() {
192+
public void whenLastIndexOf_thenPositiveIndexOrMinusOneIsReturned() {
193193
List<Object> list = new CustomList<>();
194194
list.add("baeldung");
195195
list.add("baeldung");
@@ -200,7 +200,7 @@ public void whenLastIndexOf_thenPositiveOrNegativeIndexIsReturned() {
200200
}
201201

202202
@Test
203-
public void whenSubList_thenListContainingFirstElementIsReturned() {
203+
public void whenSubListZeroToOne_thenListContainingFirstElementIsReturned() {
204204
List<Object> list = new CustomList<>();
205205
list.add("baeldung");
206206
List<Object> subList = list.subList(0, 1);
@@ -209,7 +209,7 @@ public void whenSubList_thenListContainingFirstElementIsReturned() {
209209
}
210210

211211
@Test
212-
public void whenSubList_thenListContainingSecondElementIsReturned() {
212+
public void whenSubListOneToTwo_thenListContainingSecondElementIsReturned() {
213213
List<Object> list = new CustomList<>();
214214
list.add("baeldung");
215215
list.add(".");
@@ -221,16 +221,17 @@ public void whenSubList_thenListContainingSecondElementIsReturned() {
221221
}
222222

223223
@Test
224-
public void whenToNewArray_thenArrayIsReturned() {
224+
public void givenListWithElements_whenToArray_thenArrayContainsThose() {
225225
List<Object> list = new CustomList<>();
226226
list.add("baeldung");
227+
list.add(".com");
227228
Object[] array = list.toArray();
228229

229-
assertEquals("baeldung", array[0]);
230+
assertArrayEquals(new Object[] { "baeldung", ".com" }, array);
230231
}
231232

232233
@Test
233-
public void whenToArray_thenOldArrayIsReturned() {
234+
public void givenListWithAnElement_whenToArray_thenInputArrayIsReturned() {
234235
List<Object> list = new CustomList<>();
235236
list.add("baeldung");
236237
String[] input = new String[1];
@@ -240,7 +241,7 @@ public void whenToArray_thenOldArrayIsReturned() {
240241
}
241242

242243
@Test
243-
public void whenToArray_thenNewArrayIsReturned() {
244+
public void whenToArrayIsCalledWithEmptyInputArray_thenNewArrayIsReturned() {
244245
List<Object> list = new CustomList<>();
245246
list.add("baeldung");
246247
String[] input = {};
@@ -250,7 +251,7 @@ public void whenToArray_thenNewArrayIsReturned() {
250251
}
251252

252253
@Test
253-
public void whenToArray_thenNewArrayWithTrailingNullIsReturned() {
254+
public void whenToArrayIsCalledWithLargerInput_thenOutputHasTrailingNull() {
254255
List<Object> list = new CustomList<>();
255256
list.add("baeldung");
256257
String[] input = new String[2];
@@ -260,7 +261,7 @@ public void whenToArray_thenNewArrayWithTrailingNullIsReturned() {
260261
}
261262

262263
@Test
263-
public void whenIterator_thenOneCheckIsCorrect() {
264+
public void givenListWithOneElement_whenIterator_thenThisElementIsNext() {
264265
List<Object> list = new CustomList<>();
265266
list.add("baeldung");
266267
Iterator<Object> iterator = list.iterator();
@@ -270,13 +271,12 @@ public void whenIterator_thenOneCheckIsCorrect() {
270271
}
271272

272273
@Test
273-
public void whenIterator_thenTwoChecksAreCorrect() {
274+
public void whenIteratorNextIsCalledTwice_thenTheSecondReturnsFalse() {
274275
List<Object> list = new CustomList<>();
275276
list.add("baeldung");
276277
Iterator<Object> iterator = list.iterator();
277278

278279
assertTrue(iterator.hasNext());
279-
assertEquals("baeldung", iterator.next());
280280
assertFalse(iterator.hasNext());
281281
}
282282
}

0 commit comments

Comments
 (0)