You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2014/09/02 16:10:49 UTC

git commit: Refactor LoggerWriter into two classes: LoggerWriter and LoggerWriterFilter. The old LoggerWriter is like the new LoggerWriterFilter which subclasses WriterFilter. The idea behind the new LoggerWriter is that it does not need to carry and wri

Repository: logging-log4j2
Updated Branches:
  refs/heads/master acba5dc88 -> 3faca25d9


Refactor LoggerWriter into two classes: LoggerWriter and
LoggerWriterFilter. The old LoggerWriter is like the new
LoggerWriterFilter which subclasses WriterFilter. The idea behind the
new LoggerWriter is that it does not need to carry and write to another
wrapped Writer. This is what I'd want to do in JDBC for example.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3faca25d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3faca25d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3faca25d

Branch: refs/heads/master
Commit: 3faca25d9b54691fb514bfbf373460e438ff5619
Parents: acba5dc
Author: Gary Gregory <ga...@gmail.com>
Authored: Tue Sep 2 10:10:45 2014 -0400
Committer: Gary Gregory <ga...@gmail.com>
Committed: Tue Sep 2 10:10:45 2014 -0400

----------------------------------------------------------------------
 .../log4j/streams/LoggerPrintWriter.java        |  13 +-
 .../logging/log4j/streams/LoggerStreams.java    |   4 +-
 .../logging/log4j/streams/LoggerWriter.java     |  48 ++-----
 .../log4j/streams/LoggerWriterFilter.java       | 101 ++++++++++++++
 .../log4j/streams/AbstractLoggerWriterTest.java | 138 +++++++++++++++++++
 .../log4j/streams/AbstractStreamTest.java       |  59 ++++++++
 .../log4j/streams/LoggerInputStreamTest.java    |   2 +-
 .../log4j/streams/LoggerOutputStreamTest.java   |   2 +-
 .../log4j/streams/LoggerPrintWriterTest.java    |   9 +-
 .../logging/log4j/streams/LoggerReaderTest.java |   2 +-
 .../log4j/streams/LoggerWriterFilterTest.java   |  16 +++
 .../logging/log4j/streams/LoggerWriterTest.java | 118 +---------------
 .../logging/log4j/streams/StreamTesting.java    |  61 --------
 13 files changed, 349 insertions(+), 224 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerPrintWriter.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerPrintWriter.java b/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerPrintWriter.java
