|
16 | 16 | */ |
17 | 17 | public class CollectorsUnitTest { |
18 | 18 |
|
19 | | - @Test |
20 | | - public void whenTeeing_ItShouldCombineTheResultsAsExpected() { |
21 | | - List<Integer> numbers = Arrays.asList(42, 4, 2, 24); |
22 | | - Range range = numbers.stream() |
23 | | - .collect(teeing( |
24 | | - minBy(Integer::compareTo), |
25 | | - maxBy(Integer::compareTo), |
26 | | - (min, max) -> new Range(min.orElse(null), max.orElse(null)) |
27 | | - )); |
| 19 | + @Test |
| 20 | + public void whenTeeing_ItShouldCombineTheResultsAsExpected() { |
| 21 | + List<Integer> numbers = Arrays.asList(42, 4, 2, 24); |
| 22 | + Range range = numbers.stream() |
| 23 | + .collect(teeing(minBy(Integer::compareTo), maxBy(Integer::compareTo), (min, max) -> new Range(min.orElse(null), max.orElse(null)))); |
28 | 24 |
|
29 | | - assertThat(range).isEqualTo(new Range(2, 42)); |
30 | | - } |
| 25 | + assertThat(range).isEqualTo(new Range(2, 42)); |
| 26 | + } |
31 | 27 |
|
32 | | - /** |
33 | | - * Represents a closed range of numbers between {@link #min} and |
34 | | - * {@link #max}, both inclusive. |
35 | | - */ |
36 | | - private static class Range { |
| 28 | + /** |
| 29 | + * Represents a closed range of numbers between {@link #min} and |
| 30 | + * {@link #max}, both inclusive. |
| 31 | + */ |
| 32 | + private static class Range { |
37 | 33 |
|
38 | | - private final Integer min; |
| 34 | + private final Integer min; |
39 | 35 |
|
40 | | - private final Integer max; |
| 36 | + private final Integer max; |
41 | 37 |
|
42 | | - Range(Integer min, Integer max) { |
43 | | - this.min = min; |
44 | | - this.max = max; |
45 | | - } |
| 38 | + Range(Integer min, Integer max) { |
| 39 | + this.min = min; |
| 40 | + this.max = max; |
| 41 | + } |
46 | 42 |
|
47 | | - Integer getMin() { |
48 | | - return min; |
49 | | - } |
| 43 | + Integer getMin() { |
| 44 | + return min; |
| 45 | + } |
50 | 46 |
|
51 | | - Integer getMax() { |
52 | | - return max; |
53 | | - } |
| 47 | + Integer getMax() { |
| 48 | + return max; |
| 49 | + } |
54 | 50 |
|
55 | | - @Override |
56 | | - public boolean equals(Object o) { |
57 | | - if (this == o) return true; |
58 | | - if (o == null || getClass() != o.getClass()) return false; |
59 | | - Range range = (Range) o; |
60 | | - return Objects.equals(getMin(), range.getMin()) && |
61 | | - Objects.equals(getMax(), range.getMax()); |
62 | | - } |
| 51 | + @Override |
| 52 | + public boolean equals(Object o) { |
| 53 | + if (this == o) |
| 54 | + return true; |
| 55 | + if (o == null || getClass() != o.getClass()) |
| 56 | + return false; |
| 57 | + Range range = (Range) o; |
| 58 | + return Objects.equals(getMin(), range.getMin()) && Objects.equals(getMax(), range.getMax()); |
| 59 | + } |
63 | 60 |
|
64 | | - @Override |
65 | | - public int hashCode() { |
66 | | - return Objects.hash(getMin(), getMax()); |
67 | | - } |
| 61 | + @Override |
| 62 | + public int hashCode() { |
| 63 | + return Objects.hash(getMin(), getMax()); |
| 64 | + } |
68 | 65 |
|
69 | | - @Override |
70 | | - public String toString() { |
71 | | - return "Range{" + |
72 | | - "min=" + min + |
73 | | - ", max=" + max + |
74 | | - '}'; |
75 | | - } |
76 | | - } |
| 66 | + @Override |
| 67 | + public String toString() { |
| 68 | + return "Range{" + "min=" + min + ", max=" + max + '}'; |
| 69 | + } |
| 70 | + } |
77 | 71 | } |
0 commit comments