PodamFactory没有设置带有注释的字段

时间:2019-03-08 08:51:19

标签: java unit-testing jemos-podam

我正在为类进行单元测试,并且使用PodamFactoryImpl用伪数据填充对象。

问题:
似乎具有@NotEmpty之类的注释的字段(来自javax.validation.constraints)为NULL。

有什么方法可以配置PodamFactoryImpl实例以填充所有字段? (例如将其配置为忽略注释)

我的填充方法:

public static <T> T fillObject(Class<T> clazz) {
    PodamFactory factory = new PodamFactoryImpl();
    return factory.manufacturePojoWithFullData(clazz);
}

我可悲的例子POJO:

public class Location {
    @NotEmpty
    private String tenant; //will be null
    @NotEmpty
    private String serviceName; //will be null
    @NotNull
    private List<LocationData> locations; //will be with value
    @NotNull
    private Boolean async; //will be with value
    @NotNull
    private Long companyIndex; //will be with value
    @NotEmpty
    private String topicId; //will also be null
}

1 个答案:

答案 0 :(得分:0)

您将升级神器版本

 <dependency>
    <groupId>uk.co.jemos.podam</groupId>
    <artifactId>podam</artifactId>
    <version>7.2.6.RELEASE</version>
    <scope>test</scope>
</dependency>