### Question:
OpenHoursServiceImpl implements OpenHoursService { @Override public OpeningHours save(OpeningHours hours) { log.info(LogMessage.IN_SAVE); if (hours.getOpenTime().getHour() > hours.getCloseTime().getHour()) { throw new BadRequestException(ErrorMessage.CLOSE_TIME_LATE_THAN_OPEN_TIME); } if (hours.getBreakTime() != null) { if (hours.getBreakTime().getStartTime().getHour() > hours.getOpenTime().getHour() && hours.getBreakTime().getEndTime().getHour() < hours.getCloseTime().getHour()) { breakTimeService.save(hours.getBreakTime()); } else { throw new BadRequestException(ErrorMessage.WRONG_BREAK_TIME); } } return hoursRepo.save(hours); }  List<OpeningHours> getOpenHoursByPlace(Place place); @Override OpeningHours save(OpeningHours hours); @Override List<OpeningHours> findAll(); @Override OpeningHours findById(Long id); @Override OpeningHours update(Long id, OpeningHours updatedHours); @Override Long deleteById(Long id); @Override Set<OpeningHours> findAllByPlaceId(Long placeId); @Override void deleteAllByPlaceId(Long placeId);  }### Answer:
@Test public void saveTestWOBreakTime() { OpeningHours openingHours = OpeningHours.builder() .openTime(LocalTime.of(9, 0)) .closeTime(LocalTime.of(20, 0)) .build(); when(openHoursRepo.save(openingHours)).thenReturn(openingHours); assertEquals(openingHours, openHoursService.save(openingHours)); }
@Test public void saveTestWithBreakTime() { BreakTime breakTime = BreakTime.builder() .startTime(LocalTime.of(13, 0)) .endTime(LocalTime.of(14, 0)) .build(); OpeningHours openingHours = OpeningHours.builder() .openTime(LocalTime.of(9, 0)) .closeTime(LocalTime.of(20, 0)) .breakTime(breakTime) .build(); when(openHoursRepo.save(openingHours)).thenReturn(openingHours); when(breakTimeService.save(any(BreakTime.class))).thenReturn(breakTime); assertEquals(openingHours, openHoursService.save(openingHours)); }
@Test(expected = BadRequestException.class) public void saveTestWithOpeningHoursBiggerThanEndOpeningHours_ThrowException() { OpeningHours openingHours = OpeningHours.builder() .openTime(LocalTime.of(20, 0)) .closeTime(LocalTime.of(9, 0)) .build(); openHoursService.save(openingHours); }
@Test(expected = BadRequestException.class) public void saveTestWithStartBreakTimeBiggerThanEndBreakTime_ThrowException() { BreakTime breakTime = BreakTime.builder() .startTime(LocalTime.of(13, 0)) .endTime(LocalTime.of(21, 0)) .build(); OpeningHours openingHours = OpeningHours.builder() .openTime(LocalTime.of(9, 0)) .closeTime(LocalTime.of(20, 0)) .breakTime(breakTime) .build(); openHoursService.save(openingHours); }