Giter VIP home page Giter VIP logo

javarig's Introduction

JavaRIG

Description

This project aims to provide a random instances generator for any class in java, it iterates through setters of an empty object and sets the fields values (using Java reflection api) randomly using one of the random generators defined in src/main/java/io.javarig.RandomInstanceGenerator.java

UseCase

This generator will mainly be used is Random-Testing of all java software products.

How To use

in order to generate a random object of type YourClass, this class should have

  • public no arguments constructor
  • public setters for fields you want to generate randomly
    • naming convention for setters is setFieldName
    • fields with no publicly accessed setters will be left as the default value.

giving a class Car that respects the requirements above, this code will generate a random car

RandomInstanceGenerator randomInstanceGenerator = new RandomInstanceGenerator();
Car car = randomInstanceGenerator.generate(Car.class);

Predefined Java Classes

inorder to generate an object for a certain predefined java class or primitive type, you may use the same method mentioned above

String randomString = randomInstanceGenerator.generate(String.class);

RandomInstanceGenerator::generate

the generate method represents the entrypoint for our program, it accepts multiple arguments. The easiest way to use it is with a single argument that represents the target class

Collection Generation

to generate a collection (classes that have a size; arrays, java collections, strings...) you may use the generate method with extra arguments

Exact size
  Double[] doubles = randomInstanceGenerator.generate(Double[].class, 6);

this piece of code will generate an array of length 6, that contains randomly generated Doubles if this size is not giving, it will be randomly generated between 5 and 15

Size between two bounds
  Double[] doubles = randomInstanceGenerator.generate(Double[].class, 6,9);

this will generate an array of doubles of a random size from {6,7,8}

Generic Types

to generate a class that has a generic type (a Map per example) you may pass the generic types last in the argument list, and use any of the RandomInstanceGenerator::generate methods

  HashMap<String,Float> map = randomInstanceGenerator.generate(HashMap.class , String.class , Float.class);

to precise the wanted size:

  int size = 5; // per example
  HashMap<String,Float> map = randomInstanceGenerator.generate(HashMap.class , String.class ,size, Float.class);

Javadocs

javadocs are not yet hosted but will be soon

Contributing

This is a new project, so we welcome all contributions, feel free to open a pull request

Project Structure

.
├── ...
    ├── ...    
        ├── io.javarig.exception                # package containing our custom exceptions
        ├── io.javarig.generator                # generators for specific types: array, list, map, string, primitive ...
        ├── io.javarig.RandomInstanceGenerator  # Entrypoint for our Project, contains generate method
        ├── io.javarig.testclasses              # test classes, supplied to our testing methods.
        ├── io.javarig.generation               # Junit testing classes.
├── README.md, LICENSE...   # other files

To build sources locally follow these instructions.

Tests

unit tests are done , with a 98% coverage

Technologies

  • Java
  • Maven
  • JUNIT 5
  • Java Reflection Api

Project Status

this project is in progress, the first release is planned before the end of 2022

License

Copyright (c) 2022 {Obaydah Bouifadene, Hamza Ben Yazid, Ismail Mosleh, Ibrahim Mestadi}

Licensed under the License: MIT

Contact

Check our github ☺

javarig's People

Contributors

hamzabenyazid avatar oubaydos avatar mosle77 avatar ibrahim-mestadi 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.