Java의 생성자 Java의 생성자(constructor)는 클래스(인스턴스)를 초기화 하는 가장 기본적인 방법이다. 인스턴스의 상태를 초기화 하거나 종속성을 주입하는데 사용된다. 생성자 라는 이름에 맞게 객체를 생성하는 기능을 한다. Book.class class Book { String title; String author; String genre; public Book(String title, String author, String genre) { this.title = title; this.author = author; this.genre = genre; } } Book 이라는 인스턴스를 생성하기 위해선 다음과 같은 코드를 통해 수행할 수 있다. Book 1984 = new Book("1984",..
AssertJ AssertJ는 더 다양한 assertion을 제공하는 자바 라이브러리이다. 공식 문서 : https://assertj.github.io/doc/ Junit5에서 제공하는 Assertion method가 존재하는 데, AssertJ는 어떤 특징 때문에 추가적인 라이브러리를 사용하는 것일까? 특징 메서드 체이닝을 지원하여 더 직관적이고 읽기 쉬운 테스트코드를 작성 정확한 에러메세지 JUnit이외의 추가적인 메서드 지원 AssertJ의 여러 메소드들을 연쇄적으로 호출해 코드를 작성할 수 있다. (메서드 체이닝) import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; public cla..
어려운 테스트 아래와 같은 코드가 있다. ChessGame.java class ChessService { private final ChessGameDao chessGameDao; public void createNewGame() { ChessGame newGame = ChessBoardFactory.getInitialBoard(); chessGameDao.save(newGame) } public void statusGame(ChessGame chessGame) { chessGame.status(); chessGameDao.update(chessGame); } } class ChessGame { private final ChessBoard chessBoard; } class ChessBoard { priv..