Prototype

The small library for creating object by class and fill it random data for easy-test.

License

License

GroupId

GroupId

com.github.nmuzhichin
ArtifactId

ArtifactId

prototest
Last Version

Last Version

1.0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Prototype
The small library for creating object by class and fill it random data for easy-test.

Download prototest

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.nmuzhichin/prototest/ -->
<dependency>
    <groupId>com.github.nmuzhichin</groupId>
    <artifactId>prototest</artifactId>
    <version>1.0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.nmuzhichin/prototest/
implementation 'com.github.nmuzhichin:prototest:1.0.2.0'
// https://jarcasting.com/artifacts/com.github.nmuzhichin/prototest/
implementation ("com.github.nmuzhichin:prototest:1.0.2.0")
'com.github.nmuzhichin:prototest:jar:1.0.2.0'
<dependency org="com.github.nmuzhichin" name="prototest" rev="1.0.2.0">
  <artifact name="prototest" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.nmuzhichin', module='prototest', version='1.0.2.0')
)
libraryDependencies += "com.github.nmuzhichin" % "prototest" % "1.0.2.0"
[com.github.nmuzhichin/prototest "1.0.2.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.apache.commons : commons-lang3 jar 3.9
org.slf4j : slf4j-api jar 1.7.26
com.fasterxml.jackson.core : jackson-databind jar 2.9.10.1

provided (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api Optional jar 5.4.2

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-engine jar 5.4.2
com.fasterxml.jackson.core : jackson-core jar 2.9.8

Project Modules

There are no modules declared in this project.

Prototest

The small library for creating object by class and fill it random data for easy testing.

From 1.0.2.0 version, you can use annotation with Junit5 extension.

Requirements

  • JDK >= 8
  • Maven >= 3

Maven configuration

Add the Maven dependency:

<dependency>
  <groupId>com.github.nmuzhichin</groupId>
  <artifactId>prototest</artifactId>
  <version>1.0.2.0</version>
  <scope>test</scope>
</dependency>

How to use

Entry point is Prototest class that has methods for creating lazy pipeline.

Method execute() run pipeline and take ready to use object.

Sample

  • Generate empty pipeline and run it:
final Empty empty = Prototest.empty().execute();
  • Now take by class:
final SomethingClass newObj = Prototest.now(SomethingClass.class);
  • Uses flatten, identity, logs methods:
final SomethingClass obj = Prototest
                                    .configure()
                                    .fromClass(SomethingClass.class)
                                    .flatten(it -> Prototest.configure()
                                                            .fromClass(SimpleObject.class)
                                                            .side(q -> q.setName(it)))
                                    .log()
                                    .execute();
  • Complex generate with configuration and listeners:
final TypeListener listener = type -> String.class == type ? RandomStringUtils.randomNumeric(12) : null;

Prototest
         .configure(config -> config.addImplementationFor(CustomInterface.class, new CustomInterfaceAbstractImpl("123")))
         .registerContainerListener(ContainerPhase.OBJECT_EMMIT, System.out::println)
         .registerTypesListener(TypePhase.CONSTRUCTOR_ARGS, listener)
         .fromClass(ComplexObject.class)
         .log()
         .assertions(it -> it.as().nonNull())
         .execute();

Annotation sample (from 1.0.2.0)

@ExtendWith(PrototestExtension.class)
@PrototestImplementations({
        @PrototestImplementation(className = String.class, value = "123456"),
        @PrototestImplementation(className = Integer.class),
        @PrototestImplementation(className = Byte.class, value = "123"),
})
public class ExtensionTest {

    private final ComplexObject object;

    @AsPrototest
    private ComplexObject object2;

    public ExtensionTest(@AsPrototest final ComplexObject object) {
        this.object = object;
    }

    @Test
    void t(@AsPrototest(DefaultConfig.DEFAULT) ComplexObject methodArg) {
        Assertions.assertNotNull(methodArg);
        Assertions.assertNotNull(object);
        Assertions.assertNotNull(object2);
    }
}
See more in test

Versions

Version
1.0.2.0
1.0.0.1