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

net.n2oapp.properties.test.TestUtil Maven / Gradle / Ivy

There is a newer version: 7.28.2
Show newest version
package net.n2oapp.properties.test;

import java.util.function.Consumer;

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

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


    @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;
    }

    public interface Closure {

        void call();

    }



}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy