de.a9d3.testing.executer.SingleThreadExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of base-test Show documentation
Show all versions of base-test Show documentation
A project which helps you testing your java classes for basic things like getter==setter,
hashCode and equals methods and other programming schemas.
Also provides a convenient way to instantiate classes with seeded random data.
The newest version!
package de.a9d3.testing.executer;
import de.a9d3.testing.checks.CheckInterface;
import de.a9d3.testing.executer.exception.CheckFailedException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
public class SingleThreadExecutor implements Executor {
private static final Logger LOGGER = Logger.getLogger(SingleThreadExecutor.class.getName());
private static String executionLogToString(Class testClass, Map executionLog) {
StringBuilder builder = new StringBuilder();
builder.append("Tested ");
builder.append(testClass.getName());
builder.append("\n");
executionLog.forEach((check, log) -> {
builder.append(check);
builder.append(": ");
builder.append(log);
builder.append("\n");
});
return builder.toString();
}
public Boolean execute(Class c, List checks) {
Map executionLog = new HashMap<>();
boolean failed = false;
for (CheckInterface check : checks) {
boolean result = check.check(c);
executionLog.put(check.getClass().getName(), result ?
"Passed ✔️" : "Failed ❌");
if (!result) {
failed = true;
}
}
if (failed) {
throw new CheckFailedException(executionLogToString(c, executionLog));
}
LOGGER.info(() -> executionLogToString(c, executionLog));
return true;
}
}