Skip to content

Commit 3c0bd8e

Browse files
author
clininger
committed
BAEL-2184 formatting
1 parent 7d64241 commit 3c0bd8e

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

  • core-java-collections/src
    • main/java/com/baeldung/convertcollectiontoarraylist
    • test/java/com/baeldung/convertcollectiontoarraylist

‎core-java-collections/src/main/java/com/baeldung/convertcollectiontoarraylist/Foo.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public void setParent(Foo parent) {
4545
}
4646

4747
public Foo deepCopy() {
48-
return new Foo(this.id, this.name,
49-
this.parent != null ? this.parent.deepCopy() : null);
48+
return new Foo(
49+
this.id, this.name, this.parent != null ? this.parent.deepCopy() : null);
5050
}
5151

5252
}

‎core-java-collections/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)