Skip to content

marmer/JPojoAssert

Repository files navigation

CI-Build Maven Central

Quality Gate Status Code Coverage Technical Dept

Security Rating Maintainability Reliability

JPojoAssert

This library provides the generation of fluent, atomic assertion classes for pojos, beans, models, entities, or whatever you want to call your object (especially with properties). All this happens without the need to pollute the production code with annotations. And can be used as an adon for all java testing frameworks.

Bonus: Because this library is an annotation processor, you can use it without any plugins for your IDE or build tool as long as annotation processing is supported (so even with plain javac)

Sample/Getting Started:

Att the following dependency to your pom

        <dependency>
            <artifactId>JPojoAssert-processor</artifactId>
            <groupId>io.github.marmer.testutils</groupId>
            <version>${JPojoAssert.version}</version>
            <scope>test</scope>
        </dependency>

Create some Types:

        // Some possible Pojos, Beans, Models, Entities, Objects, Types, ...
        public class SomePojo{
                private String firstName;
                public String getFirstName(){
                        return firstName;
                }
        }
        
        public interface SomePojo{
                String getFirstName();
        }

Configure the generation for the types:

@GenerateAsserter({
        "io.github.marmer", //Package Configuration
        "io.github.marmer.SomePojo" //Qualified type name configuration
})
class JPojoAssertConfiguration {}

Enjoy some readable compile safe assertions for your configured types:

        // Sample Assertion related to "SomePojo"        
        SomePojoAsserter.prepareFor(pojo)
            .with( it -> assertThat(it, hasProperty("notExistingProperty")) )  // Custom assertion related to the pojo itself (Here you can do annything and assert in any way you want. E.g. use assertThat from Hamcrest, AssertJ or Truth)
            .matches(hasProperty("notExistingProperty")) //Ability to pass Hamcrest Matchers for the Pojo itself
            .withFirstName(it -> assertThat(it, equalTo("Some value"))) // Custom assertion related to the property (Here you can do annything and assert in any way you want. E.g. use assertThat from Hamcrest, AssertJ or Truth)
            .hasFirstName("Some value") // Equals Check for the value of the related property of the pojo            
            .withFirstName(equalTo("Some value")) // Hamcrest check for the value of the related property of the pojo 

//Still Work in Progress
            .hasFirstName() // Check whether the passed pojo has a property
//Still Work in Progress
            .isInstanceOfSomePojo() // Optional Check whether it is an instance related to the Base Class the Asserter was created of

            .assertAll() // Soft assertion for an atomic result (you could also use assertToFirstFail() to fail fast)

Changelog

0.7.0

Feature: Nesting of asserters for improved readability are generated for convenience for all properties related to types asserters are generated for.

Assuming you have the following types Person and Address. The following code snipped would perform an assertion all for the persons name, and for the fields street and zip of the field address. So, "it" is in this case an "AddressAsserter".

    PersonAsserter.prepareFor(person)
        .hasName("Einstein")
        .hasAddress(it -> it
            .hasStreet("Mockstreet 1")
            .hasZip("12345"))
        .assertAll()

0.6.0

Feature: Nested (inner) types can be handled now. Nested types will produce nested asserters if they are accessable somehow

0.5.2

Fixed: Project Homepage

0.5.1

Fixed: Asserters are generated for generated types as well (except for the self generated ones)

0.5.0

Feature: Generation inherited properties

 asserter.matches(hasProperty("notExistingProperty"))

0.4.0

Feature: Generation inherited properties

0.3.0

Feature: ability to assert for equality of property values e.g.:

 asserter.withFirstName("Some value")

0.2.1

Fix: Interopt with Java Fix: Changelog added Fix: generic version in Readme sample dependency

0.2.0

Feature: Generation of convenience methods for properties with hamcrest matchers e.g.:

asserter.withFirstName(equalTo("Some value")))

0.1.1

Fix: Property names in error messages

0.1.0

Feature: Simple generation of Asserter classes e.g.:

SomePojoAsserter.prepareFor(pojo).with( it -> assertThat(it, hasProperty("notExistingProperty")) )  // Custom assertion related to the pojo itself (Here you can do annything and assert in any way you want. E.g. use assertThat from Hamcrest, AssertJ or Truth))

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published