Skip to content

Commit 61504c9

Browse files
alv21pivovarit
authored andcommitted
Bael 1585 (eugenp#3750)
* Different Types of Bean Injection in Spring * BAEL-1585 * Revert "Different Types of Bean Injection in Spring" This reverts commit ae47827. * Revert "BAEL-1585" This reverts commit e792f17. * BAEL-1585 * rev1
1 parent 64e9b41 commit 61504c9

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baeldung.java_8_features;
2+
3+
public class Car {
4+
5+
private String model;
6+
private int topSpeed;
7+
8+
public Car(String model, int topSpeed) {
9+
super();
10+
this.model = model;
11+
this.topSpeed = topSpeed;
12+
}
13+
14+
public String getModel() {
15+
return model;
16+
}
17+
18+
public void setModel(String model) {
19+
this.model = model;
20+
}
21+
22+
public int getTopSpeed() {
23+
return topSpeed;
24+
}
25+
26+
public void setTopSpeed(int topSpeed) {
27+
this.topSpeed = topSpeed;
28+
}
29+
30+
31+
}

‎core-java-8/src/test/java/com/baeldung/java8/Java8MaxMinUnitTest.java‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.baeldung.java8;
22

3+
import com.baeldung.java_8_features.Car;
34
import com.baeldung.java_8_features.Person;
5+
46
import org.junit.Test;
57

68
import java.util.Arrays;
@@ -44,4 +46,29 @@ public void whenListIsOfPersonObjectThenMinCanBeDoneUsingCustomComparatorThrough
4446
assertEquals("Should be Alex", alex, minByAge);
4547
}
4648

49+
@Test
50+
public void whenArrayIsOfIntegerThenMinUsesIntegerComparator() {
51+
int[] integers = new int[] { 20, 98, 12, 7, 35 };
52+
53+
int min = Arrays.stream(integers)
54+
.min()
55+
.getAsInt();
56+
57+
assertEquals(7, min);
58+
}
59+
60+
@Test
61+
public void whenArrayIsOfCustomTypeThenMaxUsesCustomComparator() {
62+
final Car porsche = new Car("Porsche 959", 319);
63+
final Car ferrari = new Car("Ferrari 288 GTO", 303);
64+
final Car bugatti = new Car("Bugatti Veyron 16.4 Super Sport", 415);
65+
final Car mcLaren = new Car("McLaren F1", 355);
66+
final Car[] fastCars = { porsche, ferrari, bugatti, mcLaren };
67+
68+
final Car maxBySpeed = Arrays.stream(fastCars)
69+
.max(Comparator.comparing(Car::getTopSpeed))
70+
.orElseThrow(NoSuchElementException::new);
71+
72+
assertEquals(bugatti, maxBySpeed);
73+
}
4774
}

0 commit comments

Comments
 (0)