람다 표현식을 별도의 메서드로 추출 후 인수로 전달,
도메인 클래스에 메서드로 작성을 통해 메서드 참조로 변환 가능하다
연습 많이 해라
킹론적으로 반복자를 이용한 컬렉션 처리 코드를 스트림으로 바꿔야한다
어려움
제대로 작동하는 코드를 구현하기 위함
assertj를 이용한 테스트 코드
class DebuggingTest {
@Test
void testMoveAllPointsRightBy() throws Exception {
//given
List<Point> points = Arrays.asList(new Point(5, 5), new Point(10, 5));
List<Point> expectedPoints = Arrays.asList(new Point(15, 5), new Point(20, 5));
//when
List<Point> newPoints = Point.moveAllPointsRightBy(points, 10);
//then
assertThat(newPoints).usingRecursiveComparison().isEqualTo(expectedPoints);
}
}
public class UsingRecursiveComparison {
public static void main(String[] args) {
Person sherlock = new Person("Sherlock", 1.80);
sherlock.home.ownedSince = new Date(123);
sherlock.home.address.street = "Baker Street";
sherlock.home.address.number = 221;
Person sherlock2 = new Person("Sherlock", 1.80);
sherlock2.home.ownedSince = new Date(123);
sherlock2.home.address.street = "Baker Street";
sherlock2.home.address.number = 221;
// assertion succeeds as the data of both objects are the same.
assertThat(sherlock).usingRecursiveComparison().isEqualTo(sherlock2);
// assertion fails because sherlock.equals(sherlock2) is false.
assertThat(sherlock).isEqualTo(sherlock2);
}
static class Person {
String name;
double height;
Home home = new Home();
}
static class Home {
Address address = new Address();
Date ownedSince;
}
static class Address {
int number;
String street;
}
}
이곳은 잘 모르겠다..