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

com.github.lpandzic.junit.bdd.When Maven / Gradle / Ivy

package com.github.lpandzic.junit.bdd;

import java.util.Optional;

/**
 * Defines behavior that is being tested.
 *
 * @author Lovro Pandzic
 */
public final class When {

    When() {
    }

    /**
     * Used for specifying behavior that should throw an exception.
     *
     * @param throwableSupplier supplier or throwable
     * @param                type of throwable
     *
     * @return new {@link Then.Throws}
     */
    public  Then.Throws when(ThrowableSupplier throwableSupplier) {

        try {
            throwableSupplier.get();
        } catch (Throwable t) {
            Bdd.putThrownException(t);
        }

        return new Then.Throws<>();
    }

    /**
     * Used for specifying behavior that should return a value.
     *
     * @param value returned by the specified behavior
     * @param    type of {@code value}
     *
     * @return new {@link Then.Returns}
     */
    public  Then.Returns when(T value) {

        return new Then.Returns<>(Optional.ofNullable(value));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy