Skip to content

Commit

Permalink
fix: 수도권 검증 로직에서 missing 좌표도 추가 (#604)
Browse files Browse the repository at this point in the history
Co-authored-by: coli-geonwoo <[email protected]>
  • Loading branch information
coli-geonwoo and coli-geonwoo authored Sep 26, 2024
1 parent b0a0a5d commit ccc71e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SupportRegionValidator implements ConstraintValidator<SupportRegion
private static final BigDecimal MAX_LATITUDE = new BigDecimal("38.3");
private static final BigDecimal MIN_LONGITUDE = new BigDecimal("125.6");
private static final BigDecimal MAX_LONGITUDE = new BigDecimal("127.9");
private static final BigDecimal MISSING_COORDINATES = new BigDecimal("0.0");

private String latitudeFieldName;
private String longitudeFieldName;
Expand Down Expand Up @@ -41,11 +42,17 @@ public boolean isValid(Object object, ConstraintValidatorContext constraintValid

private boolean isInLatitudeRange(String latitude) {
BigDecimal latitudeValue = new BigDecimal(latitude);
return MIN_LATITUDE.compareTo(latitudeValue) <= 0 && MAX_LATITUDE.compareTo(latitudeValue) >= 0;
return isMissingCoordinate(latitudeValue)
|| (MIN_LATITUDE.compareTo(latitudeValue) <= 0 && MAX_LATITUDE.compareTo(latitudeValue) >= 0);
}

private boolean isInLongitudeRange(String longitude) {
BigDecimal longitudeValue = new BigDecimal(longitude);
return MIN_LONGITUDE.compareTo(longitudeValue) <= 0 && MAX_LONGITUDE.compareTo(longitudeValue) >= 0;
return isMissingCoordinate(longitudeValue)
|| (MIN_LONGITUDE.compareTo(longitudeValue) <= 0 && MAX_LONGITUDE.compareTo(longitudeValue) >= 0);
}

private boolean isMissingCoordinate(BigDecimal coordinate) {
return MISSING_COORDINATES.compareTo(coordinate) == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -36,6 +37,16 @@ void isValid(String latitude, String longitude, boolean expected) {
assertThat(valid).isEqualTo(expected);
}

@DisplayName("행방불명 좌표(0.0)는 true를 반환한다")
@Test
void isValidMissingCoordinate() {
MateEtaRequest mateEtaRequest = new MateEtaRequest(false, "0.0", "0.0");

boolean valid = supportRegionValidator.isValid(mateEtaRequest, mock(ConstraintValidatorContext.class));

assertThat(valid).isEqualTo(true);
}

private static Stream<Arguments> supportRegionTestCases() {
return Stream.of(
Arguments.of("37.505713", "127.050691", true), // 서울
Expand Down

0 comments on commit ccc71e6

Please sign in to comment.