Permalink
Browse files

Fix for #339

  • Loading branch information...
1 parent e572769 commit d43dfdccfe97c2fa812f7d52e0795b2bed67da8c @aslakhellesoy aslakhellesoy committed Jul 10, 2012
@@ -143,12 +143,12 @@ public void match(Match match) {
}
@Override
- public void embedding(String mimeType, InputStream data) {
+ public void embedding(String mimeType, byte[] data) {
// Creating a file instead of using data urls to not clutter the js file
String extension = MIME_TYPES_EXTENSIONS.get(mimeType);
if (extension != null) {
StringBuilder fileName = new StringBuilder("embedded").append(embeddedIndex++).append(".").append(extension);
- writeBytes(data, reportFileOutputStream(fileName.toString()));
+ writeBytesAndClose(data, reportFileOutputStream(fileName.toString()));
writeToJsReport("embedding", new StringBuilder("'").append(mimeType).append("','").append(fileName).append("'").toString());
}
}
@@ -161,11 +161,11 @@ public void write(String text) {
private void copyReportFiles() {
for (String textAsset : TEXT_ASSETS) {
InputStream textAssetStream = getClass().getResourceAsStream(textAsset);
- writeBytes(textAssetStream, reportFileOutputStream(textAsset));
+ writeStreamAndClose(textAssetStream, reportFileOutputStream(textAsset));
}
}
- private void writeBytes(InputStream in, OutputStream out) {
+ private void writeStreamAndClose(InputStream in, OutputStream out) {
byte[] buffer = new byte[16 * 1024];
try {
int len = in.read(buffer);
@@ -179,6 +179,14 @@ private void writeBytes(InputStream in, OutputStream out) {
}
}
+ private void writeBytesAndClose(byte[] buf, OutputStream out) {
+ try {
+ out.write(buf);
+ } catch (IOException e) {
+ throw new CucumberException("Unable to write to report file item: ", e);
+ }
+ }
+
private NiceAppendable jsOut() {
if (jsOut == null) {
try {
@@ -23,7 +23,6 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
-import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.DecimalFormat;
@@ -141,7 +140,7 @@ public void match(Match match) {
}
@Override
- public void embedding(String mimeType, InputStream data) {
+ public void embedding(String mimeType, byte[] data) {
}
@Override
@@ -13,7 +13,6 @@
import gherkin.formatter.model.ScenarioOutline;
import gherkin.formatter.model.Step;
-import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -100,15 +99,15 @@ public void result(Result result) {
@Override
public void before(Match match, Result result) {
- handleHook(match, result, "B");
+ handleHook(result, "B");
}
@Override
public void after(Match match, Result result) {
- handleHook(match, result, "A");
+ handleHook(result, "A");
}
- private void handleHook(Match match, Result result, String character) {
+ private void handleHook(Result result, String character) {
if (result.getStatus().equals(Result.FAILED)) {
if (!monochrome) {
ANSI_ESCAPES.get(result.getStatus()).appendTo(out);
@@ -125,7 +124,7 @@ public void match(Match match) {
}
@Override
- public void embedding(String mimeType, InputStream data) {
+ public void embedding(String mimeType, byte[] data) {
}
@Override
@@ -15,7 +15,6 @@
import gherkin.formatter.model.ScenarioOutline;
import gherkin.formatter.model.Step;
-import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
@@ -73,7 +72,7 @@ public void examples(Examples examples) {
}
@Override
- public void embedding(String mimeType, InputStream data) {
+ public void embedding(String mimeType, byte[] data) {
}
@Override
@@ -1,7 +1,5 @@
package cucumber.runtime;
-import java.io.InputStream;
-
/**
* After Hooks that declare a parameter of this type will receive an instance of this class.
* This allows an After hook to inspect whether or not a Scenario failed.
@@ -26,7 +24,7 @@
* @see cucumber.formatter.HTMLFormatter
* @see gherkin.formatter.JSONFormatter
*/
- void embed(InputStream data, String mimeType);
+ void embed(byte[] data, String mimeType);
/**
* Outputs some text into the report.
@@ -3,7 +3,6 @@
import gherkin.formatter.Reporter;
import gherkin.formatter.model.Result;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@@ -37,7 +36,7 @@ public boolean isFailed() {
}
@Override
- public void embed(InputStream data, String mimeType) {
+ public void embed(byte[] data, String mimeType) {
reporter.embedding(mimeType, data);
}
@@ -4,8 +4,6 @@
import gherkin.formatter.model.Result;
import org.junit.Test;
-import java.io.ByteArrayInputStream;
-
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -43,7 +41,7 @@ public void undefined_and_pending_is_pending() throws Exception {
@Test
public void embeds_data() {
- ByteArrayInputStream data = new ByteArrayInputStream(new byte[]{1, 2, 3});
+ byte[] data = new byte[]{1, 2, 3};
r.embed(data, "bytes/foo");
verify(reporter).embedding("bytes/foo", data);
}
@@ -5,7 +5,7 @@
import gherkin.formatter.model.DataTableRow;
import gherkin.lexer.Lexer;
import gherkin.lexer.Listener;
-import gherkin.lexer.i18n.EN;
+import gherkin.lexer.En;
import java.util.ArrayList;
import java.util.Collections;
@@ -17,7 +17,7 @@
public static DataTable parse(String source, String dateFormat) {
final List<DataTableRow> rows = new ArrayList<DataTableRow>();
- Lexer l = new EN(new Listener() {
+ Lexer l = new En(new Listener() {
@Override
public void comment(String comment, Integer line) {
throw new UnsupportedOperationException();
@@ -17,7 +17,6 @@
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashSet;
@@ -93,7 +92,7 @@ public void before(Match match, Result result) {
@Override
public void result(Result result) {
- if(result.getError() != null) {
+ if (result.getError() != null) {
throw new RuntimeException(result.getError());
}
}
@@ -108,7 +107,7 @@ public void match(Match match) {
}
@Override
- public void embedding(String mimeType, InputStream data) {
+ public void embedding(String mimeType, byte[] data) {
}
@Override
@@ -14,7 +14,6 @@
import org.junit.runner.Description;
import org.junit.runner.notification.RunNotifier;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@@ -62,7 +61,7 @@ public void match(Match match) {
}
@Override
- public void embedding(String mimeType, InputStream data) {
+ public void embedding(String mimeType, byte[] data) {
reporter.embedding(mimeType, data);
}

0 comments on commit d43dfdc

Please sign in to comment.