No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Different Java utility

Build Status Maven Central

This is a utility for simplifying the writing of tests.

Getting started




Guard helps you, when you need to check a some boolean condition and expect a throws Exception if condition is false.

Guard.check( 02 + 010 != 12, CruelJavaWorldException.class, "ooops");

Guard.check( object != null, WrongArgumentException.class, "Object must be not null");

Guard check

You can use this tool while writing a test, to make tests for a checking throw of the exception more readable.

public void guardWithoutErrorInfo() {

    GuardCheck.check(() -> { throw new IndexOutOfBoundsException(); },

public void testGuardCheck() {

    GuardCheck.check(() -> {
                         throw new NotFoundException(TestErrorInfo.TEST_ERROR);


You can use it with an ErrorInfo to accumulate all you domain specific exceptions in an one enum-file:

public enum TestErrorInfo implements ErrorInfo {
    TEST_ERROR_ARG("wrong arg");

    private static final int BASE = 1000;
    private final String msg;

    TestErrorInfo(String msg) {
        this.msg = msg;

    public String getMessage() {
        return this.msg;

    public Integer getCode() {
        return BASE + ordinal();

and sample of a test case :

Guard.check(a != b, TestErrorInfo.TEST_ERROR);

Collision Detector for ErrorInfos

In order to ensure the uniqueness of codes in a whole project, you can use enums which implements an ErrorInfo interface.

public void assertInPackage() {   
    // Act & assert

Utils to work with Garbage Collector


You can use this tool to run the garbage collector and finalize unused memory in your junit tests.

public void testWeakAfterGC() {
    // Arrange
    String instance = new String("123");
    WeakReference<String> ref = new WeakReference<>(instance);

    // Act
    instance = null;

    // Asserts

Simple memory LeakDetector

You can check a memory leak in your code for a particular object.

    public void testWithLeak() {
        // Arrange
        Foo foo = new Foo();
        Foo bar = foo;
        LeakDetector leakDetector = new LeakDetector(foo);

        // Act
        foo = null;

        // Asserts