@@ -33,6 +33,9 @@ public static void setUpClass() {
3333 srcCollection .add (sam );
3434 srcCollection .add (alice );
3535 srcCollection .add (buffy );
36+
37+ // make sure the collection isn't sorted accidentally
38+ assertFalse ("Oops: source collection is already sorted!" , isSorted (srcCollection ));
3639 }
3740
3841 /**
@@ -50,6 +53,7 @@ public void whenUsingConstructor_thenVerifyShallowCopy() {
5053 @ Test
5154 public void whenUsingStream_thenVerifyShallowCopy () {
5255 ArrayList <Foo > newList = srcCollection .stream ().collect (toCollection (ArrayList ::new ));
56+
5357 verifyShallowCopy (srcCollection , newList );
5458 }
5559
@@ -61,6 +65,7 @@ public void whenUsingDeepCopy_thenVerifyDeepCopy() {
6165 ArrayList <Foo > newList = srcCollection .stream ()
6266 .map (foo -> foo .deepCopy ())
6367 .collect (toCollection (ArrayList ::new ));
68+
6469 verifyDeepCopy (srcCollection , newList );
6570 }
6671
@@ -69,11 +74,11 @@ public void whenUsingDeepCopy_thenVerifyDeepCopy() {
6974 */
7075 @ Test
7176 public void whenUsingSortedStream_thenVerifySortOrder () {
72- assertFalse ("Oops: source collection is already sorted!" , isSorted (srcCollection ));
7377 ArrayList <Foo > newList = srcCollection .stream ()
7478 .map (foo -> foo .deepCopy ())
7579 .sorted (Comparator .comparing (Foo ::getName ))
7680 .collect (toCollection (ArrayList ::new ));
81+
7782 assertTrue ("ArrayList is not sorted by name" , isSorted (newList ));
7883 }
7984
@@ -130,7 +135,7 @@ private boolean fooDiff(Foo a, Foo b) {
130135 * @param c collection of Foo
131136 * @return true if the collection is sorted by name
132137 */
133- private boolean isSorted (Collection <Foo > c ) {
138+ private static boolean isSorted (Collection <Foo > c ) {
134139 String prevName = null ;
135140 for (Foo foo : c ) {
136141 if (prevName == null || foo .getName ().compareTo (prevName ) > 0 ) {
0 commit comments