Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fabasoad/pojo

POJO testing library that help you to avoid boilerplate code to test your POJO classes
https://github.com/fabasoad/pojo

java pojo pojo-tester pojo-testing

Last synced: 2 months ago
JSON representation

POJO testing library that help you to avoid boilerplate code to test your POJO classes

Awesome Lists containing this project

README

        

# POJO testing library

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)
![GitHub release](https://img.shields.io/github/v/release/fabasoad/pojo?include_prereleases)
![unit-tests](https://github.com/fabasoad/pojo/actions/workflows/unit-tests.yml/badge.svg)
![security](https://github.com/fabasoad/pojo/actions/workflows/security.yml/badge.svg)
![linting](https://github.com/fabasoad/pojo/actions/workflows/linting.yml/badge.svg)
[![Known Vulnerabilities](https://snyk.io/test/github/fabasoad/pojo/badge.svg)](https://snyk.io/test/github/fabasoad/pojo)

## Import

1. Add [GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry#authenticating-to-github-packages)
maven server to `pom.xml`
2. Import `pojo` dependency.

### Maven

```xml

io.fabasoad
pojo
0.2.1

```

## Examples

### Java

```java
public class PojoTest {
// The package to test
private static final String PACKAGE_NAME = "io.fabasoad.pojo";

@Test
public void testPojoStructureAndBehavior() {
final PojoValidator validator = PojoValidatorBuilder.create(PACKAGE_NAME)
.with(new GettersTester(new GettersMustExistRule()))
.with(new FieldsTester(
new FieldsMustBeFinalRule(),
new FieldsMustBePrivateRule()))
.build();

validator.validate();
}
}
```

### Groovy

```groovy
class PojoSpec extends Specification {
// The package to test
def PACKAGE_NAME = "io.fabasoad.pojo";

def "Getters and fields must follow the rules"() {
given:
def builder = PojoValidatorBuilder.create(PACKAGE_NAME)

when:
def validator = builder
.with(new GettersTester(new GettersMustExistRule()))
.with(new FieldsTester(
new FieldsMustBeFinalRule(),
new FieldsMustBePrivateRule()))
.build()

then:
validator.validate()
}
}
```