io.github.lunkesapps.MultiErrorCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of MultiErrorCheckJava8 Show documentation
Show all versions of MultiErrorCheckJava8 Show documentation
Library for MultiErrors Check For Java 8
The newest version!
package io.github.lunkesapps;
import org.hamcrest.Matcher;
import org.junit.runners.model.MultipleFailureException;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import static org.hamcrest.MatcherAssert.assertThat;
public class MultiErrorCheck {
private ArrayList errors = new ArrayList<>();
private ArrayList callables = new ArrayList<>();
public void addCheck(T actual, Matcher matcher) {
addCheck("", actual, matcher);
}
public void addCheck(String reason, T actual, Matcher matcher) {
callables.add(new Callable() {
@Override
public Object call() throws Exception {
try {
assertThat(reason, actual, matcher);
} catch (Throwable err) {
errors.add(err);
}
return null;
}
});
}
public void validateAllErrors() throws Throwable {
callables.forEach(callable -> {
try {
callable.call();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
MultipleFailureException.assertEmpty(errors);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy