Skip to content

For cucumber/cucumber-jvm#304 #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
Expand Down Expand Up @@ -39,8 +40,19 @@ public class FormatterFactory {
put("usage", UsageFormatter.class);
}};
private static final Pattern FORMATTER_WITH_FILE_PATTERN = Pattern.compile("([^:]+):(.*)");
private Appendable defaultOut = System.out;
private Appendable defaultOut = new NonCloseableStdoutWriter();

static class NonCloseableStdoutWriter extends OutputStreamWriter {
NonCloseableStdoutWriter() {
super(System.out);
}
@Override
public void close() throws IOException {
// We have no intention to close System.out
}
}


public Formatter create(String formatterString) {
Matcher formatterWithFile = FORMATTER_WITH_FILE_PATTERN.matcher(formatterString);
String formatterName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.hamcrest.CoreMatchers.*;

public class FormatterFactoryTest {
private FormatterFactory fc = new FormatterFactory();
Expand Down Expand Up @@ -69,7 +72,7 @@ public void instantiates_usage_formatter_with_file_arg() throws IOException {
@Test
public void instantiates_single_custom_appendable_formatter_with_stdout() {
WantsAppendable formatter = (WantsAppendable) fc.create("cucumber.runtime.formatter.FormatterFactoryTest$WantsAppendable");
assertEquals(System.out, formatter.out);
assertThat(formatter.out, is(instanceOf(OutputStreamWriter.class)));
try {
fc.create("cucumber.runtime.formatter.FormatterFactoryTest$WantsAppendable");
fail();
Expand All @@ -81,7 +84,7 @@ public void instantiates_single_custom_appendable_formatter_with_stdout() {
@Test
public void instantiates_custom_appendable_formatter_with_stdout_and_file() throws IOException {
WantsAppendable formatter = (WantsAppendable) fc.create("cucumber.runtime.formatter.FormatterFactoryTest$WantsAppendable");
assertEquals(System.out, formatter.out);
assertThat(formatter.out, is(instanceOf(OutputStreamWriter.class)));

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