Git Product home page Git Product logo

data-factory's Introduction

项目简介

本项目用于根据对象,随机自动生成初始化信息。便于测试。

Maven Central Build Status Coverage Status

特性

  • 8 大基本类型的支持

  • String、Date、金额,日期等常见类型的支持

  • java8 常见时间类的支持

  • 支持 String 和 Number 类型的注解定义

  • 添加 @DataFactory 注解支持

  • 支持 Regex 正则表达式

变更日志

变更日志

核心类讲解

DataUtil 工具类

提供线程安全的方法:

/**
 * 构建结果
 * @param clazz 类型
 * @return 构建结果
 */
public static <T> T build(final Class<T> clazz) {
    IData data = getInstance();
    return (T) data.build(null, clazz);
}

/**
 * 构建结果
 * @param context 执行上下文
 * @param clazz 类型
 * @return 构建结果
 */
public static <T> T build(final IContext context, final Class<T> clazz) {
    IData data = getInstance();
    return (T) data.build(context, clazz);
}

快速开始

准备工作

JDK 1.8+

Maven 3.0+

如果是 idea,测试的时候 Enable Annotation Processing

maven 引入

<dependency>
    <groupId>com.github.houbb</groupId>
    <artifactId>data-factory-core</artifactId>
    <version>0.0.3</version>
</dependency>

演示对象

一个用于演示的普通 java 对象。

public class User {

    private String name;

    private int age;

    private Date birthday;

    private List<String> stringList;

    //S/F 的枚举
    private StatusEnum statusEnum;

    private Map<String, String> map;
    
    //Getter & Setter
}

使用工具类

@Test
public void buildBeanBaseTest() throws Exception {
    User user = DataUtil.build(User.class);
    System.out.println(user);
}

输出信息如下:

User{name='wZ8CJZtK', age=-564106861, birthday=Wed Feb 27 22:14:34 CST 2019, stringList=[Du4iJkQj], statusEnum=S, map={yA5yDqM=Kdzi}}

内容每次都随机。便于基本的测试数据填充。

拓展阅读

DataFactory-01-注解支持

DataFactory-02-正则表达式支持

data-factory's People

Contributors

houbb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.