BAEL-2184 formatting
This commit is contained in:
parent
7d64241f16
commit
3c0bd8e6e8
@ -45,8 +45,8 @@ public class Foo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Foo deepCopy() {
|
public Foo deepCopy() {
|
||||||
return new Foo(this.id, this.name,
|
return new Foo(
|
||||||
this.parent != null ? this.parent.deepCopy() : null);
|
this.id, this.name, this.parent != null ? this.parent.deepCopy() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,9 @@ public class FooUnitTest {
|
|||||||
srcCollection.add(sam);
|
srcCollection.add(sam);
|
||||||
srcCollection.add(alice);
|
srcCollection.add(alice);
|
||||||
srcCollection.add(buffy);
|
srcCollection.add(buffy);
|
||||||
|
|
||||||
|
// make sure the collection isn't sorted accidentally
|
||||||
|
assertFalse("Oops: source collection is already sorted!", isSorted(srcCollection));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,6 +53,7 @@ public class FooUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void whenUsingStream_thenVerifyShallowCopy() {
|
public void whenUsingStream_thenVerifyShallowCopy() {
|
||||||
ArrayList<Foo> newList = srcCollection.stream().collect(toCollection(ArrayList::new));
|
ArrayList<Foo> newList = srcCollection.stream().collect(toCollection(ArrayList::new));
|
||||||
|
|
||||||
verifyShallowCopy(srcCollection, newList);
|
verifyShallowCopy(srcCollection, newList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +65,7 @@ public class FooUnitTest {
|
|||||||
ArrayList<Foo> newList = srcCollection.stream()
|
ArrayList<Foo> newList = srcCollection.stream()
|
||||||
.map(foo -> foo.deepCopy())
|
.map(foo -> foo.deepCopy())
|
||||||
.collect(toCollection(ArrayList::new));
|
.collect(toCollection(ArrayList::new));
|
||||||
|
|
||||||
verifyDeepCopy(srcCollection, newList);
|
verifyDeepCopy(srcCollection, newList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,11 +74,11 @@ public class FooUnitTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingSortedStream_thenVerifySortOrder() {
|
public void whenUsingSortedStream_thenVerifySortOrder() {
|
||||||
assertFalse("Oops: source collection is already sorted!", isSorted(srcCollection));
|
|
||||||
ArrayList<Foo> newList = srcCollection.stream()
|
ArrayList<Foo> newList = srcCollection.stream()
|
||||||
.map(foo -> foo.deepCopy())
|
.map(foo -> foo.deepCopy())
|
||||||
.sorted(Comparator.comparing(Foo::getName))
|
.sorted(Comparator.comparing(Foo::getName))
|
||||||
.collect(toCollection(ArrayList::new));
|
.collect(toCollection(ArrayList::new));
|
||||||
|
|
||||||
assertTrue("ArrayList is not sorted by name", isSorted(newList));
|
assertTrue("ArrayList is not sorted by name", isSorted(newList));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +135,7 @@ public class FooUnitTest {
|
|||||||
* @param c collection of Foo
|
* @param c collection of Foo
|
||||||
* @return true if the collection is sorted by name
|
* @return true if the collection is sorted by name
|
||||||
*/
|
*/
|
||||||
private boolean isSorted(Collection<Foo> c) {
|
private static boolean isSorted(Collection<Foo> c) {
|
||||||
String prevName = null;
|
String prevName = null;
|
||||||
for (Foo foo : c) {
|
for (Foo foo : c) {
|
||||||
if (prevName == null || foo.getName().compareTo(prevName) > 0) {
|
if (prevName == null || foo.getName().compareTo(prevName) > 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user