A lightweight, zero-dependency, expressive Java library for pure input assertions.
Ensure your code is Always Valid with a fluent and readable API, perfect for domain invariants or input validation in any layer.
- π« Zero Dependencies β Pure Java, no transitive pollution
- π― Typed Exceptions β Get
StringTooShortExceptioninstead ofIllegalArgumentException - π Rich Metadata β Exceptions contain field name, invalid value, and constraints
- π Fluent API β Chainable, expressive, self-documenting code
- ποΈ DDD Ready β Perfect for domain invariants in Clean Architecture
dependency>
groupId>io.github.sympolgroupId>
artifactId>pure-assertartifactId>
version>1.0.0version>
dependency>
implementation 'io.github.sympol:pure-assert:1.0.0'
import io.github.sympol.pure.asserts.Assert;
public class User {
private final String email;
private final int age;
public User(String email, int age) {
this.email = Assert.field("email", email)
.notBlank()
.email()
.value(); // Returns the validated value
this.age = Assert.field("age", age)
.min(18)
.max(120)
.value();
}
}
| Type | Available Methods |
|---|---|
| Strings | notBlank(), minLength(n), maxLength(n), matches(pattern), email(), url(), satisfies(predicate) |
| Numbers | min(n), max(n), positive(), strictlyPositive(), satisfies(predicate) |
| Collections | notEmpty(), maxSize(n), noNullElement() |
| Dates | inPast(), inFuture(), after(date), before(date) |
| UUID | isValid(), isVersion(v), isNotNil() |
Extend the validation chain using satisfies:
Assert.field("username", username)
.notBlank()
.satisfies(u -> u.startsWith("user_"), "Username must start with 'user_'");
| Feature | Pure Assert | Guava / Apache | Jakarta Validator |
|---|---|---|---|
| Dependencies | Zero | Heavy | Heavy |
| API Style | Fluent | Static | Annotations |
| Typed Exceptions | β Yes | β No | β No |
| Rich Metadata | β Yes | Limited | Yes |
| Clean Domain | β Perfect | Acceptable | Poor |
|
|
π‘ For API or UI validation, consider Jakarta Validation (Bean Validation) instead.
To use this library while enforcing a “Zero Dependency” rule in your domain layer:
plugin>
groupId>org.apache.maven.pluginsgroupId>
artifactId>maven-enforcer-pluginartifactId>
version>3.0.0version>
executions>
execution>
id>enforce-no-external-depsid>
goals>
goal>enforcegoal>
goals>
configuration>
rules>
bannedDependencies>
excludes>
exclude>*exclude>
excludes>
includes>
include>*:*:*:*:testinclude>
include>io.github.sympol:pure-assertinclude>
includes>
bannedDependencies>
rules>
configuration>
execution>
executions>
plugin>
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
This project is licensed under the Apache License 2.0 – see the LICENSE file for details.