Generator fake objects from a template

Overview

Fixture Factory

Build Status codecov

Fixture Factory is a tool to help developers quickly build and organize fake objects for unit tests. The key idea is to create specification limits of the data (templates) instead of hardcoded data. Try using F-F, then you can focus on the behavior of your methods and we manage the data.

Installing

Use it like a maven dependency on your project

<dependency>
	<groupId>br.com.six2six</groupId>
	<artifactId>fixture-factory</artifactId>
	<version>3.1.0</version>
</dependency>

Usage

Writing template rules

Fixture.of(Client.class).addTemplate("valid", new Rule(){{
	add("id", random(Long.class, range(1L, 200L)));
	add("name", random("Anderson Parra", "Arthur Hirata"));
	add("nickname", random("nerd", "geek"));
	add("email", "${nickname}@gmail.com");
	add("birthday", instant("18 years ago"));
	add("address", one(Address.class, "valid"));
}});

Fixture.of(Address.class).addTemplate("valid", new Rule(){{
	add("id", random(Long.class, range(1L, 100L)));
	add("street", random("Paulista Avenue", "Ibirapuera Avenue"));
	add("city", "São Paulo");
	add("state", "${city}");
	add("country", "Brazil");
	add("zipCode", random("06608000", "17720000"));
}});

You can also create a new template based on another existing template. Using this you can override the definition for a property

Fixture.of(Address.class).addTemplate("augustaStreet").inherits("valid", new Rule(){{
	add("street", "Augusta Street");
}});

Using on your tests code:

Gimme one object from label "valid"

Client client = Fixture.from(Client.class).gimme("valid");

Gimme N objects from label "valid"

List<Client> clients = Fixture.from(Client.class).gimme(5, "valid");

Gimme N objects each one from one label

List<Client> clients = Fixture.from(Client.class).gimme(2, "valid", "invalid");

Additional helper functions to create generic template:

Managing Templates

Templates can be written within TemplateLoader interface

public class ClientTemplateLoader implements TemplateLoader {
    @Override
    public void load() {
        Fixture.of(Client.class).addTemplate("valid", new Rule(){{
            add("id", random(Long.class, range(1L, 200L)));
            add("name", random("Anderson Parra", "Arthur Hirata"));
            add("nickname", random("nerd", "geek"));
            add("email", "${nickname}@gmail.com");
            add("birthday", instant("18 years ago"));
            add("address", one(Address.class, "valid"));
        }});

        Fixture.of(Address.class).addTemplate("valid", new Rule(){{
            add("id", random(Long.class, range(1L, 100L)));
            add("street", random("Paulista Avenue", "Ibirapuera Avenue"));
            add("city", "São Paulo");
            add("state", "${city}");
            add("country", "Brazil");
            add("zipCode", random("06608000", "17720000"));
        }});
    }
}

All templates can be loaded using FixtureFactoryLoader telling what package that contains the templates

FixtureFactoryLoader.loadTemplates("br.com.six2six.template");

Example of loading templates with JUnit tests

@BeforeClass
public static void setUp() {
    FixtureFactoryLoader.loadTemplates("br.com.six2six.template");
}

Processors

Fixture-Factory comes with a simple mechanism to execute custom logic after the generation of each object.

To do so, implement the Processor interface:

public class MyCustomProcessor implements Processor {
	public void execute(Object object) {
 		//do something with the created object
	}
}

And use it:

Fixture.from(SomeClass.class).uses(new MyCustomProcessor()).gimme("someTemplate");

The #execute method will be called for each object that Fixture-Factory generates. For instance, if a Client has an Address, the framework will generate the Address, call #execute with the generated Address as argument, set the Address into the Client, call #execute with the generated Client as argument and then return it.

In case you want to persist the generated object in your database and you are using Hibernate, we already have a HibernateProcessor that persists all created objects using the provided session:

Fixture.from(Client.class).uses(new HibernateProcessor(session)).gimme("valid");

Relationship (one-to-one and one-to-many)

Fixture.of(Order.class).addTemplate("valid", new Rule(){{
	add("id", random(Long.class, range(1L, 200L)));
	add("items", has(3).of(Item.class, "valid"));
	// add("items", has(3).of(Item.class, "valid", "invalid", "external")); this will generate three Item, each one from one of the given templates
	add("payment", one(Payment.class, "valid"));
}});

Fixture.of(Item.class).addTemplate("valid", new Rule(){{
	add("productId", random(Integer.class, range(1L, 200L)));
}});

