https://github.com/robsonbittencourt/utility-generator
Generate fixtures class to use in your tests
https://github.com/robsonbittencourt/utility-generator
fixture fixture-generator generator java mapper
Last synced: about 1 year ago
JSON representation
Generate fixtures class to use in your tests
- Host: GitHub
- URL: https://github.com/robsonbittencourt/utility-generator
- Owner: robsonbittencourt
- License: mit
- Created: 2016-03-03T01:44:17.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-07-26T01:00:27.000Z (almost 9 years ago)
- Last Synced: 2025-03-24T08:05:50.054Z (about 1 year ago)
- Topics: fixture, fixture-generator, generator, java, mapper
- Language: Java
- Size: 142 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Utility Generator
[](https://travis-ci.org/robsonbittencourt/utility-generator) [](https://sonarcloud.io/dashboard?id=com.github.robsonbittencourt%3Autility-generator) [](https://sonarcloud.io/component_measures/metric/coverage/list?id=com.github.robsonbittencourt%3Autility-generator) [](https://sonarcloud.io/project/issues?id=com.github.robsonbittencourt%3Autility-generator&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=com.github.robsonbittencourt%3Autility-generator&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=com.github.robsonbittencourt%3Autility-generator&resolved=false&types=CODE_SMELL)
> Generate utility class to use in your project
## Generate Jar File
To generate this project as a jar file you need to run a maven command with these parameters:
- clean compile assembly:single
## Usage
## To use the Fixture class
- You should instantiate a FixtureConfiguration.
- The default method prefix is `with` but you can use any word.
- The default root path is `src/test/java/`, also you can use any path.
- Instantiate the Fixture and call the generate method
### Example:
Person:
```java
public class Person {
private String name;
private int age;
//getters and setters
}
```
You Generator class:
```java
FixtureConfiguration config = new FixtureConfiguration();
config.setMethodPrefix("with");
config.setRootPath(loader.getAbsolutePath() + config.getRootPath());
AbstractGeneratedClass fixture = new Fixture(Person.class, config);
fixture.generate();
```
Output:
```java
package com.utility.generator.main;
import com.utility.generator.main.Person;
import java.util.List;
import java.util.ArrayList;
public class PersonFixture {
private Person person = new Person();
public static PersonFixture get() {
return new PersonFixture();
}
public Person build() {
return person;
}
public List buildList(Integer amount) {
List persons = new ArrayList<>();
for (int i = 0; i < amount; i++) {
persons.add(this.build());
}
return persons;
}
public PersonFixture withName(String name) {
this.person.setName(name);
return this;
}
public PersonFixture withAge(int age) {
this.person.setAge(age);
return this;
}
}
```
## To use the Mapper Test Generator Method
- You must specify a `Class Name Suffix`
- You must specify a `Method Name` that will be used in your test method
- You must set your `TypeClass` and `EntityClass`, they are required in any mapper.