Skip to content

Commit

Permalink
Trying to use Generex as proposed in Issue mtedone#218 to fill an email
Browse files Browse the repository at this point in the history
  • Loading branch information
daivanov committed Oct 30, 2016
1 parent 946ba4f commit 21335eb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>com.github.mifmif</groupId>
<artifactId>generex</artifactId>
<version>1.0.1</version>
</dependency>

<!-- Testing dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mifmif.common.regex.Generex;

import uk.co.jemos.podam.api.PodamUtils;
import uk.co.jemos.podam.exceptions.PodamMockeryException;

Expand Down Expand Up @@ -177,9 +180,8 @@ public Object getValue() throws PodamMockeryException {
if (null != (minAnno = findTypeFromList(annotations, Pattern.class))) {

Pattern pattern = (Pattern) minAnno;
LOG.warn("At the moment PODAM doesn't support @Pattern({}),"
+ " returning null", pattern.regexp());
return null;
Generex generex = new Generex(pattern.regexp());
return generex.random();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class ValidatedPojo {
@Size(min = 2)
private Collection<String> minCollection;

@Pattern(regexp = "^[a-zA-Z0-9_]*$")
@Pattern(regexp = "[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}")
private String identifier;

@Email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ public void podamShouldFulfillMostOfTheJavaxValidationFramework() throws Excepti

PodamFactory podamFactory = podamFactorySteps.givenAPodamFactoryWithEmailStrategy();

ValidatedPojo pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(ValidatedPojo.class, podamFactory);
podamValidationSteps.theObjectShouldNotBeNull(pojo);
Object obj = podamInvocationSteps.whenIInvokeTheFactoryForClass(ValidatedPojo.class, podamFactory);
podamValidationSteps.theObjectShouldNotBeNull(obj);
podamValidationSteps.thePojoMustBeOfTheType(obj, ValidatedPojo.class);

ValidatedPojo pojo = (ValidatedPojo)obj;

podamValidationSteps.theStringMatchesAPattern(pojo.getIdentifier(), "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$");

podamValidationSteps.theObjectShouldNotBeNull(pojo.getBoolFalse());
podamValidationSteps.theObjectShouldNotBeNull(pojo.getBoolTrue());
podamValidationSteps.theStringFieldCannotBeNullOrEmpty(pojo.getFilledString());
Expand All @@ -49,7 +55,7 @@ public void podamShouldFulfillMostOfTheJavaxValidationFramework() throws Excepti
podamValidationSteps.theObjectShouldNotBeNull(pojo.getMaxCollection());
podamValidationSteps.theObjectShouldNotBeNull(pojo.getMinCollection());
podamValidationSteps.theObjectShouldNotBeNull(pojo.getEmail());
podamValidationSteps.theObjectShouldBeNull(pojo.getIdentifier());
podamValidationSteps.theObjectShouldNotBeNull(pojo.getIdentifier());

Validator validator = podamFactorySteps.givenAJavaxValidator();
validatorSteps.thePojoShouldNotViolateAnyValidationsOnValidatedPojo(validator, pojo);
Expand Down

0 comments on commit 21335eb

Please sign in to comment.