index f36c911..531a08b 100644
--- a/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerPrintWriter.java
+++ b/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerPrintWriter.java
@@ -35,11 +35,11 @@ public class LoggerPrintWriter extends PrintWriter {
     private static final String FQCN = LoggerPrintWriter.class.getName();
 
     public LoggerPrintWriter(final Logger logger, final Level level) {
-        this(null, false, (ExtendedLogger) logger, FQCN, level, null);
+        this((ExtendedLogger) logger, false, FQCN, level, null);
     }
 
     public LoggerPrintWriter(final Logger logger, final Level level, final Marker marker) {
-        this(null, false, (ExtendedLogger) logger, FQCN, level, marker);
+        this((ExtendedLogger) logger, false, FQCN, level, marker);
     }
 
     public LoggerPrintWriter(final Writer writer, final Logger logger, final Level level) {
@@ -58,9 +58,16 @@ public class LoggerPrintWriter extends PrintWriter {
         this(writer, autoFlush, (ExtendedLogger) logger, FQCN, level, marker);
     }
 
+    @SuppressWarnings("resource")
     public LoggerPrintWriter(final Writer writer, final boolean autoFlush, final ExtendedLogger logger, final String fqcn,
             final Level level, final Marker marker) {
-        super(new LoggerWriter(writer, logger, fqcn, level, marker), autoFlush);
+        super(new LoggerWriterFilter(writer, logger, fqcn, level, marker), autoFlush);
+    }
+
+    @SuppressWarnings("resource")
+    public LoggerPrintWriter(final ExtendedLogger logger, final boolean autoFlush, final String fqcn,
+            final Level level, final Marker marker) {
+        super(new LoggerWriter(logger, fqcn, level, marker), autoFlush);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerStreams.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerStreams.java b/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerStreams.java
index 1ad59d9..887cc4d 100644
--- a/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerStreams.java
+++ b/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerStreams.java
@@ -73,8 +73,8 @@ public class LoggerStreams {
             return new BufferedBuilder(logger, level, marker, 0);
         }
 
-        public LoggerWriter create(final Writer writer) {
-            return new LoggerWriter(writer, logger, level, marker);
+        public LoggerWriterFilter create(final Writer writer) {
+            return new LoggerWriterFilter(writer, logger, level, marker);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerWriter.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerWriter.java b/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerWriter.java
index 30915d6..8233d64 100644
--- a/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerWriter.java
+++ b/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerWriter.java
@@ -27,96 +27,64 @@ import org.apache.logging.log4j.spi.ExtendedLogger;
 import org.apache.logging.log4j.streams.util.CharStreamLogger;
 
 /**
- * Writer that logs each line written to a pre-defined level. Can also be configured with a Marker.
- * This class provides an interface that follows the {@link java.io.Writer} methods in spirit, but
- * doesn't require output to any external writer.
+ * Writer that logs each line written to a pre-defined level. Can also be configured with a Marker. This class provides
+ * an interface that follows the {@link java.io.Writer} methods in spirit, but doesn't require output to any external
+ * writer.
  */
 public class LoggerWriter extends Writer {
     private static final String FQCN = LoggerWriter.class.getName();
 
-    private final Writer writer;
     private final CharStreamLogger logger;
     private final String fqcn;
 
-    public LoggerWriter(final Logger logger, final Level level) {
-        this(null, (ExtendedLogger) logger, FQCN, level, null);
-    }
-
     public LoggerWriter(final Logger logger, final Level level, final Marker marker) {
-        this(null, (ExtendedLogger) logger, FQCN, level, marker);
+        this((ExtendedLogger) logger, FQCN, level, marker);
     }
 
-    public LoggerWriter(final Writer writer, final Logger logger, final Level level) {
-        this(writer, (ExtendedLogger) logger, FQCN, level, null);
-    }
-
-    public LoggerWriter(final Writer writer, final Logger logger, final Level level, final Marker marker) {
-        this(writer, (ExtendedLogger) logger, FQCN, level, marker);
+    public LoggerWriter(final Logger logger, final Level level) {
+        this((ExtendedLogger) logger, FQCN, level, null);
     }
 
-    public LoggerWriter(final Writer writer, final ExtendedLogger logger, final String fqcn, final Level level, final Marker marker) {
-        this.writer = writer;
+    public LoggerWriter(final ExtendedLogger logger, final String fqcn, final Level level, final Marker marker) {
         this.logger = new CharStreamLogger(logger, level, marker);
         this.fqcn = fqcn;
     }
 
     @Override
     public void write(final int c) throws IOException {
-        if (writer != null) {
-            writer.write(c);
-        }
         logger.put(fqcn, (char) c);
     }
 
     @Override
     public void write(final char[] cbuf) throws IOException {
-        if (writer != null) {
-            writer.write(cbuf);
-        }
         logger.put(fqcn, cbuf, 0, cbuf.length);
     }
 
     @Override
     public void write(final char[] cbuf, final int off, final int len) throws IOException {
-        if (writer != null) {
-            writer.write(cbuf, off, len);
-        }
         logger.put(fqcn, cbuf, off, len);
     }
 
     @Override
     public void write(final String str) throws IOException {
-        if (writer != null) {
-            writer.write(str);
-        }
         logger.put(fqcn, str, 0, str.length());
     }
 
     @Override
     public void write(final String str, final int off, final int len) throws IOException {
-        if (writer != null) {
-            writer.write(str, off, len);
-        }
         logger.put(fqcn, str, off, len);
     }
 
     @Override
     public void flush() throws IOException {
-        if (writer != null) {
-            writer.flush();
-        }
     }
 
     @Override
     public void close() throws IOException {
-        if (writer != null) {
-            writer.close();
-        }
         logger.close(fqcn);
     }
 
-    @Override
     public String toString() {
-        return LoggerWriter.class.getSimpleName() + "{stream=" + writer + '}';
+        return this.getClass().getSimpleName() + "[fqcn=" + fqcn + ", logger=" + logger + "]";
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerWriterFilter.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerWriterFilter.java b/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerWriterFilter.java
new file mode 100644
index 0000000..9b7e3a0
--- /dev/null
+++ b/log4j-streams/src/main/java/org/apache/logging/log4j/streams/LoggerWriterFilter.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.streams;
+
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.spi.ExtendedLogger;
+import org.apache.logging.log4j.streams.util.CharStreamLogger;
+
+/**
+ * Writer that logs each line written to a pre-defined level. Can also be configured with a Marker. This class provides
+ * an interface that follows the {@link java.io.Writer} methods in spirit, but doesn't require output to any external
+ * out.
+ */
+public class LoggerWriterFilter extends FilterWriter {
+    private static final String FQCN = LoggerWriterFilter.class.getName();
+
+    private final CharStreamLogger logger;
+    private final String fqcn;
+
+    public LoggerWriterFilter(final Writer out, final Logger logger, final Level level) {
+        this(out, (ExtendedLogger) logger, FQCN, level, null);
+    }
+
+    public LoggerWriterFilter(final Writer out, final Logger logger, final Level level, final Marker marker) {
+        this(out, (ExtendedLogger) logger, FQCN, level, marker);
+    }
+
+    public LoggerWriterFilter(final Writer out, final ExtendedLogger logger, final String fqcn, final Level level,
+            final Marker marker) {
+        super(out);
+        this.logger = new CharStreamLogger(logger, level, marker);
+        this.fqcn = fqcn;
+    }
+
+    @Override
+    public void write(final int c) throws IOException {
+        out.write(c);
+        logger.put(fqcn, (char) c);
+    }
+
+    @Override
+    public void write(final char[] cbuf) throws IOException {
+        out.write(cbuf);
+        logger.put(fqcn, cbuf, 0, cbuf.length);
+    }
+
+    @Override
+    public void write(final char[] cbuf, final int off, final int len) throws IOException {
+        out.write(cbuf, off, len);
+        logger.put(fqcn, cbuf, off, len);
+    }
+
+    @Override
+    public void write(final String str) throws IOException {
+        out.write(str);
+        logger.put(fqcn, str, 0, str.length());
+    }
+
+    @Override
+    public void write(final String str, final int off, final int len) throws IOException {
+        out.write(str, off, len);
+        logger.put(fqcn, str, off, len);
+    }
+
+    @Override
+    public void flush() throws IOException {
+        out.flush();
+    }
+
+    @Override
+    public void close() throws IOException {
+        out.close();
+        logger.close(fqcn);
+    }
+
+    @Override
+    public String toString() {
+        return LoggerWriterFilter.class.getSimpleName() + "{writer=" + out + '}';
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/AbstractLoggerWriterTest.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/AbstractLoggerWriterTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/AbstractLoggerWriterTest.java
new file mode 100644
index 0000000..5d727cb
--- /dev/null
+++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/AbstractLoggerWriterTest.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.streams;
+
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public abstract class AbstractLoggerWriterTest extends AbstractStreamTest {
+    protected StringWriter wrapped;
+    protected Writer writer;
+
+    @Before
+    public void createStream() {
+        wrapped = createWriter();
+        writer = createWriterWrapper();
+    }
+
+    protected abstract StringWriter createWriter();
+
+    protected abstract Writer createWriterWrapper();
+
+    @Test
+    public void testWrite_CharArray() throws Exception {
+        final char[] chars = FIRST.toCharArray();
+        writer.write(chars);
+        assertMessages();
+        writer.write('\n');
+        assertMessages(FIRST);
+        if (wrapped != null) {
+            assertEquals(FIRST + '\n', wrapped.toString());
+        }
+    }
+
+    @Test
+    public void testWrite_CharArray_Offset_Length() throws Exception {
+        final char[] chars = FIRST.toCharArray();
+        final int middle = chars.length / 2;
+        final int length = chars.length - middle;
+        final String right = new String(chars, middle, length);
+        writer.write(chars, middle, length);
+        assertMessages();
+        writer.write('\n');
+        assertMessages(right);
+        if (wrapped != null) {
+            assertEquals(FIRST.substring(middle, FIRST.length()) + '\n', wrapped.toString());
+        }
+    }
+
+    @Test
+    public void testWrite_Character() throws Exception {
+        for (final char c : FIRST.toCharArray()) {
+            writer.write(c);
+            assertMessages();
+        }
+        writer.write('\n');
+        assertMessages(FIRST);
+        if (wrapped != null) {
+            assertEquals(FIRST + '\n', wrapped.toString());
+        }
+    }
+
+    @Test
+    public void testWrite_IgnoresWindowsNewline() throws IOException {
+        writer.write(FIRST + "\r\n");
+        writer.write(LAST);
+        writer.close();
+        assertMessages(FIRST, LAST);
+        if (wrapped != null) {
+            assertEquals(FIRST + "\r\n" + LAST, wrapped.toString());
+        }
+    }
+
+    @Test
+    public void testWrite_MultipleLines() throws IOException {
+        writer.write(FIRST + '\n' + LAST + '\n');
+        assertMessages(FIRST, LAST);
+        if (wrapped != null) {
+            assertEquals(FIRST + '\n' + LAST + '\n', wrapped.toString());
+        }
+    }
+
+    @Test
+    public void testFlush() throws IOException {
+        final OutputStream out = EasyMock.createMock(OutputStream.class);
+        out.flush(); // expect the flush to come through to the mocked OutputStream
+        out.close();
+        replay(out);
+
+        final LoggerOutputStream los = new LoggerOutputStream(out, getLogger(), LEVEL);
+        los.flush();
+        los.close();
+        verify(out);
+    }
+
+    @Test
+    public void testClose_NoRemainingData() throws IOException {
+        writer.close();
+        assertMessages();
+        if (wrapped != null) {
+            assertEquals("", wrapped.toString());
+        }
+    }
+
+    @Test
+    public void testClose_HasRemainingData() throws IOException {
+        writer.write(FIRST);
+        assertMessages();
+        writer.close();
+        assertMessages(FIRST);
+        if (wrapped != null) {
+            assertEquals(FIRST, wrapped.toString());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/AbstractStreamTest.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/AbstractStreamTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/AbstractStreamTest.java
new file mode 100644
index 0000000..6422309
--- /dev/null
+++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/AbstractStreamTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.streams;
+
+import static org.hamcrest.core.StringStartsWith.startsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Before;
+import org.junit.ClassRule;
+
+public abstract class AbstractStreamTest {
+    protected final static String NEWLINE = System.getProperty("line.separator");
+    protected final static Level LEVEL = Level.ERROR;
+    protected final static String FIRST = "first";
+    protected final static String LAST = "last";
+
+    @ClassRule
+    public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-unit-test.xml");
+
+    protected static Logger getLogger() {
+        return ctx.getLogger("UnitTestLogger");
+    }
+
+    @Before
+    public void clearAppender() {
+        ((ListAppender) ctx.getAppender("UnitTest")).clear();
+    }
+
+    protected void assertMessages(final String... messages) {
+        final List<String> actualMsgs = ((ListAppender) ctx.getAppender("UnitTest")).getMessages();
+        assertEquals("Unexpected number of results.", messages.length, actualMsgs.size());
+        for (int i = 0; i < messages.length; i++) {
+            final String start = LEVEL.name() + ' ' + messages[i];
+            assertThat(actualMsgs.get(i), startsWith(start));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java
index 3d11e02..09e5269 100644
--- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java
+++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java
@@ -27,7 +27,7 @@ import java.io.InputStream;
 import org.junit.Before;
 import org.junit.Test;
 
-public class LoggerInputStreamTest extends StreamTesting {
+public class LoggerInputStreamTest extends AbstractStreamTest {
     protected ByteArrayInputStream wrapped;
     protected ByteArrayOutputStream read;
     protected InputStream in;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java
index 21ebef1..4b9aa36 100644
--- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java
+++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java
@@ -29,7 +29,7 @@ import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Test;
 
-public class LoggerOutputStreamTest extends StreamTesting {
+public class LoggerOutputStreamTest extends AbstractStreamTest {
     protected ByteArrayOutputStream wrapped;
     protected OutputStream out;
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java
index e46f840..7bc799c 100644
--- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java
+++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java
@@ -20,15 +20,20 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
 
 import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.io.Writer;
 
 import org.junit.Test;
 
-public class LoggerPrintWriterTest extends LoggerWriterTest {
+public class LoggerPrintWriterTest extends AbstractLoggerWriterTest {
     private PrintWriter print; 
 
+    protected StringWriter createWriter() {
+        return new StringWriter();
+    }
+
     @Override
-    protected Writer createWriter() {
+    protected Writer createWriterWrapper() {
         print = new LoggerPrintWriter(wrapped, getLogger(), LEVEL);
         return print;
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java
index b41b9c6..8ac5ec9 100644
--- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java
+++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java
@@ -28,7 +28,7 @@ import java.nio.CharBuffer;
 import org.junit.Before;
 import org.junit.Test;
 
-public class LoggerReaderTest extends StreamTesting {
+public class LoggerReaderTest extends AbstractStreamTest {
     protected StringReader wrapped;
     protected StringWriter read;
     protected Reader reader;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterFilterTest.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterFilterTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterFilterTest.java
new file mode 100644
index 0000000..c3aac1c
--- /dev/null
+++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterFilterTest.java
@@ -0,0 +1,16 @@
+package org.apache.logging.log4j.streams;
+
+import java.io.StringWriter;
+import java.io.Writer;
+
+public class LoggerWriterFilterTest extends AbstractLoggerWriterTest {
+
+    protected StringWriter createWriter() {
+        return new StringWriter();
+    }
+
+    protected Writer createWriterWrapper() {
+        return new LoggerWriterFilter(wrapped, getLogger(), LEVEL);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java
index ea188af..b52e468 100644
--- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java
+++ b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java
@@ -1,124 +1,16 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 package org.apache.logging.log4j.streams;
 
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.io.OutputStream;
 import java.io.StringWriter;
 import java.io.Writer;
 
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class LoggerWriterTest extends StreamTesting {
-    protected StringWriter wrapped;
-    protected Writer writer;
-
-    @Before
-    public void createStream() {
-        wrapped = new StringWriter();
-        writer = createWriter();
-    }
-
-    protected Writer createWriter() {
-        return new LoggerWriter(wrapped, getLogger(), LEVEL);
-    }
-
-    @Test
-    public void testWrite_CharArray() throws Exception {
-        final char[] chars = FIRST.toCharArray();
-        writer.write(chars);
-        assertMessages();
-        writer.write('\n');
-        assertMessages(FIRST);
-        assertEquals(FIRST + '\n', wrapped.toString());
-    }
-
-    @Test
-    public void testWrite_CharArray_Offset_Length() throws Exception {
-        final char[] chars = FIRST.toCharArray();
-        final int middle = chars.length / 2;
-        final int length = chars.length - middle;
-        final String right = new String(chars, middle, length);
-        writer.write(chars, middle, length);
-        assertMessages();
-        writer.write('\n');
-        assertMessages(right);
-        assertEquals(FIRST.substring(middle, FIRST.length()) + '\n', wrapped.toString());
-    }
-
-    @Test
-    public void testWrite_Character() throws Exception {
-        for (final char c : FIRST.toCharArray()) {
-            writer.write(c);
-            assertMessages();
-        }
-        writer.write('\n');
-        assertMessages(FIRST);
-        assertEquals(FIRST + '\n', wrapped.toString());
-    }
+public class LoggerWriterTest extends AbstractLoggerWriterTest {
 
-    @Test
-    public void testWrite_IgnoresWindowsNewline() throws IOException {
-        writer.write(FIRST + "\r\n");
-        writer.write(LAST);
-        writer.close();
-        assertMessages(FIRST, LAST);
-        assertEquals(FIRST + "\r\n" + LAST, wrapped.toString());
+    protected StringWriter createWriter() {
+        return null;
     }
 
-    @Test
-    public void testWrite_MultipleLines() throws IOException {
-        writer.write(FIRST + '\n' + LAST + '\n');
-        assertMessages(FIRST, LAST);
-        assertEquals(FIRST + '\n' + LAST + '\n', wrapped.toString());
+    protected Writer createWriterWrapper() {
+        return new LoggerWriter(getLogger(), LEVEL);
     }
 
-    @Test
-    public void testFlush() throws IOException {
-        final OutputStream out = EasyMock.createMock(OutputStream.class);
-        out.flush(); // expect the flush to come through to the mocked OutputStream
-        out.close();
-        replay(out);
-
-        final LoggerOutputStream los = new LoggerOutputStream(out, getLogger(), LEVEL);
-        los.flush();
-        los.close();
-        verify(out);
-    }
-
-    @Test
-    public void testClose_NoRemainingData() throws IOException {
-        writer.close();
-        assertMessages();
-        assertEquals("", wrapped.toString());
-    }
-
-    @Test
-    public void testClose_HasRemainingData() throws IOException {
-        writer.write(FIRST);
-        assertMessages();
-        writer.close();
-        assertMessages(FIRST);
-        assertEquals(FIRST, wrapped.toString());
-    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3faca25d/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java
----------------------------------------------------------------------
diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java
deleted file mode 100644
index c2d9a61..0000000
--- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/StreamTesting.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.logging.log4j.streams;
-
-import static org.hamcrest.core.StringStartsWith.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
-import java.util.List;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-
-@Ignore
-public class StreamTesting {
-    protected final static String NEWLINE = System.getProperty("line.separator");
-    protected final static Level LEVEL = Level.ERROR;
-    protected final static String FIRST = "first";
-    protected final static String LAST = "last";
-
-    @ClassRule
-    public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-unit-test.xml");
-
-    protected static Logger getLogger() {
-        return ctx.getLogger("UnitTestLogger");
-    }
-
-    @Before
-    public void clearAppender() {
-        ((ListAppender) ctx.getAppender("UnitTest")).clear();
-    }
-
-    protected void assertMessages(final String... messages) {
-        final List<String> actualMsgs = ((ListAppender) ctx.getAppender("UnitTest")).getMessages();
-        assertEquals("Unexpected number of results.", messages.length, actualMsgs.size());
-        for (int i = 0; i < messages.length; i++) {
-            final String start = LEVEL.name() + ' ' + messages[i];
-            assertThat(actualMsgs.get(i), startsWith(start));
-        }
-    }
-}