【问题标题】:PodamFactory is not setting fields with annotationsPodamFactory 没有设置带有注释的字段
【发布时间】:2019-03-08 08:51:18
【问题描述】:

我正在为我的类做单元测试,我使用 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
}

【问题讨论】:

标签: java unit-testing jemos-podam


【解决方案1】:

你将升级工件版本

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-19
    • 2019-09-16
    • 1970-01-01
    • 2019-06-15
    • 2014-10-05
    • 1970-01-01
    • 2017-10-29
    • 2015-09-19
    相关资源
    最近更新 更多