-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[10단계 - 콘솔 UI 지원] 리브(김민주) 미션 제출합니다. #176
Changes from 1 commit
ab3b07c
d987938
6c57bca
e6f8113
6ed5224
d62e310
85bbef9
c9612a9
4c548e5
9c698e0
5a8b0a0
9c7f39a
052d2ce
5e9b9c2
a66a28e
bf661f1
c04c8e8
4f5c0fc
b0cf1d8
5f01db3
e20a498
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package roomescape.repository; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentSkipListMap; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import roomescape.domain.ReservationTime; | ||
|
||
public class MemoryReservationTimeRepository implements ReservationTimeRepository { | ||
|
||
private final Map<Long, ReservationTime> reservationTimes; | ||
private final AtomicLong index; | ||
|
||
public MemoryReservationTimeRepository() { | ||
this.reservationTimes = new ConcurrentSkipListMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 먼저 concurrent는 동기화를 위해서 사용했습니다.
|
||
this.index = new AtomicLong(); | ||
} | ||
|
||
@Override | ||
public ReservationTime save(ReservationTime reservationTimeRequest) { | ||
ReservationTime newReservationTime = new ReservationTime(index.incrementAndGet(), reservationTimeRequest); | ||
reservationTimes.put(newReservationTime.getId(), newReservationTime); | ||
return newReservationTime; | ||
} | ||
|
||
@Override | ||
public ReservationTime findById(Long id) { | ||
return reservationTimes.get(id); | ||
} | ||
|
||
@Override | ||
public List<ReservationTime> findAll() { | ||
return List.copyOf(reservationTimes.values()); | ||
} | ||
|
||
@Override | ||
public Optional<Integer> deleteById(Long id) { | ||
if (reservationTimes.containsKey(id)) { | ||
reservationTimes.remove(id); | ||
return Optional.of(1); | ||
} else { | ||
return Optional.empty(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional 잘 적용해주셨네요! 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다! 그리고 |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package roomescape.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.DynamicTest.dynamicTest; | ||
|
||
import java.time.LocalTime; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.DynamicTest; | ||
import org.junit.jupiter.api.TestFactory; | ||
import roomescape.dto.ReservationTimeRequest; | ||
import roomescape.dto.ReservationTimeResponse; | ||
import roomescape.repository.MemoryReservationTimeRepository; | ||
|
||
class ReservationTimeServiceTest { | ||
|
||
@TestFactory | ||
@DisplayName("예약 시간을 저장, 조회, 삭제한다.") | ||
Collection<DynamicTest> saveReservationTimeAndFindAndDelete() { | ||
ReservationTimeService reservationTimeService = new ReservationTimeService( | ||
new MemoryReservationTimeRepository()); | ||
|
||
return List.of( | ||
dynamicTest("예약 시간을 저장한다.", () -> { | ||
ReservationTimeRequest reservationTimeRequest = new ReservationTimeRequest(LocalTime.of(10, 0)); | ||
ReservationTimeResponse newReservationTime = reservationTimeService.createReservationTime( | ||
reservationTimeRequest); | ||
|
||
assertAll( | ||
() -> assertThat(newReservationTime.id()).isSameAs(1L), | ||
() -> assertThat(newReservationTime.startAt()).isEqualTo("10:00") | ||
); | ||
}), | ||
dynamicTest("예약 시간을 모두 조회한다.", () -> { | ||
assertThat(reservationTimeService.findReservationTimes()).hasSize(1); | ||
}), | ||
dynamicTest("예약 시간을 삭제한다.", () -> { | ||
reservationTimeService.deleteReservationTime(1L); | ||
|
||
assertThat(reservationTimeService.findReservationTimes()).hasSize(0); | ||
}), | ||
dynamicTest("이미 삭제된 예약 시간을 삭제하려고 시도하면 예외가 발생한다.", () -> { | ||
assertThatIllegalArgumentException() | ||
.isThrownBy(() -> reservationTimeService.deleteReservationTime(1L)) | ||
.withMessage("존재하지 않는 시간입니다."); | ||
}) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class 시작 부분과 필드 사이 공백은 보통 안 넣어주시던데 여기는 들어가있네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
꼼꼼하게 봐주셔서 감사합니다! 👍
수정했습니다. 😆