Compare commits
No commits in common. "ca2a6c179562583f8510227dcef7b280ec8ebb36" and "7e38b5a2e0416831cfe1657e379b03fde3709abc" have entirely different histories.
ca2a6c1795
...
7e38b5a2e0
6 changed files with 24 additions and 150 deletions
|
@ -1,24 +0,0 @@
|
||||||
package eu.ztsh.wymiana.validation;
|
|
||||||
|
|
||||||
import jakarta.validation.Constraint;
|
|
||||||
import jakarta.validation.Payload;
|
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|
||||||
|
|
||||||
|
|
||||||
@Retention(RUNTIME)
|
|
||||||
@Target({ TYPE_USE })
|
|
||||||
@Documented
|
|
||||||
@Constraint(validatedBy = {ValidExchangeRequestValidator.class })
|
|
||||||
public @interface ValidExchangeRequest {
|
|
||||||
|
|
||||||
String message() default "Exchange request is not valid";
|
|
||||||
Class<?>[] groups() default { };
|
|
||||||
Class<? extends Payload>[] payload() default { };
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package eu.ztsh.wymiana.validation;
|
|
||||||
|
|
||||||
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
|
|
||||||
import jakarta.validation.ConstraintValidator;
|
|
||||||
import jakarta.validation.ConstraintValidatorContext;
|
|
||||||
|
|
||||||
public class ValidExchangeRequestValidator implements ConstraintValidator<ValidExchangeRequest, CurrencyExchangeRequest> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(CurrencyExchangeRequest currencyExchangeRequest,
|
|
||||||
ConstraintValidatorContext constraintValidatorContext) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package eu.ztsh.wymiana.web.model;
|
|
||||||
|
|
||||||
import eu.ztsh.wymiana.validation.ValidExchangeRequest;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.Builder;
|
|
||||||
import org.hibernate.validator.constraints.pl.PESEL;
|
|
||||||
|
|
||||||
@Builder
|
|
||||||
@ValidExchangeRequest
|
|
||||||
public record CurrencyExchangeRequest(
|
|
||||||
@PESEL String pesel,
|
|
||||||
@NotNull String from,
|
|
||||||
@NotNull String to,
|
|
||||||
Double toBuy,
|
|
||||||
Double toSell
|
|
||||||
) {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,42 +1,58 @@
|
||||||
package eu.ztsh.wymiana.validation;
|
package eu.ztsh.wymiana.validation;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
import org.hibernate.validator.internal.engine.DefaultClockProvider;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
class AdultValidatorTest extends ValidatorTest<AdultValidator, String> {
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
protected AdultValidatorTest() {
|
class AdultValidatorTest {
|
||||||
super(new AdultValidator());
|
|
||||||
|
private static AdultValidator validator;
|
||||||
|
private static ConstraintValidatorContext validatorContext;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void prepare() {
|
||||||
|
validator = new AdultValidator();
|
||||||
|
validatorContext = Mockito.mock(ConstraintValidatorContext.class);
|
||||||
|
Mockito.when(validatorContext.getClockProvider()).thenReturn(DefaultClockProvider.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("No digits in PESEL")
|
@DisplayName("No digits in PESEL")
|
||||||
void invalidPatternTest() {
|
void invalidPatternTest() {
|
||||||
assertThatValidation("notAPesel").isFalse();
|
assertThat(call("notAPesel")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Not an adult")
|
@DisplayName("Not an adult")
|
||||||
void notAnAdultTest() {
|
void notAnAdultTest() {
|
||||||
assertThatValidation("24242400000").isFalse();
|
assertThat(call("24242400000")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Adult")
|
@DisplayName("Adult")
|
||||||
void adultTest() {
|
void adultTest() {
|
||||||
assertThatValidation("88010100000").isTrue();
|
assertThat(call("88010100000")).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Elderly person")
|
@DisplayName("Elderly person")
|
||||||
void seniorTest() {
|
void seniorTest() {
|
||||||
assertThatValidation("00010100000").isTrue();
|
assertThat(call("00010100000")).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Invalid date")
|
@DisplayName("Invalid date")
|
||||||
void notAValidDateTest() {
|
void notAValidDateTest() {
|
||||||
assertThatValidation("00919100000").isFalse();
|
assertThat(call("00919100000")).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean call(String value) {
|
||||||
|
return validator.isValid(value, validatorContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
package eu.ztsh.wymiana.validation;
|
|
||||||
|
|
||||||
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class ValidExchangeRequestValidatorTest extends ValidatorTest<ValidExchangeRequestValidator, CurrencyExchangeRequest> {
|
|
||||||
|
|
||||||
protected ValidExchangeRequestValidatorTest() {
|
|
||||||
super(new ValidExchangeRequestValidator());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Valid request with buy value specified")
|
|
||||||
void validRequestWithBuyTest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Valid request with sell value specified")
|
|
||||||
void validRequestWithSellTest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Invalid PESEL value")
|
|
||||||
void invalidPeselTest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("From and To have same value")
|
|
||||||
void sameFromToTest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Empty amounts")
|
|
||||||
void emptyBuySellTest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Both Buy and Sell params filled in")
|
|
||||||
void bothFilledBuySellTest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
@DisplayName("Negative amount value")
|
|
||||||
void negativeAmountTest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package eu.ztsh.wymiana.validation;
|
|
||||||
|
|
||||||
import jakarta.validation.ConstraintValidator;
|
|
||||||
import jakarta.validation.ConstraintValidatorContext;
|
|
||||||
import org.assertj.core.api.AbstractBooleanAssert;
|
|
||||||
import org.hibernate.validator.internal.engine.DefaultClockProvider;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
public abstract class ValidatorTest<V extends ConstraintValidator<?, C>, C> {
|
|
||||||
|
|
||||||
private final V validator;
|
|
||||||
private static ConstraintValidatorContext validatorContext;
|
|
||||||
|
|
||||||
protected ValidatorTest(V validator) {
|
|
||||||
this.validator = validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
static void prepare() {
|
|
||||||
validatorContext = Mockito.mock(ConstraintValidatorContext.class);
|
|
||||||
Mockito.when(validatorContext.getClockProvider()).thenReturn(DefaultClockProvider.INSTANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AbstractBooleanAssert<?> assertThatValidation(C value) {
|
|
||||||
return assertThat(validator.isValid(value, validatorContext));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue