MockNeat - the modern faker lib.

Overview

Mockneat Maven Central Build Status codecov is an arbitrary data-generator open-source library written in Java.

It provides a simple but powerful (fluent) API that enables developers to create json, xml, csv and sql data programatically.

It can also act as a powerful Random substitute or a mocking library.

Official Documentation: www.mockneat.com

Official Tutorial: www.mockneat.com

If you want to use mockneat to mock REST APIs checkout my other project: serverneat.

Installing

>= 0.4.4

Maven:

<dependency>
  <groupId>net.andreinc</groupId>
  <artifactId>mockneat</artifactId>
  <version>0.4.7</version>
</dependency>

Gradle:

implementation 'net.andreinc:mockneat:0.4.7'

<= 0.4.2

Maven:

<repositories>
    <repository>
        <id>jcenter</id>
        <url>https://jcenter.bintray.com/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>net.andreinc.mockneat</groupId>
        <artifactId>mockneat</artifactId>
        <version>0.4.2</version>
    </dependency>
</dependencies>

Gradle:

repositories {
  jcenter()
}
dependencies {
  compile 'net.andreinc.mockneat:mockneat:0.4.2'
}

Example - A random dice roll

List<String> somePeople = names().full().list(10).get();

fmt("#{person} rolled: #{roll1} #{roll2}")
            .param("person", seq(somePeople))
            .param("roll1", ints().rangeClosed(1, 6))
            .param("roll2", ints().rangeClosed(1, 6))
            .accumulate(10, "\n")
            .consume(System.out::println);

System.out.println("\nWho wins ?\n");

(possible) Output:

Sal Clouden rolled: 3 3
Cinthia Myrum rolled: 1 5
Wyatt Imber rolled: 5 1
Fidel Quist rolled: 2 2
Brandon Scrape rolled: 6 4
Arlene Cesare rolled: 6 4
Brandie Sumsion rolled: 3 4
Norris Tunby rolled: 3 5
Kareem Willoughby rolled: 1 5
Zoraida Finnerty rolled: 1 6

Who wins ?

Example - A simple CSV

System.out.println("First Name, Last Name, Email, Site, IP, Credit Card, Date");

csvs()
  .column(names().first())
  .column(names().last())
  .column(emails().domain("mockneat.com"))
  .column(urls().domains(POPULAR))
  .column(ipv4s().types(CLASS_B, CLASS_C_NONPRIVATE))
  .column(creditCards().types(AMERICAN_EXPRESS, VISA_16))
  .column(localDates().thisYear())
  .separator(" ; ")
  .accumulate(25, "\n")
  .consume(System.out::println);

(possible) Output:

Lorrie ; Urquilla ; [email protected] ; http://www.sugaredherlinda.com ; 172.150.99.65 ; 4991053014393849 ; 2019-05-25
Tabitha ; Copsey ; [email protected] ; http://www.arightcarnify.io ; 166.192.196.15 ; 4143903215740668 ; 2019-07-13
Laurine ; Patrylak ; [email protected] ; http://www.ninthbanc.gov ; 187.28.250.76 ; 4450754596171263 ; 2019-09-10
Starla ; Peiper ; [email protected] ; http://www.eathlessen.edu ; 202.189.115.252 ; 4470988734574428 ; 2019-02-18
Lakiesha ; Zevenbergen ; [email protected] ; http://www.unbendingeyes.edu ; 204.112.195.47 ; 4040555724781858 ; 2019-11-12

... and so on

Special thanks to the contributors:

