본문 바로가기
백엔드기술/개발언어

상속 관계에서 Lombok Builder 사용

by RevFactory 2019. 10. 6.
public enum AdAccountType {
    BUSINESS,
    INDIVIDUAL
}
@Getter
@ToString
@AllArgsConstructor
public class AdAccountTO {
    private Long id;
    private String name;
    private AdAccountType adAccountType;
}
@Getter
@ToString(callSuper = true)
public class BusinessAdAccountTO extends AdAccountTO {

    private String companyName;

    @Builder
    private BusinessAdAccountTO(Long id, String name, String companyName) {
        super(id, name, AdAccountType.BUSINESS);
        this.companyName = companyName;
    }
}
@Getter
@ToString(callSuper = true)
public class IndividualAdAccountTO extends AdAccountTO {

    private String masterName;

    @Builder
    private IndividualAdAccountTO(Long id, String name, String masterName) {
        super(id, name, AdAccountType.INDIVIDUAL);
        this.masterName = masterName;
    }
}

 

 

테스트

@Slf4j
class BusinessAdAccountTOTest {

    @Test
    public void buildTest() {
        BusinessAdAccountTO businessAdAccountTO = BusinessAdAccountTO.builder()
                .id(1L)
                .name("robin")
                .companyName("kakao")
                .build();

        assertThat(businessAdAccountTO.getId()).as("id").isEqualTo(1L);
        assertThat(businessAdAccountTO.getName()).as("name").isEqualTo("robin");
        assertThat(businessAdAccountTO.getAdAccountType()).as("type").isEqualTo(AdAccountType.BUSINESS);
        assertThat(businessAdAccountTO.getCompanyName()).as("companyName").isEqualTo("kakao");

    }

}