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

de.hilling.junit.cdi.cucumber.scope.context.ScenarioScopedContext Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package de.hilling.junit.cdi.cucumber.scope.context;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.logging.Logger;

import javax.enterprise.context.spi.Context;
import javax.enterprise.event.Observes;

import org.junit.runner.Description;

import de.hilling.junit.cdi.cucumber.scope.ScenarioScoped;
import de.hilling.junit.cdi.lifecycle.TestEvent;
import de.hilling.junit.cdi.scope.EventType;
import de.hilling.junit.cdi.scope.context.AbstractScopeContext;
import de.hilling.junit.cdi.scope.context.CustomScopeContextHolder;

/**
 * author: fseemann on 29.04.2015.
 */
public class ScenarioScopedContext extends AbstractScopeContext implements Context, Serializable {
    private static final long serialVersionUID = 1L;
    private static final Logger LOG = Logger.getLogger(ScenarioScopedContext.class
                                                       .getCanonicalName());
    private static final CustomScopeContextHolder CONTEXT_HOLDER = new CustomScopeContextHolder();
    private static boolean active = false;

    public ScenarioScopedContext() {
    }

    @Override
    protected CustomScopeContextHolder getScopeContextHolder() {
        return CONTEXT_HOLDER;
    }

    @Override public Class getScope() {
        return ScenarioScoped.class;
    }

    protected void activate(@Observes @TestEvent(EventType.STARTING) Description description) {
        active = true;
    }

    protected void deactivate(@Observes @TestEvent(EventType.FINISHING) Description description) {
        getScopeContextHolder().clear();
        active = false;
    }

    @Override
    public boolean isActive() {
        return active;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy