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

de.a9d3.testing.executer.SingleThreadExecutor Maven / Gradle / Ivy

Go to download

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy