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

io.github.olib963.javatest.fixtures.Fixtures Maven / Gradle / Ivy

package io.github.olib963.javatest.fixtures;

import io.github.olib963.javatest.CheckedSupplier;
import io.github.olib963.javatest.TestRunner;
import io.github.olib963.javatest.fixtures.internal.FixtureRunner;
import io.github.olib963.javatest.fixtures.internal.FunctionFixtureDefinition;
import io.github.olib963.javatest.fixtures.internal.TemporaryDirectory;

import java.io.File;
import java.util.function.Function;
import java.util.function.Supplier;

import static io.github.olib963.javatest.fixtures.Try.Success;
import static io.github.olib963.javatest.fixtures.Try.Try;

public class Fixtures {
    private Fixtures() {
    }

    public static  TestRunner fixtureRunner(String fixtureName,
                                                     FixtureDefinition fixtureDefinition,
                                                     Function testFunction) {
        return new FixtureRunner<>(fixtureName, fixtureDefinition, testFunction);
    }

    public static  FixtureDefinition definitionFromFunction(Supplier> creator) {
        return definitionFromFunctions(creator, x -> Success());
    }

    public static  FixtureDefinition definitionFromFunctions(Supplier> creator, Function> destroyer) {
        return new FunctionFixtureDefinition<>(creator, destroyer);
    }

    // Helper function to allow you to define a fixture using an existing, exception driven java API
    public static  FixtureDefinition definitionFromThrowingFunction(CheckedSupplier creator) {
        return definitionFromThrowingFunctions(creator, f -> {});
    }

    public static  FixtureDefinition definitionFromThrowingFunctions(CheckedSupplier creator, CheckedConsumer destroyer) {
        return definitionFromFunctions(() -> Try(creator), (Fixture f) -> Try(destroyer, f));
    }

    public static FixtureDefinition temporaryDirectory(String path) {
        return new TemporaryDirectory(path);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy