Skip to content

Commit

Permalink
test: 라벨 테스트 isOwnedCountValid 메서드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonsu00 committed Nov 28, 2024
1 parent 158d163 commit c82e888
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/test/java/postman/bottler/label/domain/LabelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import postman.bottler.label.dto.response.LabelResponseDTO;
import postman.bottler.label.exception.FirstComeFirstServedLabelException;
import postman.bottler.label.exception.InvalidLabelException;

@SpringBootTest
Expand Down Expand Up @@ -61,31 +60,32 @@ void createLabelWithAllParameters() {
}

@Test
@DisplayName("ownedCount가 limitCount를 초과하지 않는 경우 라벨 생성이 성공한다.")
void createLabelSuccessfullyWhenOwnedCountIsValid() {
@DisplayName("ownedCount가 limitCount를 초과하지 않는 경우 isOwnedCountValid 메서드는 true를 반환한다.")
void isOwnedCountValidReturnsTrue() {
// given
Long labelId = 1L;
String imageUrl = "http://example.com/image3.png";
int limitCount = 10;
int ownedCount = 5;
Label label = Label.createLabel("http://example.com/image3.png", 10);
label.increaseOwnedCount();

// when, then
assertDoesNotThrow(() -> Label.createLabel(labelId, imageUrl, limitCount, ownedCount));
// when
boolean result = label.isOwnedCountValid();

// then
assertTrue(result, "소유 인원수가 제한 인원수를 초과하지 않았을 때 true를 반환해야 함");
}

@Test
@DisplayName("ownedCount가 limitCount를 초과하는 경우 예외가 발생한다.")
void createLabelThrowsExceptionWhenOwnedCountExceedsLimit() {
@DisplayName("ownedCount가 limitCount를 초과한 경우 isOwnedCountValid 메서드는 false를 반환한다.")
void isOwnedCountValidReturnsFalse() {
// given
Long labelId = 1L;
String imageUrl = "http://example.com/image3.png";
int limitCount = 5;
int ownedCount = 6;
Label label = Label.createLabel("http://example.com/image4.png", 1);
label.increaseOwnedCount();
label.increaseOwnedCount();

// when, then
assertThrows(FirstComeFirstServedLabelException.class,
() -> Label.createLabel(labelId, imageUrl, limitCount, ownedCount),
"소유 인원수가 제한 인원수를 초과했을 때 예외가 발생해야 함");
// when
boolean result = label.isOwnedCountValid();

// then
assertFalse(result, "소유 인원수가 제한 인원수에 도달했을 때 false를 반환해야 함");
}

@Test
Expand Down Expand Up @@ -114,4 +114,4 @@ void createLabelWithNegativeLimitCountThrowsException() {
Label.createLabel(imageUrl, invalidLimitCount);
}, "limitCount가 음수일 경우 예외가 발생해야 함");
}
}
}

0 comments on commit c82e888

Please sign in to comment.