commit 31ef505512d17f54f9ae5d47a14c722ddd166992
Author:     Alex Lehmann <alexl...@gmail.com>
AuthorDate: Fri Mar 2 22:01:46 2012 +0100
Commit:     Alex Lehmann <alexl...@gmail.com>
CommitDate: Fri Mar 2 22:01:46 2012 +0100

    JBEHAVE-729: When running jbehave unit tests from inside a jar, the current 
path is converted to file:/home/.../
    
    remove trailing "file:" from path if it appears on 
CodeLocations.codeLocationFromClass
    this broke building the path later from the string (confused as relative 
path)

diff --git a/jbehave-core/src/main/java/org/jbehave/core/io/CodeLocations.java 
b/jbehave-core/src/main/java/org/jbehave/core/io/CodeLocations.java
index 6d629d2..f137f26 100755
--- a/jbehave-core/src/main/java/org/jbehave/core/io/CodeLocations.java
+++ b/jbehave-core/src/main/java/org/jbehave/core/io/CodeLocations.java
@@ -1,6 +1,7 @@
 package org.jbehave.core.io;
 
 import static org.apache.commons.lang.StringUtils.removeEnd;
+import static org.apache.commons.lang.StringUtils.removeStart;
 
 import java.io.File;
 import java.net.URL;
@@ -20,7 +21,7 @@ public class CodeLocations {
     public static URL codeLocationFromClass(Class<?> codeLocationClass) {
         String pathOfClass = codeLocationClass.getName().replace(".", "/") + 
".class";
         URL classResource = 
codeLocationClass.getClassLoader().getResource(pathOfClass);
-        String codeLocationPath = removeEnd(classResource.getFile(), 
pathOfClass);
+        String codeLocationPath = 
removeStart(removeEnd(classResource.getFile(), pathOfClass),"file:");
         return codeLocationFromPath(codeLocationPath);
     }
 
diff --git 
a/jbehave-core/src/test/java/org/jbehave/core/io/CodeLocationsBehaviour.java 
b/jbehave-core/src/test/java/org/jbehave/core/io/CodeLocationsBehaviour.java
index fc8d84f..db1dc50 100755
--- a/jbehave-core/src/test/java/org/jbehave/core/io/CodeLocationsBehaviour.java
+++ b/jbehave-core/src/test/java/org/jbehave/core/io/CodeLocationsBehaviour.java
@@ -5,11 +5,14 @@ import static org.hamcrest.Matchers.endsWith;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.not;
 
 import java.net.URL;
 
 import org.jbehave.core.io.CodeLocations.InvalidCodeLocation;
 import org.junit.Test;
+import org.junit.runner.JUnitCore;
 
 public class CodeLocationsBehaviour {
 
@@ -43,4 +46,13 @@ public class CodeLocationsBehaviour {
         assertThat(new CodeLocations(), is(notNullValue()));
     }
 
+//  wrong output looks like this:
+//  
"C:/Projects/jbehave/file:/C:/Users/Name/.m2/repository/junit/junit-dep/4.8.2/junit-dep-4.8.2.jar!"
+
+    @Test
+    public void shouldCreateValidPathFromJarClass() {
+        
assertThat(CodeLocations.codeLocationFromClass(this.getClass()).getFile(), 
not(containsString("/file:")));
+        
assertThat(CodeLocations.codeLocationFromClass(JUnitCore.class).getFile(), 
not(containsString("/file:")));
+    }
+
 }
\ No newline at end of file



Reply via email to