Skip to content

Commit

Permalink
[Core] Move URLOutputStream to formatters package
Browse files Browse the repository at this point in the history
The URLOutputStream is only used by formatters. Moving it to the
formatters package allows the visibility of the stream to be reduced
tidying up the effectively public API just a bit more.
  • Loading branch information
mpkorstanje committed Jan 3, 2019
1 parent cc41729 commit eb1a90b
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 26 deletions.
Expand Up @@ -16,7 +16,6 @@
import cucumber.api.event.WriteEvent;
import cucumber.api.formatter.NiceAppendable;
import cucumber.runtime.CucumberException;
import cucumber.runtime.io.URLOutputStream;
import gherkin.ast.Background;
import gherkin.ast.DataTable;
import gherkin.ast.DocString;
Expand Down Expand Up @@ -120,6 +119,7 @@ public void receive(TestRunFinished event) {
}
};

@SuppressWarnings("WeakerAccess") // Used by PluginFactory
public HTMLFormatter(URL htmlReportDir) {
this(htmlReportDir, createJsOut(htmlReportDir));
}
Expand Down
Expand Up @@ -13,8 +13,6 @@
import cucumber.api.formatter.StrictAware;
import cucumber.runtime.CucumberException;
import cucumber.runtime.Utils;
import cucumber.runtime.io.URLOutputStream;
import cucumber.runtime.io.UTF8OutputStreamWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Expand Down Expand Up @@ -78,6 +76,7 @@ public void receive(TestRunFinished event) {
}
};

@SuppressWarnings("WeakerAccess") // Used by plugin factory
public JUnitFormatter(URL out) throws IOException {
this.out = new UTF8OutputStreamWriter(new URLOutputStream(out));
TestCase.treatConditionallySkippedAsFailure = false;
Expand Down
Expand Up @@ -6,8 +6,6 @@
import cucumber.api.event.ConcurrentEventListener;
import cucumber.api.event.EventListener;
import cucumber.runtime.CucumberException;
import cucumber.runtime.io.URLOutputStream;
import cucumber.runtime.io.UTF8OutputStreamWriter;

import java.io.File;
import java.io.IOException;
Expand Down
Expand Up @@ -13,8 +13,6 @@
import cucumber.api.event.TestStepFinished;
import cucumber.api.formatter.StrictAware;
import cucumber.runtime.CucumberException;
import cucumber.runtime.io.URLOutputStream;
import cucumber.runtime.io.UTF8OutputStreamWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
Expand Down
Expand Up @@ -11,7 +11,6 @@
import cucumber.api.event.TestSourceRead;
import cucumber.api.formatter.NiceAppendable;
import cucumber.runtime.CucumberException;
import cucumber.runtime.io.URLOutputStream;
import gherkin.deps.com.google.gson.Gson;
import gherkin.deps.com.google.gson.GsonBuilder;
import gherkin.deps.com.google.gson.annotations.SerializedName;
Expand Down
@@ -1,4 +1,4 @@
package cucumber.runtime.io;
package cucumber.runtime.formatter;

import gherkin.deps.com.google.gson.Gson;
import cucumber.util.FixJava;
Expand All @@ -13,18 +13,18 @@
* A stream that can write to both file and http URLs. If it's a file URL, writes with a {@link java.io.FileOutputStream},
* if it's a http or https URL, writes with a HTTP PUT (by default) or with the specified method.
*/
public class URLOutputStream extends OutputStream {
class URLOutputStream extends OutputStream {
private final URL url;
private final String method;
private final int expectedResponseCode;
private final OutputStream out;
private final HttpURLConnection urlConnection;

public URLOutputStream(URL url) throws IOException {
URLOutputStream(URL url) throws IOException {
this(url, "PUT", Collections.<String, String>emptyMap(), 200);
}

public URLOutputStream(URL url, String method, Map<String, String> headers, int expectedResponseCode) throws IOException {
private URLOutputStream(URL url, String method, Map<String, String> headers, int expectedResponseCode) throws IOException {
this.url = url;
this.method = method;
this.expectedResponseCode = expectedResponseCode;
Expand Down
@@ -0,0 +1,11 @@
package cucumber.runtime.formatter;

import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;

class UTF8OutputStreamWriter extends OutputStreamWriter {
UTF8OutputStreamWriter(OutputStream out) {
super(out, Charset.forName("UTF-8"));
}
}
12 changes: 0 additions & 12 deletions core/src/main/java/cucumber/runtime/io/UTF8OutputStreamWriter.java

This file was deleted.

Expand Up @@ -9,7 +9,6 @@
import cucumber.runner.TimeServiceStub;
import cucumber.runtime.CucumberException;
import cucumber.runtime.Utils;
import cucumber.runtime.io.UTF8OutputStreamWriter;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
Expand Down
@@ -1,4 +1,4 @@
package cucumber.runtime.io;
package cucumber.runtime.formatter;

import cucumber.runtime.Utils;
import cucumber.util.FixJava;
Expand Down

0 comments on commit eb1a90b

Please sign in to comment.