Skip to content

ignaciotcrespo/MrPolite

Repository files navigation

Mr Polite Logo

build status Build Status codecov.io MIT License

Mr Polite

Mr Polite will give you anything you need, if you kindly ask for it.

Let's say you have a class Animal and you want to generate an instance of it:

Animal animal = MrPolite.one(Animal.class).please();

Mr Polite will create the Animal for you and populate with random data. He is so good with you. Very important, you need to be gentle with Mr Polite, remember to say please at the end.

Ok, what if you need many animals? Let's see another example:

List<Animal> animals = MrPolite.aListOf(15, Animal.class).please();

Mr Polite will create 15 animals for you. Nice, but sometimes you already have the instance and just want to change some fields. Let's take a look:

MrPolite.change(animal)
   .withFieldEqualTo("type", "cat")
   .please();

Notice you must say which field needs to be changed using withFieldEqualTo("type", "cat"). MrPolite will not change anything in the object unless you specify what needs to be changed. He doesn't want to be rude and change everything without being asked for it.

Polite desires

Mr Polite can do much more than just populating random data. You can express to him your desires, and you will be pleased.

MrPolite.one(Animal.class)
   .withDepth(1)
   .withFieldEqualTo("type", "cat")
   .withClassEqualTo(Integer.class, 25)
   .withCollectionSizeRange(3, 10)
   .withGenerics(Long.class)
   .withFieldImageLink("\\w*[iI]mage\\w*", 200, 300)
   .withFieldNamesInStrings()
   .withNumberRange(1000, 2000)
   .withStringsMaxLength(10)
   .overrideValues(true)
   .overrideFinals()
   .exclude(".+Uri.+")
   .exclude(String.class)
   .withDataGenerator(...) //1.0.7.2-SNAPSHOT
   .please();

For more details about these parameters, please refer to the wiki section.

Interfaces

Mr. Polite kindly checks for the most common interfaces like List, Set, Map and create ArrayList, HashSet, HashMap, for other interfaces a proxy is created returning random objects on each method.

Current Version

  • The current stable version is 1.0.6
  • The current snapshot version is 1.0.7.2-SNAPSHOT

Android support

MrPolite works fine in android, it is compiled with JDK 1.6 and tested on real projects.

Kotlin

The variables declared with val are generated ok, for constants declared with val force to overwrite everything using

        Animal animal = one(Animal.class)
                .overrideValues(true)
                .overrideFinals()
                .please();

Adding Mr Polite to your project

Using gradle:

compile 'com.github.ignaciotcrespo:mrpolite:1.0.6'

Contribution

Mr Polite is a work in progress, it is stable but of course there are still some edge cases not covered.

You are welcome to contribute to the project, feel free to create a pull request with your changes.

For questions, suggestions or feedback, create an issue in this repository.

License

Mr Polite is released under the MIT license.

The MIT License

Copyright (c) 2017, Ignacio Tomas Crespo (itcrespo@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

About

Mr Polite will create or change any java object for you, if you kindly ask for it :)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published