1010
1111public class CountedListTest {
1212 private CountedList list ;
13+ @ BeforeAll
14+ static void beforeAllMsg () {
15+ System .out .println (">>> Starting CountedListTest" );
16+ }
17+ @ AfterAll
18+ static void afterAllMsg () {
19+ System .out .println (">>> Finished CountedListTest" );
20+ }
1321 @ BeforeEach
1422 public void initialize () {
1523 list = new CountedList ();
@@ -21,7 +29,6 @@ public void initialize() {
2129 public void cleanup () {
2230 System .out .println ("Cleaning up " + list .getId ());
2331 }
24- // All tests are marked with the @Test annotation:
2532 @ Test
2633 public void insert () {
2734 System .out .println ("Running testInsert()" );
@@ -38,16 +45,12 @@ public void replace() {
3845 assertEquals (list .size (), 3 );
3946 assertEquals (list .get (1 ), "Replace" );
4047 }
41- // A helper method to reduce code duplication . As long
42- // as it isn't annotated with @Test, it will not
43- // be automatically executed by JUnit.
48+ // A helper method to simplify the code . As
49+ // long as it isn't annotated with @Test, it will
50+ // not be automatically executed by JUnit.
4451 private
4552 void compare (List <String > lst , String [] strs ) {
46- String [] array = lst .toArray (new String [0 ]);
47- assertTrue (array .length == strs .length ,
48- "Arrays not the same length" );
49- for (int i = 0 ; i < array .length ; i ++)
50- assertEquals (strs [i ], array [i ]);
53+ assertArrayEquals (lst .toArray (new String [0 ]), strs );
5154 }
5255 @ Test
5356 public void order () {
@@ -72,15 +75,3 @@ public void addAll() {
7275 "An" , "African" , "Swallow" });
7376 }
7477}
75- /* Output:
76- CountedList #0
77- Running testAddAll()
78- CountedList #1
79- Running testInsert()
80- CountedList #2
81- Running testRemove()
82- CountedList #3
83- Running testOrder()
84- CountedList #4
85- Running testReplace()
86- */
0 commit comments