Skip to content

Commit

Permalink
Apply pull request suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
binkley committed Nov 26, 2014
1 parent d378c3e commit 7ba13ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ public enum LogMode {
/**
* Capture the writes to the stream. On test failure write to the original stream.
*/
LOG_ONLY_ON_FAILURE
LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,15 @@ protected void starting(Description description) {
NO_AUTO_FLUSH, ENCODING);
setStream(wrappedStream);
} catch (UnsupportedEncodingException e) {
throw new Error(e); // JRE missing UTF-8
throw new RuntimeException(e); // JRE missing UTF-8
}
}

@Override
protected void failed(Throwable e, Description description) {
// Only log-on-failure mode needs to print; the others already handle this
switch (mode) {
case LOG_AND_WRITE_TO_STREAM:
case LOG_ONLY:
break;
case LOG_ONLY_ON_FAILURE:
originalStream.print(getLog());
break;
default:
throw new IllegalArgumentException("The LogMode " + mode
+ " is not supported");
}
if (mode == LogMode.LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY)
originalStream.print(getLog());
}

@Override
Expand All @@ -61,7 +52,7 @@ private OutputStream getNewStream() {
case LOG_AND_WRITE_TO_STREAM:
return new TeeOutputStream(originalStream, log);
case LOG_ONLY:
case LOG_ONLY_ON_FAILURE:
case LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY:
return log;
default:
throw new IllegalArgumentException("The LogMode " + mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class PrintStreamLogOnFailureTest {

@Test
public void doesNotWriteToSystemOutputStreamForLogOnFailureModeWithoutFailure() throws Throwable {
StandardOutputStreamLog log = new StandardOutputStreamLog(LogMode.LOG_ONLY_ON_FAILURE);
StandardOutputStreamLog log = new StandardOutputStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY);
PrintStream originalStream = out;
try {
ByteArrayOutputStream captureOutputStream = new ByteArrayOutputStream();
Expand All @@ -68,7 +68,7 @@ public void doesNotWriteToSystemOutputStreamForLogOnFailureModeWithoutFailure()

@Test
public void doesWriteToOutputLogForLogOnFailureModeWithoutFailure() throws Throwable {
StandardOutputStreamLog log = new StandardOutputStreamLog(LogMode.LOG_ONLY_ON_FAILURE);
StandardOutputStreamLog log = new StandardOutputStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY);
PrintStream originalStream = out;
try {
ByteArrayOutputStream captureOutputStream = new ByteArrayOutputStream();
Expand All @@ -82,7 +82,7 @@ public void doesWriteToOutputLogForLogOnFailureModeWithoutFailure() throws Throw

@Test
public void doesWriteToSystemOutputStreamForLogOnFailureModeWithFailure() throws Throwable {
StandardOutputStreamLog log = new StandardOutputStreamLog(LogMode.LOG_ONLY_ON_FAILURE);
StandardOutputStreamLog log = new StandardOutputStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY);
PrintStream originalStream = out;
ByteArrayOutputStream captureOutputStream = new ByteArrayOutputStream();
try {
Expand All @@ -97,7 +97,7 @@ public void doesWriteToSystemOutputStreamForLogOnFailureModeWithFailure() throws

@Test
public void doesWriteToOutputLogForLogOnFailureModeWithFailure() throws Throwable {
StandardOutputStreamLog log = new StandardOutputStreamLog(LogMode.LOG_ONLY_ON_FAILURE);
StandardOutputStreamLog log = new StandardOutputStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY);
PrintStream originalStream = out;
try {
ByteArrayOutputStream captureOutputStream = new ByteArrayOutputStream();
Expand All @@ -112,7 +112,7 @@ public void doesWriteToOutputLogForLogOnFailureModeWithFailure() throws Throwabl

@Test
public void doesNotWriteToSystemErrorStreamForLogOnFailureModeWithoutFailure() throws Throwable {
StandardErrorStreamLog log = new StandardErrorStreamLog(LogMode.LOG_ONLY_ON_FAILURE);
StandardErrorStreamLog log = new StandardErrorStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY);
PrintStream originalStream = err;
try {
ByteArrayOutputStream captureErrorStream = new ByteArrayOutputStream();
Expand All @@ -126,7 +126,7 @@ public void doesNotWriteToSystemErrorStreamForLogOnFailureModeWithoutFailure() t

@Test
public void doesWriteToErrorLogForLogOnFailureModeWithoutFailure() throws Throwable {
StandardErrorStreamLog log = new StandardErrorStreamLog(LogMode.LOG_ONLY_ON_FAILURE);
StandardErrorStreamLog log = new StandardErrorStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY);
PrintStream originalStream = err;
try {
ByteArrayOutputStream captureErrorStream = new ByteArrayOutputStream();
Expand All @@ -140,7 +140,7 @@ public void doesWriteToErrorLogForLogOnFailureModeWithoutFailure() throws Throwa

@Test
public void doesWriteToSystemErrorStreamForLogOnFailureModeWithFailure() throws Throwable {
StandardErrorStreamLog log = new StandardErrorStreamLog(LogMode.LOG_ONLY_ON_FAILURE);
StandardErrorStreamLog log = new StandardErrorStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY);
PrintStream originalStream = err;
ByteArrayOutputStream captureErrorStream = new ByteArrayOutputStream();
try {
Expand All @@ -155,7 +155,7 @@ public void doesWriteToSystemErrorStreamForLogOnFailureModeWithFailure() throws

@Test
public void doesWriteToErrorLogForLogOnFailureModeWithFailure() throws Throwable {
StandardErrorStreamLog log = new StandardErrorStreamLog(LogMode.LOG_ONLY_ON_FAILURE);
StandardErrorStreamLog log = new StandardErrorStreamLog(LogMode.LOG_AND_WRITE_TO_STREAM_ON_FAILURE_ONLY);
PrintStream originalStream = err;
try {
ByteArrayOutputStream captureErrorStream = new ByteArrayOutputStream();
Expand Down

0 comments on commit 7ba13ea

Please sign in to comment.