Skip to content

Commit 0be2bec

Browse files
committed
메서드 이름 변경 및 소스 코드 재정리
1 parent 4c02766 commit 0be2bec

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

java8/src/test/java/com/advenoh/streams/ConvertListToMapTest.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,51 @@
1717
public class ConvertListToMapTest {
1818

1919
@Test
20-
public void convert_students_to_map1() {
20+
public void convert_students_to_map_of_nameVsAge() {
2121
int max = 3;
2222
List<Student> students = TestUtil.getStudentSample(max);
2323

24-
Map<String, Integer> nameVsAgeMap1 = students
24+
Map<String, Integer> nameVsAgeMap = students
2525
.stream()
2626
.collect(Collectors.toMap(
2727
i1 -> i1.getName(),
2828
i2 -> i2.getAge())
2929
);
3030

31-
assertThat(nameVsAgeMap1.size()).isEqualTo(max);
32-
log.info("nameVsAgeMap1 : {}", nameVsAgeMap1);
31+
assertThat(nameVsAgeMap.size()).isEqualTo(max);
32+
log.info("nameVsAgeMap : {}", nameVsAgeMap);
33+
}
34+
35+
@Test
36+
public void convert_students_to_map_of_nameVsAge_method_reference() {
37+
int max = 3;
38+
List<Student> students = TestUtil.getStudentSample(max);
3339

3440
//method reference
35-
Map<String, Integer> nameVsAgeMap2 = students
41+
Map<String, Integer> nameVsAgeMap = students
3642
.stream()
3743
.collect(Collectors.toMap(
3844
Student::getName,
3945
Student::getAge)
4046
);
4147

42-
assertThat(nameVsAgeMap2.size()).isEqualTo(max);
43-
48+
assertThat(nameVsAgeMap.size()).isEqualTo(max);
4449
}
4550

4651
@Test
47-
public void convert_students_to_map2() {
52+
public void convert_students_to_map_of_idVsStudent() {
4853
int max = 3;
4954
List<Student> students = TestUtil.getStudentSample(max);
5055

51-
Map<Integer, Student> nameVsAgeMap1 = IntStream.range(0, max).boxed()
56+
Map<Integer, Student> idVsStudentMap = IntStream.range(0, max).boxed()
5257
.collect(Collectors.toMap(
5358
i1 -> i1 + 1,
5459
i2 -> students.get(i2)
5560
));
5661

57-
nameVsAgeMap1.forEach((it, it2) -> log.info("{}", it));
62+
idVsStudentMap.forEach((it, it2) -> log.info("{}", it));
5863

59-
assertThat(nameVsAgeMap1.size()).isEqualTo(max);
64+
assertThat(idVsStudentMap.size()).isEqualTo(max);
6065

6166
}
6267

0 commit comments

Comments
 (0)