All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.n2oapp.framework.api.util.N2oTestUtil Maven / Gradle / Ivy

There is a newer version: 7.28.2
Show newest version
package net.n2oapp.framework.api.util;

import net.n2oapp.framework.api.exception.N2oException;

import java.util.function.Consumer;

/**
 * @author operehod
 * @since 13.04.2015
 */
public class N2oTestUtil {

    public static void assertOnException(Closure closure, Class clazz) {
        assertOnException(closure, clazz, e -> {
        });
    }

    public static void assertOnN2oException(Closure closure) {
        assertOnException(closure, N2oException.class);
    }

    @SuppressWarnings("unchecked")
    public static  void assertOnException(Closure closure, Class clazz, Consumer checker) {
        boolean result = false;
        try {
            closure.call();
        } catch (Exception e) {
            result = clazz.isAssignableFrom(e.getClass());
            checker.accept((T) e);
        }
        assert result;
    }



    public static void assertOnSuccess(Closure closure) {
        boolean result = true;
        try {
            closure.call();
        } catch (Exception e) {
            result = false;
        }
        assert result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy