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)
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)
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()
Feature: Nested (inner) types can be handled now. Nested types will produce nested asserters if they are accessable somehow
Fixed: Project Homepage
Fixed: Asserters are generated for generated types as well (except for the self generated ones)
Feature: Generation inherited properties
asserter.matches(hasProperty("notExistingProperty"))
Feature: Generation inherited properties
Feature: ability to assert for equality of property values e.g.:
asserter.withFirstName("Some value")
Fix: Interopt with Java Fix: Changelog added Fix: generic version in Readme sample dependency
Feature: Generation of convenience methods for properties with hamcrest matchers e.g.:
asserter.withFirstName(equalTo("Some value")))
Fix: Property names in error messages
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))