zoukankan      html  css  js  c++  java
  • Java 一个mock 工具/random

    https://www.baeldung.com/java-easy-random

    <dependency>
        <groupId>org.jeasy</groupId>
        <artifactId>easy-random-core</artifactId>
        <version>4.0.0</version>
    </dependency>
    @Test
    void givenDefaultConfiguration_thenGenerateSingleObject() {
        EasyRandom generator = new EasyRandom();
        Person person = generator.nextObject(Person.class);
    
        assertNotNull(person.getAge());
        assertNotNull(person.getFirstName());
        assertNotNull(person.getLastName());
    }
    @Test
    void givenDefaultConfiguration_thenGenerateObjectsList() {
        EasyRandom generator = new EasyRandom();
        List<Person> persons = generator.objects(Person.class, 5)
            .collect(Collectors.toList());
    
        assertEquals(5, persons.size());
    }
    @Test
    void givenCustomConfiguration_thenGenerateSingleEmployee() {
        EasyRandomParameters parameters = new EasyRandomParameters();
        parameters.stringLengthRange(3, 3);
        parameters.collectionSizeRange(5, 5);
        parameters.excludeField(FieldPredicates.named("lastName").and(FieldPredicates.inClass(Employee.class)));
        parameters.excludeType(TypePredicates.inPackage("not.existing.pkg"));
        parameters.randomize(YearQuarter.class, new YearQuarterRandomizer());
    
        EasyRandom generator = new EasyRandom(parameters);
        Employee employee = generator.nextObject(Employee.class);
    
        assertEquals(3, employee.getFirstName().length());
        assertEquals(5, employee.getCoworkers().size());
        assertEquals(5, employee.getQuarterGrades().size());
        assertNotNull(employee.getDepartment());
    
        assertNull(employee.getLastName());
    
        for (YearQuarter key : employee.getQuarterGrades().keySet()) {
            assertEquals(key.getStartDate(), key.getEndDate().minusMonths(3L));
        }
    }
  • 相关阅读:
    android ImageSwitcher
    andriod Spinner
    andriod RadioButton
    anriod TabHost
    给大学生的几条良心建议
    6月最新地铁站周边二手房价格出炉
    机器学习 101 Mahout 简介 建立一个推荐引擎 使用 Mahout 实现集群 使用 Mahout 实现内容分类 结束语 下载资源
    Vim设置colorscheme小技巧
    2017年阳光私募基金一季度报告
    实用的 atom 插件
  • 原文地址:https://www.cnblogs.com/tekikesyo/p/15410732.html
Copyright © 2011-2022 走看看