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

com.agilarity.jbehave.LocalStoryFinder Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package com.agilarity.jbehave;

import static org.apache.commons.lang.StringUtils.EMPTY;

import java.util.List;

import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.JUnitStories;

public class LocalStoryFinder implements StoryPathFinder {
    private final Class storiesClass;
    private final String storyFileExtension;

    public LocalStoryFinder(final Class storiesClass) {
        super();
        this.storiesClass = storiesClass;
        this.storyFileExtension = "story";
    }

    public LocalStoryFinder(final Class storiesClass,
            final String storyFileExtension) {
        super();
        this.storiesClass = storiesClass;
        this.storyFileExtension = storyFileExtension;
    }

    public List findStoryPaths() {
        return new StoryFinder().findPaths(getLocation(), getStoryPattern(),
                EMPTY);
    }

    private String getLocation() {
        return CodeLocations.codeLocationFromClass(storiesClass).getFile();
    }

    private String getStoryPattern() {
        return String.format("**/%s/**/%s.%s", getPackageAsPath(),
                getStoryNameFilter(), getStoryFileExtension());
    }

    private String getPackageAsPath() {
        return storiesClass.getPackage().getName().replace(".", "/");
    }

    private String getStoryNameFilter() {
        return System.getProperty("story-name.filter", "*");
    }

    private String getStoryFileExtension() {
        return storyFileExtension;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy