Skip to content

Commit e508ea5

Browse files
committed
Merge branch 'issue-304' of git://github.com/Mishail/cucumber-jvm into Mishail-issue-304
2 parents 3f39086 + c4809b2 commit e508ea5

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

core/src/main/java/cucumber/runtime/formatter/FormatterFactory.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.io.File;
1111
import java.io.IOException;
12+
import java.io.OutputStreamWriter;
1213
import java.lang.reflect.Constructor;
1314
import java.lang.reflect.InvocationTargetException;
1415
import java.util.HashMap;
@@ -39,8 +40,19 @@ public class FormatterFactory {
3940
put("usage", UsageFormatter.class);
4041
}};
4142
private static final Pattern FORMATTER_WITH_FILE_PATTERN = Pattern.compile("([^:]+):(.*)");
42-
private Appendable defaultOut = System.out;
43+
private Appendable defaultOut = new NonCloseableStdoutWriter();
4344

45+
static class NonCloseableStdoutWriter extends OutputStreamWriter {
46+
NonCloseableStdoutWriter() {
47+
super(System.out);
48+
}
49+
@Override
50+
public void close() throws IOException {
51+
// We have no intention to close System.out
52+
}
53+
}
54+
55+
4456
public Formatter create(String formatterString) {
4557
Matcher formatterWithFile = FORMATTER_WITH_FILE_PATTERN.matcher(formatterString);
4658
String formatterName;

core/src/test/java/cucumber/runtime/formatter/FormatterFactoryTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
import java.io.File;
99
import java.io.IOException;
10+
import java.io.OutputStreamWriter;
1011

1112
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertThat;
1214
import static org.junit.Assert.fail;
15+
import static org.hamcrest.CoreMatchers.*;
1316

1417
public class FormatterFactoryTest {
1518
private FormatterFactory fc = new FormatterFactory();
@@ -69,7 +72,7 @@ public void instantiates_usage_formatter_with_file_arg() throws IOException {
6972
@Test
7073
public void instantiates_single_custom_appendable_formatter_with_stdout() {
7174
WantsAppendable formatter = (WantsAppendable) fc.create("cucumber.runtime.formatter.FormatterFactoryTest$WantsAppendable");
72-
assertEquals(System.out, formatter.out);
75+
assertThat(formatter.out, is(instanceOf(OutputStreamWriter.class)));
7376
try {
7477
fc.create("cucumber.runtime.formatter.FormatterFactoryTest$WantsAppendable");
7578
fail();
@@ -81,7 +84,7 @@ public void instantiates_single_custom_appendable_formatter_with_stdout() {
8184
@Test
8285
public void instantiates_custom_appendable_formatter_with_stdout_and_file() throws IOException {
8386
WantsAppendable formatter = (WantsAppendable) fc.create("cucumber.runtime.formatter.FormatterFactoryTest$WantsAppendable");
84-
assertEquals(System.out, formatter.out);
87+
assertThat(formatter.out, is(instanceOf(OutputStreamWriter.class)));
8588

8689
WantsAppendable formatter2 = (WantsAppendable) fc.create("cucumber.runtime.formatter.FormatterFactoryTest$WantsAppendable:" + TempDir.createTempFile().getAbsolutePath());
8790
assertEquals(UTF8FileWriter.class, formatter2.out.getClass());

0 commit comments

Comments
 (0)