Comments
  • Add the possibility to register Custom MockUnits to the MockNeat object.

    Add the possibility to register Custom MockUnits to the MockNeat object.

    Write a generic mechanism that allows the user to register Custom MockUnits with a MockNeat instance and/or globally.

    mock.register("name", Class, MockUnit) mock.custom("name").val

    To investigate what is the best strategy to achieve this.

    enhancement 
    opened by nomemory 11
  • No instructions to use this project from Maven?

    No instructions to use this project from Maven?

    It looks too complex to use this project from Maven, since it's required to download two different source projects, build them and add them to local Maven repository.

    Almost useless when working with Maven.

    opened by aborroy 10
  • Antivirus complains of Java Trojan for mockneat-0.3.8.jar

    Antivirus complains of Java Trojan for mockneat-0.3.8.jar

    My antivirus complains of the following message for the mockneat library. The version I am using is 0.3.8.

    Virus: Java.Trojan.GenericGBA.20288

    Is there any possible changes that can be made in the next version of this library so as to avoid such for future versions?

    opened by dishantkamble 7
  • Generate Numbers with a lower bound?

    Generate Numbers with a lower bound?

    it seems to be possible to generate a Upper bound using the .bound() method when working with Numbers. But is it possible to set a lower bound? The use case is mainly to enforce positive numbers

    1. >= 0
    2. > 0
    opened by StephenOTT 7
  • using list(MockUnitInt) doesn't generate a new random value each time.

    using list(MockUnitInt) doesn't generate a new random value each time.

    I am trying to generate lists of data with random size. I started with

    MockUnit<T> things;
    MockUnit<List<T>> listsOfThings = things.list(ints().range(0, 10));
    

    my expectation from looking at the API was that each time I called listOfThings.val() I'd get a new list with a random size. in practice, the random size is evaluated once, and I get lists of the same size each time.

    i've worked around this by doing

    MockUnit<List<T>> listsOfThings = ints().range(0, 10).map( size -> things.list(size).val());
    

    but that feels awkward.

    what's the intention of MockUnit.list(MockUnitInt) ? would you be open to a PR that evaluates the random size each time a new val is requested?

    opened by osi 6
  • Markovs doesn't honor RandomType

    Markovs doesn't honor RandomType

    I have a use case to have repeatable text generation based on a given seed. It appears that Markovs doesn't honor RandomType.OLD as it directly relies on ThreadLocalRandom. Please let me know if you would like me to create a pull request to fix it.

    opened by bin01 5
  • Add possibility to directly mock data into database.

    Add possibility to directly mock data into database.

    Just looking at the tutorial for mocking a MySQL database i had the thought that it would make things even better if you could directly store the resulting list into a database. A JPA provider could take care of generalising the sql code generation based on the the domain classes and the mockneat list().val(); call can make a call to the JPA persist method for storing.

    Im not familiar with the functional programming api in java 8 but if you can tell me what would be needed in order to integrate something like this into Mockneat i can help with that part.

    opened by jaysudodeveloper 5
  • localDates() does not work when using a formatter that contains time

    localDates() does not work when using a formatter that contains time

    This code: localDates().thisYear().display(ISO_LOCAL_DATE_TIME)

    fails, because ISO_LOCAL_DATE_TIME uses HOUR_OF_DAY, MINUTE_OF_HOUR, SECOND_OF_MINUTE but the formatted class is LocalDate which has no reference to time.

    opened by luciano-fiandesio 4
  • Allow option to provide BIN prefix when generating credit card number

    Allow option to provide BIN prefix when generating credit card number

    Congratulations on a cool library, "neat" is an appropriate name. 👍

    I was planning to use the creditCards() method to easily generate a credit card number, but need it to be generated with a specific BIN else it will be rejected as invalid in the system I'm testing. From the code the card prefix is taken from the CreditCardType enum, which in the case of Visa is just the first digit (4). From what I've read this is the IIN, the issuer identification number.

    It would be nice if CreditCards had another method to specify a pool of BINs to use when generating the number, e.g.

    String cardNumber1 = mockNeat.creditCards().visa().bins(445434).val();
    String cardNumber2 = mockNeat.creditCards().visa().bins(445434, 414433).val();
    
    opened by lazycodeninja 4
  • Change int to long for number of records passed to list...

    Change int to long for number of records passed to list...

    I will work on it and send a PR shortly. Currently the code takes only int for number of records. If we need billions of records created, we will need to change it to long

    default MockUnit<List> list(Supplier<List> listSupplier, int size)

    I am planning to add another method which will take long as an input.

    opened by rajib76 4
  • Feature to be able to generate data in chunks with a seed...

    Feature to be able to generate data in chunks with a seed...

    This is not a issue but a feature addition. I will try to see if I can add it but please feel free if anyone wants to pick it up. The feature requirement is as below

    Lets say that I want to create a creditcard file with 10,000 records. I should be able to create the file in one run or in 5 runs with 2000 records in each run. When I compare the one file with 10000 records and 5 files with 2000 records each, the content should be the same.

    I am not sure if this feature is already available in mockneat

    opened by rajib76 4
  • tutorial for shuffling a subset of properties, given an instance of object

    tutorial for shuffling a subset of properties, given an instance of object

    Bonjour,

    I had working with MockNeat to implement a groovy interface. Given an instance of an object, the interface can shuffle all the fields of the object.

    interface Shuffle {
        void shuffleObject()
        void shufflePartly(Class[] classesThatChange)
    }
    

    It can also shuffle some fields of the instance without touching the others, for instance : all the String type. This interface can deal with inheritance with respect on protected field.

    It was not easy for me to design the script. I tried insistantly to find a elegant way with filler(), constructor() and factory(), reading the website tutorials but none of these calls can shuffle an existing instance partially.

    So my script is using only reflect(). :-) Maybe there is a better alternative solution. In case not, I suggest to underline the power of reflect() in your tutorial. Hope the script can help.

    Thank you for the lib.

    tuto-shuffle-interface.groovy.txt

    opened by fredfr94 1
Releases(0.4.3)
Owner
Andrei Ciobanu
I make computers do as I say. Looking for new opportunities as a Senior Dev / (Technical) Engineering Manager
Andrei Ciobanu
A lightweight, mixin like injection lib using ASM