Fixture.of(Payment.class).addTemplate("valid", new Rule(){{
	add("id", random(Long.class, range(1L, 200L)));
}});

Regex

Fixture.of(Any.class).addTemplate("valid", new Rule(){{
	add("id", regex("\\d{3,5}"));
	add("phoneNumber", regex("(\\d{2})-(\\d{4})-(\\d{4})"));
});

Date

Fixture.of(Any.class).addTemplate("valid", new Rule(){{
	add("dueDate", beforeDate("2011-04-15", new SimpleDateFormat("yyyy-MM-dd")));
	add("payDate", afterDate("2011-04-15", new SimpleDateFormat("yyyy-MM-dd")));
	add("birthday", randomDate("2011-04-15", "2011-11-07", new SimpleDateFormat("yyyy-MM-dd")));
	add("cutDate", instant("now"));
});

Name

Fixture.of(Any.class).addTemplate("valid", new Rule(){{
	add("firstName", firstName());
	add("lastName", lastName());
});

Unique random

Fixture.of(Any.class).addTemplate("valid", new Rule() {{
	add("country", "Brazil");
	add("state", uniqueRandom("São Paulo", "Rio de Janeiro", "Minas Gerais", "Bahia"));
}});

The attribute state of this fixture will contain an unique value each time it is generated. Note that if this fixture is generated more times than there are available state values, the state values will start to repeat.

CNPJ

Fixture.of(User.class).addTemplate("valid", new Rule() {{
	add("cnpj", cnpj()); // this will generate an unformatted CNPJ e.g. 11111111111111
	add("cnpj", cnpj(true)); this will generate a formatted CNPJ e.g. 11.111.111/1111-11
}});

You can see more utilization on tests!

Contributing

Want to contribute with code, documentation or bug report?

Do it by joining the mailing list on Google Groups.

Credits

Fixture-Factory was written by:

with contributions from several authors, including:

License

Fixture-Factory is released under the Apache 2.0 license. See the LICENSE file included with the distribution for details.

Comments
  • Distinct value in one-to-many relationship

    Distinct value in one-to-many relationship

    I'm using Fixture Factory and I have a doubt.

    When using a one-to-many relatorionship we must do this: add("skills", has(2).of(Skill.class, "valid"));

    But this generates duplicated skills and I don't want then to be repeated.

    Is there an option to generate no duplicated value?

    Thanks!

    opened by viniciusffj 10
  • Support jdk8 classes using lambdas

    Support jdk8 classes using lambdas

    This PR is being submitted as means to solve issue #90. A quick summary of what I did in the PR:

    1. Upgraded Paranamer library to 2.8
    2. Moved target and sorce java version to 1.8 (JDK 8) to use lambdas in tests.
    3. Added tests to make sure that classes with lambda expressions will work with fixture-factory.

    If I am supposed to do improvements or fix any kind of error let me know.

    opened by pedro-stanaka 9
  • list with different elements

    list with different elements

    Just started using this framework and I didn't realize how to create a list with different elements. I think this is not possible, right? Something like this:

    add("items", has(2).of(Item.class, "itemOne", "itemTwo");

    opened by wagnerfrancisco 8
  • Added a cache for factories requested in Fixture.from static method.

    Added a cache for factories requested in Fixture.from static method.

    A ObjectFactory operates like a singleton for each class when was created in Fixture.from static method. Example:

    Entity e1 = Fixture.from(Entity.class).gimme("valid");
    Entity e2 = Fixture.from(Entity.class).gimme("valid");
    

    This snippet call a Fixture.from method twice and create two ObjectFactory for two diferent fixtures from Entity. Two identical factory was created under the same TemplateHolder object provided by templates map in Fixture class. Even with no expansive computations theres no need to create a ObjectFactory in each call of Fixture.from. With this modification, a single ObjectFactory is created and two different fixtures for the Entity class.

    opened by quikkoo 6
  • Enum support

    Enum support

    Thanks for the cool library!

    Would be cool if the library could create enums:

    public enum Foo {
       Bar, Baz;
    }
    
    Fixture.of(Foo.class).addTemplate(new Rule() {{
        oneOf(Bar, Baz);
    }});
    
    Fixture.from(Foo.class).gimme("random");
    
    opened by Entea 5
  • Unique random function

    Unique random function

    When using Fixture Factory I felt the need for a function capable of generating unique random values (that is, a function that generates in each call a value different from those it has already generated in previous calls).

    I created then a function which can generate unique random values from a fixed array of values, from a range of integers, or from the values of an Enum.

    The method used to guarantee that each call to generateValue() produces an unique value is the Fisher-Yates shuffle (http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm). When the unique random function is initialized, it generates an array composed of all the possible values that can be generated and then shuffles the array using the FIsher-Yates method. The function then returns those values in order, as they are requested.

    The drawback of this is method is that it may consume too much memory if the user specifies a large range of values as the dataset. However, I have chosen not to impose a fixed limit to this range, for two reasons: firstly, I wouldn't know what arbitrary number to choose for the limit; secondly, I believe that whoever wants an unique sequence of values probably doesn't want too many values to be generated (the use case I have in mind is something like choosing from a list of countries, for instance).

    I also chose not to extend the existing RandomFunction because I felt that there is nothing in RandomFunction that my new function could reuse.

    opened by Tavio 5
  • Big decimal range

    Big decimal range

    Hi Fixture Factory community,

    This pull request is regarding issue #61. To Implement this, I had to change both the BigDecimal and BigInteger features but I believe it will be ok since I was able to write tests for both cases. I also noticed a little typo in README tutorial so I fixed it.

    There are tests failing in master branch but I couldn't figure out what it was about so I didn't fixed it, the tests are:

    • shouldCreateImmutableObjectUsingCorrectPartialConstructor
    • shouldCreateImmutableObjectUsingAnotherPartialConstructor
    opened by csrcordeiro 5
  • add support for properties with SortedSet and other collection datatype

    add support for properties with SortedSet and other collection datatype

    When execute fixture, following exception is displayed:

    target = {java.lang.ClassCastException@1827}"java.lang.ClassCastException: Cannot cast java.util.HashSet to java.util.SortedSet"

    public class Father {
        private SortedSet<Son> children = new TreeSet<>();
    }
    
    Fixture.of(Father.class).addTemplate("valid", new Rule() {
                {
                    add("children", has(1).of(Son.class, "valid"));
                }
            });
    

    Is it can add support for other collection beyond Set?

    protected TransformerChain buildTransformerChain(Transformer transformer) {
            TransformerChain transformerChain = new TransformerChain(transformer);
    
            transformerChain.add(new CalendarTransformer());
            transformerChain.add(new SetTransformer());
            transformerChain.add(new PrimitiveTransformer());
            transformerChain.add(new WrapperTransformer());
    
            return transformerChain;
        }
    

    Or get implementation class from Set interface, instead of create HashSet:

    public <T> T transform(Object value, Class<T> type) {
            return type.cast(new HashSet((Collection) value));
        }
    
    opened by paulovitor 5
  • fixing template where we want to override nested attribute value

    fixing template where we want to override nested attribute value

    In immutable objects, when we try to override a nested attribute in the gimme call it doesn't work.

    Now, after create the object with all property definitions, we take the properties that were not used in the constructor and starting processing then as deferred properties.

    @ahirata @aparra can you guys review it please?

    After merging it I'm going to release a fix version 2.2.1

    opened by nykolaslima 4
  • Order rules by dependencies

    Order rules by dependencies

    Today we have the following problem:

    Fixture.of(User.class).addTemplate("valid", new Rule() {{
    add("email", "${name}@gmail.com");
    add("name", random("nykolas", "otavio"));
    }};
    

    The above code fails because email depends on name but when email is evaluated, name was not evaluated yet.

    @Tavio has solved this problem on Angular-Fixture-Factory(https://github.com/Tavio/angular-fixture-factory) project using Topological sort(http://en.wikipedia.org/wiki/Topological_sorting) https://github.com/Tavio/angular-fixture-factory/blob/master/angular-fixture-factory.js#L264-L312

    We can use the same approach here.

    opened by nykolaslima 4
  • Regex Problem

    Regex Problem

    Regex invalid?

        Fixture.of(User.class).addTemplate("valid", new Rule(){{
            add("name",regex("[A-Z]"));
        }});
    

    Problem:

    java.util.regex.PatternSyntaxException: Unclosed character class near index 3 [A-Z ^ at java.util.regex.Pattern.error(Pattern.java:1924) at java.util.regex.Pattern.clazz(Pattern.java:2493) at java.util.regex.Pattern.sequence(Pattern.java:2030) at java.util.regex.Pattern.expr(Pattern.java:1964) at java.util.regex.Pattern.compile(Pattern.java:1665) at java.util.regex.Pattern.(Pattern.java:1337) at java.util.regex.Pattern.compile(Pattern.java:1022) at br.com.six2six.bfgex.interpreter.Parser.parse(Parser.java:34) at br.com.six2six.bfgex.interpreter.Parser.parse(Parser.java:113) at br.com.six2six.bfgex.RegexGen.of(RegexGen.java:8) at br.com.six2six.fixturefactory.function.impl.RegexFunction.generateValue(RegexFunction.java:17) at br.com.six2six.fixturefactory.Property.getValue(Property.java:37) at br.com.six2six.fixturefactory.ObjectFactory.generateConstructorParamValue(ObjectFactory.java:180) at br.com.six2six.fixturefactory.ObjectFactory.processArguments(ObjectFactory.java:208) at br.com.six2six.fixturefactory.ObjectFactory.processConstructorArguments(ObjectFactory.java:186) at br.com.six2six.fixturefactory.ObjectFactory.createObject(ObjectFactory.java:108) at br.com.six2six.fixturefactory.ObjectFactory.createObjects(ObjectFactory.java:137) at br.com.six2six.fixturefactory.ObjectFactory.gimme(ObjectFactory.java:71) at br.com.six2six.fixturefactory.function.FixtureFunction.gimmeWithQuantity(FixtureFunction.java:65) at br.com.six2six.fixturefactory.function.FixtureFunction.generate(FixtureFunction.java:56) at br.com.six2six.fixturefactory.function.FixtureFunction.generateValue(FixtureFunction.java:45) at br.com.six2six.fixturefactory.function.impl.AssociationFunctionImpl.generateValue(AssociationFunctionImpl.java:49) at br.com.six2six.fixturefactory.Property.getValue(Property.java:45) at br.com.six2six.fixturefactory.ObjectFactory.processPropertyValue(ObjectFactory.java:230) at br.com.six2six.fixturefactory.ObjectFactory.createObject(ObjectFactory.java:116) at br.com.six2six.fixturefactory.ObjectFactory.gimme(ObjectFactory.java:58) at br.com.silvanopessoa.rest.model.UsuarioTest.loadUsuario(UsuarioTest.java:56) at br.com.silvanopessoa.rest.model.UsuarioTest.deve_gerar_um_usuario_valido(UsuarioTest.java:116) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

    opened by silvanopessoa 3
  • Bump hibernate-core from 4.2.3.Final to 5.4.24.Final

    Bump hibernate-core from 4.2.3.Final to 5.4.24.Final

    Bumps hibernate-core from 4.2.3.Final to 5.4.24.Final.

    Release notes

    Sourced from hibernate-core's releases.

    Hibernate ORM 5.2.0

    5.2.0 includes many improvements and bug-fixes. For a complete list of changes, see https://hibernate.atlassian.net/projects/HHH/versions/23150/tab/release-report-done.

    Many of the changes in 5.2.0 have important ramifications in terms of both usage and extension. Be sure to read the 5.2 Migration Guide for details.

    Below is a discussion of the major changes.

    Java 8 baseline

    5.2 moves to Java 8 as its baseline. This means:

    • The hibernate-java8 module has been removed, and that functionality has been moved into hibernate-core.
    • Native support for Java 8 date/time types as Query parameters.
    • Support for streaming (java.util.stream.Stream) query results.
    • Support for java.util.Optional as return from methods that may return null.
    • Leveraging Java 8 "default methods" when introducing new methods to extension points.

    Consolidating JPA support into hibernate-core.

    That effectively means that the hibernate-entitymanager module no longer exists. Its functionality being consumed into hibernate-core.

    JCache support

    Support for using any JCache-compliant cache impl as a second-level caching provider.

    Session-level batch size support

    Support has been added for specifying a batch size for write operations per Session.

    5th bug-fix release for 5.0

    The 5th bug-fix release for Hibernate ORM 5.0. This release and the upcoming 5.0.6 release have been done on an accelerated time-box of 2 weeks (from the normal 4 weeks for bug-fix releases) due to US holidays.

    The complete list of changes can be found here (or here for people without a Hibernate Jira account).

    For information on consuming the release via your favorite dependency-management-capable build tool, see http://hibernate.org/orm/downloads/

    For those of you allergic to dependency-management-capable build tools, the release bundles can be obtained from SourceForge or BinTray.

    Fourth bug-fix release for 5.0

    The fourth bug-fix release for Hibernate ORM 5.0

    There are 52 issues resolved in this release. 20 of those came out of the recent Jira cleanup. Initially that initiative pulled in roughly 750 issues. To date, 66 of those have been resolved - fixed or verified as out-of-date, unable-to-reproduce, etc. An additional 14 have been more properly reclassified as feature or enhancement requests rather than bugs. The really cool part is the amount of community help we have gotten in making that happen! Thanks to everyone responding, verifying and even fixing alot of these bugs!

    The complete list of changes can be found here. People without a Hibernate Jira account will not be able to access the previous link and can access the changelog in GitHub; the issue I reported with Atlassian has been resolved and is ready for deployment into our hosted environment, I just do not know when that will happen.

    For information on consuming the release via your favorite dependency-management-capable build tool, see http://hibernate.org/orm/downloads/

    For those of you allergic to dependency-management-capable build tools, the release bundles can be obtained from SourceForge or BinTray.

    Third bug-fix release for 5.0

    http://in.relation.to/2015/10/28/hibernate-orm-503-final-release/

    ... (truncated)

    Changelog

    Sourced from hibernate-core's changelog.

    Changes in 5.4.24.Final (November 17, 2020)

    https://hibernate.atlassian.net/projects/HHH/versions/31892

    ** Bug * [HHH-14333] - Pessimistic Lock causes FOR UPDATE on outer join statements * [HHH-14329] - DirtinessTracker usage for enhanced entities doesn't respect mutable types * [HHH-14322] - HBM many-to-one property-ref broken since 5.3.2 due to HHH-12684 * [HHH-14317] - Avoid closing datasource in AgroalConnectionProvider if datasource is not initialized * [HHH-14316] - Avoid accessing state in DriverManagerConnectionProviderImpl if null * [HHH-14312] - Padded batch style entity loader ignores entity graph * [HHH-14310] - Document hibernate.query.in_clause_parameter_padding * [HHH-14288] - Complex batch insert query stopped to work * [HHH-14279] - Broken 'with key(...)' operator on entity-key maps * [HHH-14276] - Nested ID class using derived identifiers fails with strange AnnotationException: unable to find column reference in the @​MapsId mapping: game_id * [HHH-14257] - An Entity A with a map collection having as index an Embeddable with a an association to the Entity A fails with a NPE * [HHH-13310] - getParameterValue() not working for collections

    ** Improvement * [HHH-14332] - Make it easier for Quarkus SPI to avoid loading XML * [HHH-14325] - Add Query hint for specifying "query spaces" for native queries * [HHH-14158] - Upgrade Javassist to the latest version

    ** Task * [HHH-14324] - Add .gradletasknamecache to .gitignore * [HHH-14309] - Improve BulkOperationCleanupAction#affectedEntity * [HHH-14225] - CVE-2020-25638 Potential for SQL injection on use_sql_comments logging enabled

    Changes in 5.4.23.Final (November 01, 2020)

    https://hibernate.atlassian.net/projects/HHH/versions/31887

    ** Bug * [HHH-14279] - Broken 'with key(...)' operator on entity-key maps * [HHH-14275] - Broken link to Infinispan User Guide in Hibernate 5.3 User Guide * [HHH-14260] - Dead links in user guide * [HHH-14259] - HHH-13980 is not merged into 5.4 * [HHH-14249] - MultiLineImport fails when script contains blank spaces or tabs at the end of the last sql statement * [HHH-14247] - Automatic release scripts, wrong Jira release url * [HHH-14227] - Insert statements are not ordered with entities that use inheritance and reference a subclass

    ** Improvement * [HHH-14305] - Analyse retained heap after bootstrap to trim memory consumption * [HHH-14304] - Replacing eager initialization of LockingStrategy within AbstractEntityPersister * [HHH-14303] - Upgrade to JBoss Loging 3.4.1.Final * [HHH-14302] - Upgrade to Agroal 1.9 * [HHH-14301] - Upgrade to Byte Buddy 1.10.17

    ... (truncated)

    Commits
    • 0b5d3a2 5.4.24.Final
    • 33123d2 HHH-14333 Pessimistic Lock causes FOR UPDATE on outer join statements
    • 84e37c1 HHH-14332 Make it easier for Quarkus SPI to avoid loading XML related resources
    • da8706e HHH-14329 Amend existing DirtyTrackingTest
    • 2669848 HHH-14329 consider mutable types always as potentially dirty when using Dirti...
    • 5ea0d92 HHH-14329 test case showing that DirtinessTracker usage for enhanced entities...
    • c444d5f HHH-14325 - Add Query hint for specifying "query spaces" for native queries
    • 49ae7bd HHH-14325 - Add Query hint for specifying "query spaces" for native queries
    • fe2230f HHH-14276 Amend style and formatting
    • a8fdb4d HHH-14276 Avoid quoting column name for looking up references during composit...
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump junit from 4.12 to 4.13.1

    Bump junit from 4.12 to 4.13.1

    Bumps junit from 4.12 to 4.13.1.

    Release notes

    Sourced from junit's releases.

    JUnit 4.13.1

    Please refer to the release notes for details.

    JUnit 4.13

    Please refer to the release notes for details.

    JUnit 4.13 RC 2

    Please refer to the release notes for details.

    JUnit 4.13 RC 1

    Please refer to the release notes for details.

    JUnit 4.13 Beta 3

    Please refer to the release notes for details.

    JUnit 4.13 Beta 2

    Please refer to the release notes for details.

    JUnit 4.13 Beta 1

    Please refer to the release notes for details.

    Commits
    • 1b683f4 [maven-release-plugin] prepare release r4.13.1
    • ce6ce3a Draft 4.13.1 release notes
    • c29dd82 Change version to 4.13.1-SNAPSHOT
    • 1d17486 Add a link to assertThrows in exception testing
    • 543905d Use separate line for annotation in Javadoc
    • 510e906 Add sub headlines to class Javadoc
    • 610155b Merge pull request from GHSA-269g-pwp5-87pp
    • b6cfd1e Explicitly wrap float parameter for consistency (#1671)
    • a5d205c Fix GitHub link in FAQ (#1672)
    • 3a5c6b4 Deprecated since jdk9 replacing constructor instance of Double and Float (#1660)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • What to expect for the future of the FixtureFactory?

    What to expect for the future of the FixtureFactory?

    The fixture-factory is deprecated? I really like the tool... but it is not having upgrades. In fact, I noticed that there has been no commit for 14 months. Should I continue using it in my projects?

    Below is a list of improvements that I propose and could help to develop.

    1. Update the source code to Java11 mvn test its only working on Java8 and it is broke on Java11

    2. Support to local variable type inference (var) on from/gimme We inform the class on from method of FixtureFacture, so I imagine something like this:

      private <T> T fromExample(Class<T> clazz) {
        if (String.class.equals(clazz))
          return (T) "Test";
        if (Integer.class.equals(clazz))
          return (T) Integer.valueOf(12);
        return null;
      }
    
      @Test
      public void testGenerics() {
        var str = fromExample(String.class); // ### 
        System.out.println(str.substring(0, 3));
        var num = fromExample(Integer.class); // ### 
        System.out.println(num / 2);
      }
    

    Output:

    Tes
    6
    
    1. The Processors are useful and already working on all situations. But, to simplify, if a class that implements TemplateLoader also implements theProcessor interface, the execute method could be executed when generating the instances. Or the Rule class can have a method postConstruct that I can override (I think I prefer this option) Or another way would be to create a postConstruct annotation like Spring does (This I don't know how to do :sweat_smile:)

    2. The "prefix-${name}" feature is greatting. But it is not possible to do this with instances of other types (non String)

    • There could be a function similar like gimmeReference (" client.adress ")` that returns the instance of an object in another property.
    • But the best solution, in my opinion, would be for FixtureFactory to support Function / Predicate or any other interface for anonymous functions that generate value:
    new Rule() {{
      add("locator", regex("[A-Z0-9]{6}"));
      add("branchId", random(Long.class, range(1L, 100L)));
      add("code", o -> o.getBranchId().toString() + o.locator().replace("[A-Z]", ""));   // here
      add("corporateId", o -> Integer.valueOf(o.getBranchId().toString().charAt(0)));  // and here
    }}
    
    1. It would be very useful to have a way to use the regex orrandom function directly from the test (outside the template) ... for primitive types there is no example of how to do it. I needed this to generate queryParameters and custom headers. But I didn't find any example using FixtureFacture.

    2. Phenomenal the instant("18 years ago") feature. But don't works with LocalDate and LocalDateTime. Ok ... it's easy to solve like with LocalDate.now().minusYears(30). But it is strange to break the execution

    3. When I do something wrong :innocent:, the exception thrown does not inform the attribute name, it only tells the reason.

    The items are in the order I remembered ...

    Congratulations for tool ... I'm putting it on all my projects (at CVC Corp), I don't see anything like what you created anywhere.

    Tell me what you think about the list items. If you liked the suggestions, and will continue to support the tool, I can try to help.

    opened by flaviolsousa 3
  • Bump commons-beanutils from 1.8.3 to 1.9.2

    Bump commons-beanutils from 1.8.3 to 1.9.2

    Bumps commons-beanutils from 1.8.3 to 1.9.2.

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Child class non-empty constructors not found

    Child class non-empty constructors not found

    I was using fixtures with a class with final fields and constructors only, without issue. I had to change this class to an abstract class eventually, but fixtures were not working on the subclasses, throwing Could not find constructor with args [] on class on the child class. While there was no need for an empty constructor on the parent class.

    Workaround: add an empty constructor on the parent class, override it with a private constructor on the child class.

    public abstract class Transaction<T, U> {
        private final String transactionId;
    
       ...
    
        // Needed this to support fixtures
        TransactionHistory() {
            this(null);
        }
    
        TransactionHistory(final String transactionId) {
            this(transactionId);
        }
    }
    
    public class ChargeTransaction extends Transaction<ChargeRequest, ChargeResponse> {
        private ChargeTransaction() {
        }
    }
    
    opened by tikal 3
Releases(3.0.0)
  • 3.0.0(Jan 29, 2015)

    Features

    • has and gimme functions now supports multiple templates
    Fixture.from(User.class).gimme(2, "male", "female");
    
    Fixture.of(User.class).addTemplate("valid", new Rule() {{
      add("addresses", has(2).of(Address.class, "sp", "mg"));
    }});
    
    • adding asString to instant function #58 add("birthdayAsString", instant("18 years ago").asString("dd/MM/yyyy"));
    • uniqueRandom function to generate unique values #70
    • CNPJ function #55 add("cnpj", cnpj());

    Bugfixes

    • Fixing range function with BigDecimal type #69
    • Fixing fixtures for inner classes with construtors in Java 8 935214c
    • Fixing overriding nested attribute in gimme call #73
    • And others...

    Others

    • Little improvements in documentation
    • Functions' package was refactored, this will break people that are importing those functions
    Source code(tar.gz)
    Source code(zip)
    fixture-factory-3.0.0-sources.jar(31.19 KB)
    fixture-factory-3.0.0.jar(59.87 KB)
  • 2.2.0(Apr 25, 2014)

    Features

    • Fixtures can now define Processors that will run after object instantiation. We already provide a HibernateProcessor to load generated fixtures into database, making easy to create integration tests Fixture.from(User.class).uses(new HibernateProcessor(session)).gimme("valid"); //this will generate new User based on valid template and insert it to database through Hibernate
    • Now we have TemplateLoader interface that should be used to declare or templates.
    public class UserTemplateLoader implements TemplateLoader {
      @Override
      public void load() {
        Fixture.of(User.class).addTemplate("valid", new Rule() {{
          add("name", random("Nykolas", "Anderson", "Arthur"));
          ...
        }});
      }
    }
    

    And to load declared templates, we have the new class FixtureFactoryLoader that loads all templates in declared package FixtureFactoryLoader.loadTemplates("br.com.six2six.template");

    • New random function to BigDecimal and BigInteger add("ammount", random(BigDecimal.class, new MathContext(2)));
    • Support to override properties definitions on gimme call #41
    Client client = Fixture.from(User.class).gimme("valid", new Rule() {{
      add("name", "New name only for this client");
    }});
    

    Bugfixes

    • Prioritise default constructor and choose right constructor based on parameter name and type #32
    • Bugfix for attributes on inherited classes #35
    • Reset property on inherited template #38
    • Generate random values for short and byte #41
    • And others...
    Source code(tar.gz)
    Source code(zip)
    fixture-factory-2.2.0.jar(53.15 KB)
Owner
six2six
six2six
A library for setting up Java objects as test data.

Beanmother Beanmother helps to create various objects, simple and complex, super easily with fixtures for testing. It encourages developers to write m

Jaehyun Shin 113 Nov 7, 2022
Arbitrary test data generator for parameterized tests in Java inspired by AutoFixture.

AutoParams AutoParams is an arbitrary test data generator for parameterized tests in Java inspired by AutoFixture. Sometimes setting all the test data

null 260 Jan 2, 2023
A template for Spring Boot REST API tested with JUnit 5 and Cucumber 6

demo-bdd Un template Spring Boot pour lancer un BDD/ATDD avec Cucumber 6 et JUnit 5. Maven et le JDK 17 seront nécessaires. Exécuter les tests Le proj

Rui Lopes 4 Jul 19, 2022
Java fake data generator

jFairy by Devskiller Java fake data generator. Based on Wikipedia: Fairyland, in folklore, is the fabulous land or abode of fairies or fays. Try jFair

DevSkiller 718 Dec 10, 2022
Annotation processor to create immutable objects and builders. Feels like Guava's immutable collections but for regular value objects. JSON, Jackson, Gson, JAX-RS integrations included

Read full documentation at http://immutables.org // Define abstract value type using interface, abstract class or annotation @Value.Immutable public i

Immutables 3.2k Dec 31, 2022
Java 8 optimized, memory efficient, speedy template engine producing statically typed, plain java objects

Rocker Templates by Fizzed Fizzed, Inc. (Follow on Twitter: @fizzed_inc) Sponsored by Rocker is proudly sponsored by Greenback. We love the service an

Fizzed, Inc. 669 Dec 29, 2022
A JNI code generator based on the JNI generator used by the eclipse SWT project

HawtJNI Description HawtJNI is a code generator that produces the JNI code needed to implement java native methods. It is based on the jnigen code gen

FuseSource 153 Nov 17, 2022
Log4j-payload-generator - Log4j jndi injects the Payload generator

0x01 简介 log4j-payload-generator是 woodpecker框架 生产log4 jndi注入漏洞payload的插件。目前可以一键生产以下5类payload。 原始payload {[upper|lower]:x}类型随机混payload {[upper|lower]:x}

null 469 Dec 30, 2022
OpenApi Generator - REST Client Generator

Quarkus - Openapi Generator Welcome to Quarkiverse! Congratulations and thank you for creating a new Quarkus extension project in Quarkiverse! Feel fr

Quarkiverse Hub 46 Jan 3, 2023
Te4j (Template Engine For Java) - Fastest and easy template engine

Te4j About the project Te4j (Template Engine For Java) - Fastest and easy template engine Pros Extremely fast (127k renders per second on 4790K) Easy

Lero4ka16 19 Nov 11, 2022
cglib - Byte Code Generation Library is high level API to generate and transform Java byte code. It is used by AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.

cglib Byte Code Generation Library is high level API to generate and transform JAVA byte code. It is used by AOP, testing, data access frameworks to g

Code Generation Library 4.5k Jan 8, 2023
sql2o is a small library, which makes it easy to convert the result of your sql-statements into objects. No resultset hacking required. Kind of like an orm, but without the sql-generation capabilities. Supports named parameters.

sql2o Sql2o is a small java library, with the purpose of making database interaction easy. When fetching data from the database, the ResultSet will au

Lars Aaberg 1.1k Dec 28, 2022
A Java serialization/deserialization library to convert Java Objects into JSON and back

Gson Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to a

Google 21.7k Jan 8, 2023
A Java library for serializing objects as PHP serialization format.

Java PHP Serializer Latest release: A Java library for serializing objects as PHP serialization format. The library fully implements the PHP serializa

Marcos Passos 14 Jun 13, 2022
A library for setting up Java objects as test data.

Beanmother Beanmother helps to create various objects, simple and complex, super easily with fixtures for testing. It encourages developers to write m

Jaehyun Shin 113 Nov 7, 2022
ObjectBox is a superfast lightweight database for objects

ObjectBox Java (Kotlin, Android) ObjectBox is a superfast object-oriented database with strong relation support. ObjectBox is embedded into your Andro

ObjectBox 4.1k Dec 30, 2022
Text Object Java Objects (TOJOs): an object representation of a multi-line structured text file like CSV

It's a simple manager of "records" in a text file of CSV, JSON, etc. format. It's something you would use when you don't want to run a full database,

Yegor Bugayenko 19 Dec 27, 2022
An object mapping jetbrains plugin, it will automatically generate the get/set code between the two objects.

BeanMappingKey 简体中文 | English 一键生成两个实体类之间的字段映射代码,用于代替 BeanUtil 与 MapStruct 等工具。 使用指南 在 Java 开发的过程中,经常会使用众多包装型的对象如:BO、VO、DTO,它们之间往往只有两三个字段的差异, 而对它们进行相互

Rookie 60 Dec 14, 2022