YearMonthRequestDto { public String getBeforeMonthByString () { String strDate = this.strYearMonth+"-01"; LocalDate date = parse(strDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")); LocalDate beforeDate = date.minusMonths(1); return beforeDate.format(DateTimeFormatter.ofPattern("yyyy-MM")); } YearMonthRequestDto(YearMonth yearMonth); @Builder  YearMonthRequestDto(YearMonth yearMonth, String strYearMonth); String getBeforeMonthByString(); YearMonth getBeforeMonthByYearMonth(); int getQuarterOfYear(); LocalDate getLocalDate(); LocalDateTime getLocalDateTime();  }
@Test void 문자열로_직전월을_구한다() throws Exception { String month = "2020-09"; YearMonthRequestDto dto = YearMonthRequestDto.builder() .strYearMonth(month) .build(); String beforeMonth = dto.getBeforeMonthByString(); assertThat(beforeMonth).isEqualTo("2020-08"); }