ClassTransform A lightweight, mixin like injection lib using ASM. The usage is like Mixins. You can almost copy-paste mixins code and it works. Why? I

Lenni0451 15 Dec 22, 2022
Sui - Modern super user interface implementation on Android.

Sui Modern super user interface (SUI) implementation on Android. The name, Sui, also comes from a character. Introduction Sui provides Java APIs, Shiz

Rikka apps 1k Jan 5, 2023
Piranha - a modern cloud runtime

Piranha Project The Piranha Project delivers you with Cloud ready containers and useful add-on / integration modules. Getting Started To get started w

Piranha Cloud 161 Dec 24, 2022
Free and 100% open source Progressive Java Runtime for modern Java™ deployments supported by a leading OpenJDK contributor

BellSoft Liberica JDK is a build of OpenJDK that is tested and verified to be compliant with the Java SE specification using OpenJDK Technology Compat

null 195 Dec 22, 2022
The goal of the project is to create a web application using Java EE and database (PostgreSQL) without connecting a modern technology stack like spring boot and hibernate

About The Project SignIn page SignUp page Profile page The goal of the project is to create a web application using Java EE and database (PostgreSQL)

Islam Khabibullin 2 Mar 23, 2022
InterfaceMaker is a modern plugin to handle and customize join items, hotbars and menus with a developer and administrator friendly API.

Interface Maker InterfaceMaker is a modern plugin to handle and customize join items, hotbars and menus with a developer friendly API. Features Simple

2LStudios - Minecraft 10 Nov 27, 2022
A reimagination of qCraft for modern Minecraft.

qCraft Reimagined A reimagination of qCraft for modern Minecraft. About qCraft is a mod that introduced many concepts of Quantum Physics into Minecraf

Skye Prince 13 Dec 21, 2022
JHusky - Modern native Git hooks made easy for java environments

JHusky Modern native Git hooks made easy for java environments JHusky improves your commits and more ?? Jwoof! Install Include it to your project as a

Pedro Caires 23 Oct 31, 2022
Tabletop Games Framework (TAG) - a Java-based benchmark for developing modern board games for AI research

The Tabletop Games Framework (TAG) is a Java-based benchmark for developing modern board games for AI research

null 56 Dec 12, 2022
JHipster Lite ⚡ is a development platform to generate, develop & deploy modern web applications & microservice architectures, step by step.

JHipster Lite ⚡ Description JHipster is a development platform to quickly generate, develop & deploy modern web applications & microservice architectu

JHipster 255 Jan 3, 2023
This is a Velocity plugin that makes it possible to host a modern forge server behind a Velocity proxy!

Ambassador This is a Velocity plugin that makes it possible to host a modern forge server behind a Velocity proxy! Unlike other solutions, this plugin

Adrian Bergqvist 31 Dec 28, 2022
This repository contains examples of modern Java features that appear in various videos I'm creating for my courses at Vanderbilt.

This repository contains examples of modern Java features that appear in various videos I'm creating for my courses at Vanderbilt. It's organized into

Douglas C. Schmidt 7 Dec 1, 2022
Brings the popular ruby faker gem to Java

Java Faker This library is a port of Ruby's faker gem (as well as Perl's Data::Faker library) that generates fake data. It's useful when you're develo

DiUS Computing Pty Ltd 3.9k Dec 31, 2022
Brings the popular ruby faker gem to Java and Kotlin

Data Faker This library is a modern port of java-faker, built on Java 8, with up to date libraries and several newly added Fake Generators. This libra

null 453 Jan 7, 2023
Java lib for monitoring directories or individual files via java.nio.file.WatchService

ch.vorburger.fswatch Java lib for monitoring directories or individual files based on the java.nio.file.WatchService. Usage Get it from Maven Central

Michael Vorburger ⛑️ 21 Jan 7, 2022
Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE 8 and provides the functionalities to use and handle easily Tiles in your JavaFX application.

Lib-Tile Intention Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE and provides the functionalities to use and handle easily Tile

Peter Rogge 13 Apr 13, 2022
The WhatsApp lib for java

Gorgeous The WhatsApp lib Yowsup is no longer updated. There is no WhatsApp library available, but many people need it. I will gradually open source t

null 88 Oct 11, 2022
A minecraft forge lib that is used by most of my mods.

MatyLib A minecraft forge lib that is used by most of my mods. Installing (for modders) Before installing, please decide on what version you want, by

matyrobbrt 2 Jan 7, 2022
Nightmare-text - This is a simple lib that help to create, titles, actionbars, hovers and click actions chat components.

Nightmare text This is a simple lib that help to create, titles, actionbars, hovers and click actions chat components. Setup public final class Testin

Jonathan Narvaez 8 Mar 9, 2022