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

ar.com.dgarcia.javaspec.impl.model.impl.TestSpecDefinition Maven / Gradle / Ivy

The newest version!
package ar.com.dgarcia.javaspec.impl.model.impl;

import ar.com.dgarcia.javaspec.api.contexts.TestContext;
import ar.com.dgarcia.javaspec.api.variable.Variable;
import ar.com.dgarcia.javaspec.impl.model.SpecTest;

import java.util.List;

/**
 * This type represents the interpreted definition of a test spec
 * Created by kfgodel on 12/07/14.
 */
public class TestSpecDefinition extends SpecElementSupport implements SpecTest {

    private Runnable testCode;
    private PendingStatus pendingState;
    private Variable sharedContext;

    @Override
    public boolean isMarkedAsPending() {
        return pendingState.isPendingConsidering(getContainerGroup()) || getContainerGroup().isMarkedAsDisabled();
    }

    @Override
    public List getBeforeBlocks() {
        return getContainerGroup().getBeforeBlocks();
    }

    @Override
    public List getAfterBlocks() {
        return getContainerGroup().getAfterBlocks();
    }

    @Override
    public Runnable getTestCode() {
        return testCode;
    }

    @Override
    public void markAsPending() {
        this.pendingState = PendingStatus.PENDING;
    }

    @Override
    public Runnable getSpecExecutionCode() {
        SpecExecutionBlock executionBlock = SpecExecutionBlock.create(this.getBeforeBlocks(), this.getTestCode(), this.getAfterBlocks(), getContainerGroup().getTestContext(), sharedContext);
        return executionBlock;
    }

    public static TestSpecDefinition create(String testName, Runnable testCode, Variable sharedContext) {
        TestSpecDefinition test = new TestSpecDefinition();
        test.setName(testName);
        test.testCode = testCode;
        test.pendingState = PendingStatus.NORMAL;
        test.sharedContext = sharedContext;
        return test;
    }

    /**
     * Creates a test in pending state
     * @param testName The name to identify the test
     * @return The created definition
     */
    public static TestSpecDefinition createPending(String testName, Variable sharedContext) {
        TestSpecDefinition test = create(testName, null, sharedContext);
        test.markAsPending();
        return test;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy