added ParameterizedTest for offer validator
This commit is contained in:
@@ -28,6 +28,9 @@ public final class OfferValidator {
|
|||||||
if (offer.getOfferId().equals("")) {
|
if (offer.getOfferId().equals("")) {
|
||||||
throw new InvalidOfferException("Offer ID cannot be empty");
|
throw new InvalidOfferException("Offer ID cannot be empty");
|
||||||
}
|
}
|
||||||
|
if (offer.getLastUpdate().equals("")) {
|
||||||
|
throw new InvalidOfferException("LastUpdate cannot be empty");
|
||||||
|
}
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
throw new InvalidOfferException("Required information is missing in the offer", e);
|
throw new InvalidOfferException("Required information is missing in the offer", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package de.rwu.easydrop.service.validation;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
@@ -25,11 +27,31 @@ public class OfferValidatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("invalidOffer")
|
@MethodSource("invalidOfferProvider")
|
||||||
void validate_InvalidOffer_ThrowsInvalidOfferException(Offer offer) {
|
void validate_InvalidOffer_ThrowsInvalidOfferException(Offer offer) {
|
||||||
// Act and Assert
|
// Act and Assert
|
||||||
assertThrows(InvalidOfferException.class, () -> OfferValidator.validate(offer));
|
assertThrows(InvalidOfferException.class, () -> OfferValidator.validate(offer));
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static Stream<Offer> invalidOfferProvider() {
|
||||||
|
return Stream.of(
|
||||||
|
createOfferWithEmptylastUpdate(),
|
||||||
|
createOfferWithEmptyId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Offer createOfferWithEmptylastUpdate() {
|
||||||
|
Offer offer = new Offer();
|
||||||
|
offer.setOfferId("3729798");
|
||||||
|
offer.setLastUpdate("");
|
||||||
|
return offer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Offer createOfferWithEmptyId() {
|
||||||
|
Offer offer = new Offer();
|
||||||
|
offer.setOfferId("");
|
||||||
|
offer.setLastUpdate("8798476");
|
||||||
|
return offer;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user