Skip to content

Commit cfc60cb

Browse files
Additional unit-tests for #789
* tests whether files are created when the parent directory does not exists * removes duplicate test case
1 parent 6bffa75 commit cfc60cb

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

core/src/test/java/cucumber/runtime/io/URLOutputStreamTest.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
import java.io.Writer;
2323
import java.net.InetSocketAddress;
2424
import java.net.URI;
25+
import java.net.URISyntaxException;
2526
import java.net.URL;
2627
import java.nio.charset.Charset;
28+
import java.nio.file.Files;
29+
import java.nio.file.Path;
2730
import java.util.concurrent.BlockingQueue;
2831
import java.util.concurrent.ExecutionException;
2932
import java.util.concurrent.Executors;
@@ -47,16 +50,21 @@ public void stopWebbit() throws ExecutionException, InterruptedException {
4750
}
4851

4952
@Test
50-
public void can_write_to_file() throws IOException {
51-
File tmp = File.createTempFile("cucumber-jvm", "tmp");
52-
Writer w = new UTF8OutputStreamWriter(new URLOutputStream(tmp.toURI().toURL()));
53+
public void write_to_file_without_existing_parent_directory() throws IOException, URISyntaxException {
54+
Path filesWithoutParent = Files.createTempDirectory("filesWithoutParent");
55+
String baseURL = filesWithoutParent.toUri().toURL().toString();
56+
URL urlWithoutParentDirectory = new URL(baseURL + "/non/existing/directory");
57+
58+
Writer w = new UTF8OutputStreamWriter(new URLOutputStream(urlWithoutParentDirectory));
5359
w.write("Hellesøy");
5460
w.close();
55-
assertEquals("Hellesøy", FixJava.readReader(openUTF8FileReader(tmp)));
61+
62+
File testFile = new File(urlWithoutParentDirectory.toURI());
63+
assertEquals("Hellesøy", FixJava.readReader(openUTF8FileReader(testFile)));
5664
}
5765

5866
@Test
59-
public void can_write_to_file_using_path() throws IOException {
67+
public void can_write_to_file() throws IOException {
6068
File tmp = File.createTempFile("cucumber-jvm", "tmp");
6169
Writer w = new UTF8OutputStreamWriter(new URLOutputStream(tmp.toURI().toURL()));
6270
w.write("Hellesøy");

0 commit comments

Comments
 (0)