package com.atlassian.bitbucket.test.runners;

import com.atlassian.bitbucket.test.filters.CompatibleProductTopologyFilter;
import com.atlassian.bitbucket.test.filters.CompositeTestFilter;
import com.atlassian.bitbucket.test.filters.DarkFeatureFilter;
import com.google.common.collect.ImmutableList;
import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.NoTestsRemainException;

import static org.junit.runners.Parameterized.Parameter;

/**
 * A {@link Runner} that applies a list of custom {@link Filter filters}.
 *
 * Through inheritance of {@link ParameterisedRunnerBase} it also supports {@link Parameter parameterised} test execution.
 */
public class ConditionalRunner extends ParameterisedRunnerBase {

    public ConditionalRunner(Class<?> klass) throws Throwable {
        super(klass);

        try {
            new CompositeTestFilter(ImmutableList.<Filter>builder()
                    .add(new CompatibleProductTopologyFilter(getTestClass()))
                    .add(new DarkFeatureFilter(getTestClass()))
                    .build()).apply(target);
        } catch (NoTestsRemainException ex) {
            //We are totally OK with that
        }
    }

}
