Skip to content

Commit

Permalink
#296 fix: 제약 조건 변경 (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghwankim-dev authored Apr 7, 2024
1 parent 0fe9437 commit 153fc6f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface CountNumber {
String message() default "0포함 양수여야 합니다";
String message() default "개수는 양수여야 합니다";

Class<?>[] groups() default {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public boolean isValid(Count value, ConstraintValidatorContext context) {
if (value == null) {
return false;
}
return value.getValue().compareTo(BigInteger.ZERO) >= 0;
return value.getValue().compareTo(BigInteger.ZERO) > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import javax.validation.Payload;

@Documented
@Constraint(validatedBy = {MoneyValidator.class})
@Constraint(validatedBy = MoneyValidator.class)
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MoneyNumber {
String message() default "0포함 양수여야 합니다";
String message() default "금액은 양수여야 합니다";

Class<?>[] groups() default {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

public class MoneyValidator implements ConstraintValidator<MoneyNumber, Money> {
@Override
public boolean isValid(codesquad.fineants.domain.common.money.Money value, ConstraintValidatorContext context) {
public boolean isValid(Money value, ConstraintValidatorContext context) {
if (value == null) {
return false;
}
return value.getAmount().compareTo(BigDecimal.ZERO) >= 0;
return value.getAmount().compareTo(BigDecimal.ZERO) > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,14 @@ void addPurchaseHistoryWithInvalidInput() throws Exception {
requestBody.put("purchasePricePerShare", 0);
requestBody.put("memo", "첫구매");

String body = objectMapper.writeValueAsString(requestBody);

given(portfolioRepository.findById(anyLong())).willReturn(Optional.of(portfolio));
given(portfolioRepository.findById(anyLong()))
.willReturn(Optional.of(portfolio));

// when & then
mockMvc.perform(post(url)
.contentType(MediaType.APPLICATION_JSON)
.characterEncoding(StandardCharsets.UTF_8)
.content(body))
.content(ObjectMapperUtil.serialize(requestBody)))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("code").value(equalTo(400)))
.andExpect(jsonPath("status").value(equalTo("Bad Request")))
Expand Down

0 comments on commit 153fc6f

Please sign in to comment.