##### Coverage Report - org.jbehave.core.io.AbstractStoryPathResolver

Classes in this File | Line Coverage | Branch Coverage | Complexity
AbstractStoryPathResolver |
100% | 15/15
100% | 6/6
| 1.8;1.8

1 |  |
     package org.jbehave.core.io;
2 |  |
3 |  |
     import org.jbehave.core.Embeddable;
4 |  |
5 |  |
     public abstract class AbstractStoryPathResolver implements
6 |  |
             StoryPathResolver {
7 |  |
8 |  |
             static final String DOT_REGEX = "\\.";
9 |  |
             static final String SLASH = "/";
10 |  |
             static final String EMPTY = "";
11 |  |
             static final String DEFAULT_EXTENSION = ".story";
12 |  |
13 |  |
             private final String extension;
14 |  |
15 | 359 |
             protected AbstractStoryPathResolver(String extension) {
16 | 359 |
                     this.extension = extension;
17 | 359 |
             }
18 |  |
19 |  |
             public String resolve(Class<? extends Embeddable> embeddableClass) {
20 | 49 |
             return formatPath(resolveDirectory(embeddableClass), resolveName(embeddableClass), extension);
21 |  |
             }
22 |  |
23 |  |
             private String formatPath(String directory, String name,
24 |  |
                             String extension) {
25 | 49 |
                     StringBuffer sb = new StringBuffer();
26 | 49 |
                     if (directory.length() > 0) {
27 | 48 |
                             sb.append(directory).append(SLASH);
28 |  |
                     }
29 | 49 |
                     sb.append(name);
30 | 49 |
                     if (extension.length() > 0) {
31 | 44 |
                             sb.append(extension);
32 |  |
                     }
33 | 49 |
                     return sb.toString();
34 |  |
             }
35 |  |
36 |  |
             protected String resolveDirectory(
37 |  |
                             Class<? extends Embeddable> embeddableClass) {
38 | 49 |
                     Package scenarioPackage = embeddableClass.getPackage();
39 | 49 |
                     if (scenarioPackage != null) {
40 | 48 |
                             return scenarioPackage.getName().replaceAll(DOT_REGEX, SLASH);
41 |  |
                     }
42 | 1 |
                     return EMPTY;
43 |  |
             }
44 |  |
45 |  |
             protected abstract String resolveName(
46 |  |
                             Class<? extends Embeddable> embeddableClass);
47 |  |
48 |  |
     }