-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handles zip and wsjar protocols properly (fixes #808)
- Loading branch information
1 parent
b2b9f94
commit cfd70af
Showing
2 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
34 changes: 25 additions & 9 deletions
34
core/src/main/java/cucumber/runtime/io/ZipResourceIteratorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
core/src/test/java/cucumber/runtime/io/ZipResourceIteratorFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cucumber.runtime.io; | ||
|
||
import static cucumber.runtime.io.ZipResourceIteratorFactory.filePath; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.net.URLStreamHandler; | ||
|
||
import org.junit.Test; | ||
|
||
// https://github.com/cucumber/cucumber-jvm/issues/808 | ||
public class ZipResourceIteratorFactoryTest { | ||
|
||
private static final URLStreamHandler NULL_URL_STREAM_HANDLER = new URLStreamHandler() { | ||
@Override | ||
protected URLConnection openConnection(URL u) throws IOException { | ||
return null; | ||
} | ||
}; | ||
|
||
@Test | ||
public void is_factory_for_jar_protocols() throws IOException { | ||
ZipResourceIteratorFactory factory = new ZipResourceIteratorFactory(); | ||
|
||
assertTrue(factory.isFactoryFor(new URL("jar:file:cucumber-core.jar!/cucumber/runtime/io"))); | ||
assertTrue(factory.isFactoryFor(new URL(null, "zip:file:cucumber-core.jar!/cucumber/runtime/io", NULL_URL_STREAM_HANDLER))); | ||
assertTrue(factory.isFactoryFor(new URL(null, "wsjar:file:cucumber-core.jar!/cucumber/runtime/io", NULL_URL_STREAM_HANDLER))); | ||
assertFalse(factory.isFactoryFor(new URL("file:cucumber-core"))); | ||
assertFalse(factory.isFactoryFor(new URL("http://http://cukes.info/cucumber-core.jar"))); | ||
} | ||
|
||
@Test | ||
public void computes_file_path_for_jar_protocols() throws Exception { | ||
assertEquals("cucumber-core.jar", filePath(new URL("jar:file:cucumber-core.jar!/cucumber/runtime/io"))); | ||
assertEquals("cucumber-core.jar", filePath(new URL(null, "zip:file:cucumber-core.jar!/cucumber/runtime/io", NULL_URL_STREAM_HANDLER))); | ||
assertEquals("cucumber-core.jar", filePath(new URL(null, "wsjar:file:cucumber-core.jar!/cucumber/runtime/io", NULL_URL_STREAM_HANDLER))); | ||
assertEquals("cucumber-core.jar", filePath(new URL("jar:file:cucumber-core.jar!/"))); | ||
assertEquals("cucumber-core.jar", filePath(new URL(null, "zip:file:cucumber-core.jar!/", NULL_URL_STREAM_HANDLER))); | ||
assertEquals("cucumber-core.jar", filePath(new URL(null, "wsjar:file:cucumber-core.jar!/", NULL_URL_STREAM_HANDLER))); | ||
assertEquals("cucumber-core.jar", filePath(new URL("file:cucumber-core.jar"))); | ||
} | ||
} |