Skip to content
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

πŸš€ 2단계 - μˆ˜κ°•μ‹ μ²­(도메인 λͺ¨λΈ) #326

Open
wants to merge 13 commits into
base: choomi1217
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: SessionType Test
choomi1217 committed Dec 4, 2023
commit 89a679b3e32930bac21fecd20b932104dab034ea
20 changes: 10 additions & 10 deletions src/main/java/nextstep/courses/domain/PaidSessionType.java
Original file line number Diff line number Diff line change
@@ -5,25 +5,25 @@
public class PaidSessionType implements SessionType {

private int maximumHeadCount;
private int price;
private long price;

public PaidSessionType(int maximumHeadCount, int price) {
public PaidSessionType(int maximumHeadCount, long price) {
this.maximumHeadCount = maximumHeadCount;
this.price = price;
}

public void canRegistered(int payedPrice){
int nextHeadCount = maximumHeadCount + 1;
if(maximumHeadCount < nextHeadCount){
private void canRegistered(long payedPrice, int headCount) {
int nextHeadCount = headCount + 1;
if (maximumHeadCount < nextHeadCount) {
throw new IllegalArgumentException("μΈμ›μˆ˜κ°€ μ΄ˆκ³Όν–ˆμŠ΅λ‹ˆλ‹€.");
}
if(this.price != payedPrice){
throw new IllegalArgumentException("μ§€λΆˆ κΈˆμ•‘μ΄ λ‹€λ¦…λ‹ˆλ‹€.");
if (payedPrice < this.price) {
throw new IllegalArgumentException("μ§€λΆˆν•˜μ‹  κΈˆμ•‘μ΄ λͺ¨μžλžλ‹ˆλ‹€.");
}
}

public PaidSessionType registered(int payedPrice) {
canRegistered(payedPrice);
return new PaidSessionType(this.maximumHeadCount + 1, this.price);
public PaidSessionType registered(long payedPrice, int headCount) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

등둝 κ°€λŠ₯ν•œμ§€ ν™•μΈν•˜λŠ” 뢀뢄을 μΆ”μƒν™”ν•˜λ©΄ 쒋을 것 κ°™μ•„μš”! μ§€κΈˆμ€ μΈν„°νŽ˜μ΄μŠ€μ— λ©”μ„œλ“œκ°€ ν•˜λ‚˜λ„ μ—†λŠ” 것 κ°™μ•„μ„œμš”..!
λ‚˜μ•„κ°€μ„œ 그런 λŠλ‚Œμ΄ λœλ‹€λ©΄ sessionType을 Enum으둜 관리해도 쒋지 μ•Šμ„κΉŒμš” ?
μ§€κΈˆμ€ SessionType을 DB둜 κ΄€λ¦¬ν•˜λ €λ©΄ μ–˜λ„ λ³„λ„μ˜ 도메인이 λ˜μ–΄μ•Ό ν•  것 κ°™μ•„μš”!

canRegistered(payedPrice, headCount);
return new PaidSessionType(headCount + 1, this.price);
}
}
1 change: 1 addition & 0 deletions src/main/java/nextstep/courses/domain/Session.java
Original file line number Diff line number Diff line change
@@ -8,5 +8,6 @@ public class Session {
private SessionType type;
private SessionStatus status;
private int price;
private int headCount;

}
42 changes: 42 additions & 0 deletions src/test/java/nextstep/courses/domain/SessionTypeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package nextstep.courses.domain;

import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatNoException;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class SessionTypeTest {

@DisplayName("무료 κ°•μ˜λŠ” λˆ„κ΅¬λ‚˜ μˆ˜κ°•μ‹ μ²­μ΄ κ°€λŠ₯ν•©λ‹ˆλ‹€.")
@Test
void a() {
FreeSessionType freeSessionType = new FreeSessionType();
assertThatNoException().isThrownBy(freeSessionType::registered);
}

@DisplayName("2λͺ…이 μ΅œλŒ€ 정원인 유료 κ°•μ˜λŠ” μ΅œλŒ€ μˆ˜κ°• 인원을 μ΄ˆκ³Όν•  수 μ—†μŠ΅λ‹ˆλ‹€.")
@Test
void b() {
long pirce = 10_000;
int maximumHeadCount = 100;
PaidSessionType paidSessionType = new PaidSessionType(maximumHeadCount, pirce);

assertThatNoException().isThrownBy(() -> paidSessionType.registered(pirce, 99));
assertThatIllegalArgumentException().isThrownBy(() -> paidSessionType.registered(pirce, 100));
assertThatIllegalArgumentException().isThrownBy(() -> paidSessionType.registered(pirce, 101));
}

@DisplayName("유료 κ°•μ˜λŠ” 결제금이 κ°•μ˜λ£Œμ™€ κ°™μ•„μ•Ό μˆ˜κ°•μ‹ μ²­μ΄ κ°€λŠ₯ν•©λ‹ˆλ‹€.")
@Test
void c() {
long pirce = 10_000;
int maximumHeadCount = 2;
PaidSessionType paidSessionType = new PaidSessionType(maximumHeadCount, pirce);

assertThatNoException().isThrownBy(() -> paidSessionType.registered(pirce, 1));
assertThatIllegalArgumentException().isThrownBy(() -> paidSessionType.registered(1000, 1));
}


}