mtedone / podam

PODAM - POjo DAta Mocker
https://mtedone.github.io/podam
MIT License
323 stars 750 forks source link

jakarta.validation.constraints.Email annotation not working with Strategy #315

Closed rmpt closed 1 year ago

rmpt commented 1 year ago

Seen a lot of examples for Email annotation, but it's not working for: jakarta.validation.constraints.Email

I know it shouldn't matter, but I cannot make it work so it's something from the lib I guess. There's my code:

POJO

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

@Getter
@AllArgsConstructor
@ToString
public class MyPojo {
    @Email
    @NotEmpty
    private final String email;
}

Strategy

public class EmailStrategy implements AttributeStrategy<String> {

    @Override
    public String getValue(Class<?> attrType, List<Annotation> attrAnnotations) {
        return new StringBuilder()
                .append(RandomStringUtils.random(4))
                .append("@")
                .append(RandomStringUtils.random(4))
                .append(".")
                .append(RandomStringUtils.random(3))
                .toString();
    }
}

PODAM usage

import jakarta.validation.constraints.Email;
...
var podamFactory = new PodamFactoryImpl();
AttributeStrategy<?> strategy = new EmailStrategy();
((RandomDataProviderStrategy) podamFactory.getStrategy()).addOrReplaceAttributeStrategy(Email.class, strategy);
podamFactory.manufacturePojo(MyPojo.class);

Generated email: yP_MkLtivH

Any idea? Im working on: testImplementation 'uk.co.jemos.podam:podam:7.2.11.RELEASE'

Tried another versions, but same problem.

daivanov commented 1 year ago

Hi,

And what if you remove @NotEmpty annotaton?

Thanks, Daniil

rmpt commented 1 year ago

Already tried it, same result.

daivanov commented 1 year ago

I cannot reproduce the problem. There could be some glitch with lombok generated code and I could tell, that having final in the property definition is not valid in Java.

Thanks, Daniil

daivanov commented 1 year ago

The issue must be with lombok generated code.

Thanks, Daniil

rmpt commented 1 year ago

it is not, I've tried with manual getters and setters

daivanov commented 1 year ago

Hi,

Could you change commit 993aeb6b5fadcac06b709affca4c5fcb784ca708 to demonstrate the problem?

Thanks, Daniil

daivanov commented 1 year ago

Hi.

I will close this issue as without any reproduction code there is no perspective to make a fix. Please, alter the existing test or make a gist demonstrating the problem. Then report a new issue as I suspect you cannot reopen closed issues.

Thanks, Daniil