Repository: logging-log4j2 Updated Branches: refs/heads/master 49aaf52f7 -> b5bc43857
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/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 deleted file mode 100644 index 30ec88a..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerInputStreamTest.java +++ /dev/null @@ -1,127 +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.junit.Assert.assertEquals; - -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -import org.junit.Before; -import org.junit.Test; - -public class LoggerInputStreamTest extends AbstractStreamTest { - protected ByteArrayInputStream wrapped; - protected ByteArrayOutputStream read; - protected InputStream in; - - protected InputStream createInputStream() { - return new LoggerInputStream(this.wrapped, getExtendedLogger(), LEVEL); - } - - @Before - public void createStream() { - this.wrapped = new ByteArrayInputStream((FIRST + "\r\n" + LAST).getBytes()); - this.read = new ByteArrayOutputStream(); - this.in = createInputStream(); - } - - @Test - public void testClose_HasRemainingData() throws IOException { - final byte[] bytes = new byte[1024]; - this.in.read(bytes); - assertMessages(FIRST); - this.in.close(); - assertMessages(FIRST, LAST); - } - - @Test - public void testClose_NoRemainingData() throws IOException { - this.wrapped = new ByteArrayInputStream((FIRST + '\n').getBytes()); - this.in = new LoggerInputStream(this.wrapped, getExtendedLogger(), LEVEL); - - final byte[] bytes = new byte[1024]; - this.in.read(bytes); - assertMessages(FIRST); - this.in.close(); - assertMessages(FIRST); - } - - @Test - public void testRead_ByteArray() throws Exception { - final byte[] bytes = new byte[FIRST.length()]; - assertEquals("len", bytes.length, this.in.read(bytes)); - if (!(this.in instanceof BufferedInputStream)) { - assertMessages(); - } - this.in.read(bytes); - assertMessages(FIRST); - } - - @Test - public void testRead_ByteArray_Offset_Length() throws Exception { - final byte[] bytes = new byte[FIRST.length() * 2]; - assertEquals("len", FIRST.length(), this.in.read(bytes, 0, FIRST.length())); - if (!(this.in instanceof BufferedInputStream)) { - assertMessages(); - } - this.in.read(bytes); - assertMessages(FIRST); - } - - @Test - public void testRead_IgnoresWindowsNewline() throws IOException { - final byte[] bytes = new byte[1024]; - final int len = this.in.read(bytes); - this.read.write(bytes, 0, len); - assertMessages(FIRST); - assertEquals(FIRST + "\r\n" + LAST, this.read.toString()); - this.in.close(); - assertMessages(FIRST, LAST); - } - - @Test - public void testRead_int() throws Exception { - for (int i = 0; i < FIRST.length(); i++) { - this.read.write(this.in.read()); - } - if (!(this.in instanceof BufferedInputStream)) { - assertMessages(); - } - assertEquals("carriage return", '\r', this.in.read()); - if (!(this.in instanceof BufferedInputStream)) { - assertMessages(); - } - assertEquals("newline", '\n', this.in.read()); - assertMessages(FIRST); - } - - @Test - public void testRead_MultipleLines() throws IOException { - this.wrapped = new ByteArrayInputStream((FIRST + "\n" + LAST + '\n').getBytes()); - this.in = new LoggerInputStream(this.wrapped, getExtendedLogger(), LEVEL); - - final byte[] bytes = new byte[1024]; - final int len = this.in.read(bytes); - this.read.write(bytes, 0, len); - assertMessages(FIRST, LAST); - assertEquals(FIRST + '\n' + LAST + '\n', this.read.toString()); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java deleted file mode 100644 index 73fb966..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamCallerInfoTest.java +++ /dev/null @@ -1,50 +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 org.apache.logging.log4j.Level; -import org.junit.Before; -import org.junit.Test; - -public class LoggerOutputStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting { - - private LoggerOutputStream logOut; - - @Before - public void setupStreams() { - this.logOut = new LoggerOutputStream(getExtendedLogger(), Level.WARN); - } - - @Test - public void write() throws Exception { - this.logOut.write('a'); - assertMessages("before write int", 0, "write"); - this.logOut.write('\n'); - assertMessages("after write int", 1, "write"); - - this.logOut.write("b\n".getBytes()); - assertMessages("after write byte array", 2, "write"); - - this.logOut.write("c\n".getBytes(), 0, 2); - assertMessages("after write byte array offset size", 3, "write"); - - this.logOut.write('d'); - assertMessages("before close size", 3, "write"); - this.logOut.close(); - assertMessages("after close size", 4, "write"); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/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 deleted file mode 100644 index 2847a94..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerOutputStreamTest.java +++ /dev/null @@ -1,36 +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 java.io.ByteArrayOutputStream; -import java.io.OutputStream; - -import org.apache.logging.log4j.Level; - -public class LoggerOutputStreamTest extends AbstractLoggerOutputStreamTest { - - @Override - protected ByteArrayOutputStream createOutputStream() { - return null; - } - - @Override - protected OutputStream createOutputStreamWrapper() { - return new LoggerOutputStream(getExtendedLogger(), Level.ERROR); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java deleted file mode 100644 index ad6aeda..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamCallerInfoTest.java +++ /dev/null @@ -1,146 +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 java.io.UnsupportedEncodingException; -import java.util.Locale; - -import org.apache.logging.log4j.Level; -import org.junit.Before; -import org.junit.Test; - -public class LoggerPrintStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting { - - private LoggerPrintStream logOut; - - @Test - public void close() throws Exception { - this.logOut.print("a\nb"); - assertMessages("before close size", 1, "close"); - this.logOut.close(); - assertMessages("after close size", 2, "close"); - } - - @Test - public void print_boolean() throws Exception { - this.logOut.print(true); - assertMessages("print", 0, "print_boolean"); - this.logOut.println(true); - assertMessages("println", 1, "print_boolean"); - } - - @Test - public void print_char() throws Exception { - this.logOut.print('a'); - assertMessages("print", 0, "print_char"); - this.logOut.println('b'); - assertMessages("println", 1, "print_char"); - } - - @Test - public void print_chararray() throws Exception { - this.logOut.print("a".toCharArray()); - assertMessages("print", 0, "print_chararray"); - this.logOut.println("b".toCharArray()); - assertMessages("println", 1, "print_chararray"); - } - - @Test - public void print_double() throws Exception { - this.logOut.print(1D); - assertMessages("print", 0, "print_double"); - this.logOut.println(2D); - assertMessages("println", 1, "print_double"); - } - - @Test - public void print_float() throws Exception { - this.logOut.print(1f); - assertMessages("print", 0, "print_float"); - this.logOut.println(2f); - assertMessages("println", 1, "print_float"); - } - - @Test - public void print_int() throws Exception { - this.logOut.print(1); - assertMessages("print", 0, "print_int"); - this.logOut.println(2); - assertMessages("println", 1, "print_int"); - } - - @Test - public void print_long() throws Exception { - this.logOut.print(1L); - assertMessages("print", 0, "print_long"); - this.logOut.println(2L); - assertMessages("println", 1, "print_long"); - } - - @Test - public void print_object() throws Exception { - this.logOut.print((Object) 'a'); - assertMessages("print", 0, "print_object"); - this.logOut.println((Object) 'b'); - assertMessages("println", 1, "print_object"); - } - - @Test - public void print_printf() throws Exception { - this.logOut.printf("a\n"); - assertMessages("println", 1, "print_printf"); - } - - @Test - public void print_printf_locale() throws Exception { - this.logOut.printf(Locale.getDefault(), "a\n"); - assertMessages("println", 1, "print_printf_locale"); - } - - @Test - public void print_string() throws Exception { - this.logOut.print("a"); - assertMessages("print", 0, "print_string"); - this.logOut.println("b"); - assertMessages("println", 1, "print_string"); - } - - @Before - public void setupStreams() throws UnsupportedEncodingException { - this.logOut = new LoggerPrintStream(getLogger(), Level.WARN); - } - - @Test - public void write_bytes() throws Exception { - this.logOut.write("b\n".getBytes()); - assertMessages("write", 1, "write_bytes"); - } - - @Test - public void write_bytes_offset() throws Exception { - this.logOut.write("c\n".getBytes(), 0, 2); - assertMessages("write", 1, "write_bytes_offset"); - } - - @Test - public void write_int() throws Exception { - this.logOut.write('a'); - assertMessages("write int", 0, "write_int"); - this.logOut.write('\n'); - assertMessages("write newline", 1, "write_int"); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java deleted file mode 100644 index b1df321..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintStreamTest.java +++ /dev/null @@ -1,122 +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.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; - -import org.junit.Test; - -public class LoggerPrintStreamTest extends AbstractLoggerOutputStreamTest { - private LoggerPrintStream print; - - @Override - protected ByteArrayOutputStream createOutputStream() { - return new ByteArrayOutputStream(); - } - - @Override - protected OutputStream createOutputStreamWrapper() { - return this.print = new LoggerPrintStream(this.wrapped, getExtendedLogger(), LEVEL); - } - - @Test - public void testFormat() throws Exception { - assertSame(this.print, this.print.format("[%s]", FIRST)); - assertMessages(); - this.print.println(); - assertMessages("[" + FIRST + "]"); - assertEquals("[" + FIRST + "]" + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_boolean() throws Exception { - this.print.print(true); - assertMessages(); - this.print.println(); - assertMessages("true"); - assertEquals("true" + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_char() throws Exception { - for (final char c : FIRST.toCharArray()) { - this.print.print(c); - assertMessages(); - } - this.print.println(); - assertMessages(FIRST); - assertEquals(FIRST + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_CharacterArray() throws Exception { - this.print.print(FIRST.toCharArray()); - assertMessages(); - this.print.println(); - assertMessages(FIRST); - assertEquals(FIRST + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_int() throws Exception { - this.print.print(12); - assertMessages(); - this.print.println(); - assertMessages("12"); - assertEquals("12" + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_long() throws Exception { - this.print.print(12L); - assertMessages(); - this.print.println(); - assertMessages("12"); - assertEquals("12" + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_Object() throws Exception { - this.print.print((Object) FIRST); - assertMessages(); - this.print.println(); - assertMessages(FIRST); - assertEquals(FIRST + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_String() throws Exception { - this.print.print(FIRST); - assertMessages(); - this.print.println(); - assertMessages(FIRST); - assertEquals(FIRST + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrintf() throws Exception { - assertSame(this.print, this.print.printf("<<<%s>>>", FIRST)); - assertMessages(); - this.print.println(); - assertMessages("<<<" + FIRST + ">>>"); - assertEquals("<<<" + FIRST + ">>>" + NEWLINE, this.wrapped.toString()); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java deleted file mode 100644 index 16e271e..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterCallerInfoTest.java +++ /dev/null @@ -1,145 +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 java.util.Locale; - -import org.apache.logging.log4j.Level; -import org.junit.Before; -import org.junit.Test; - -public class LoggerPrintWriterCallerInfoTest extends LoggerStreamsCallerInfoTesting { - - private LoggerPrintWriter logOut; - - @Test - public void close() throws Exception { - this.logOut.print("a\nb"); - assertMessages("before close size", 1, "close"); - this.logOut.close(); - assertMessages("after close size", 2, "close"); - } - - @Test - public void print_boolean() throws Exception { - this.logOut.print(true); - assertMessages("print", 0, "print_boolean"); - this.logOut.println(true); - assertMessages("println", 1, "print_boolean"); - } - - @Test - public void print_char() throws Exception { - this.logOut.print('a'); - assertMessages("print", 0, "print_char"); - this.logOut.println('b'); - assertMessages("println", 1, "print_char"); - } - - @Test - public void print_chararray() throws Exception { - this.logOut.print("a".toCharArray()); - assertMessages("print", 0, "print_chararray"); - this.logOut.println("b".toCharArray()); - assertMessages("println", 1, "print_chararray"); - } - - @Test - public void print_double() throws Exception { - this.logOut.print(1D); - assertMessages("print", 0, "print_double"); - this.logOut.println(2D); - assertMessages("println", 1, "print_double"); - } - - @Test - public void print_float() throws Exception { - this.logOut.print(1f); - assertMessages("print", 0, "print_float"); - this.logOut.println(2f); - assertMessages("println", 1, "print_float"); - } - - @Test - public void print_int() throws Exception { - this.logOut.print(1); - assertMessages("print", 0, "print_int"); - this.logOut.println(2); - assertMessages("println", 1, "print_int"); - } - - @Test - public void print_long() throws Exception { - this.logOut.print(1L); - assertMessages("print", 0, "print_long"); - this.logOut.println(2L); - assertMessages("println", 1, "print_long"); - } - - @Test - public void print_object() throws Exception { - this.logOut.print((Object) 'a'); - assertMessages("print", 0, "print_object"); - this.logOut.println((Object) 'b'); - assertMessages("println", 1, "print_object"); - } - - @Test - public void print_printf() throws Exception { - this.logOut.printf("a\n"); - assertMessages("println", 1, "print_printf"); - } - - @Test - public void print_printf_locale() throws Exception { - this.logOut.printf(Locale.getDefault(), "a\n"); - assertMessages("println", 1, "print_printf_locale"); - } - - @Test - public void print_string() throws Exception { - this.logOut.print("a"); - assertMessages("print", 0, "print_string"); - this.logOut.println("b"); - assertMessages("println", 1, "print_string"); - } - - @Before - public void setupStreams() { - this.logOut = new LoggerPrintWriter(getLogger(), Level.WARN); - } - - @Test - public void write_bytes() throws Exception { - this.logOut.write("b\n".toCharArray()); - assertMessages("write", 1, "write_bytes"); - } - - @Test - public void write_bytes_offset() throws Exception { - this.logOut.write("c\n".toCharArray(), 0, 2); - assertMessages("write", 1, "write_bytes_offset"); - } - - @Test - public void write_int() throws Exception { - this.logOut.write('a'); - assertMessages("write int", 0, "write_int"); - this.logOut.write('\n'); - assertMessages("write newline", 1, "write_int"); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/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 deleted file mode 100644 index d10b962..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerPrintWriterTest.java +++ /dev/null @@ -1,124 +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.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 AbstractLoggerWriterTest { - private PrintWriter print; - - @Override - protected StringWriter createWriter() { - return new StringWriter(); - } - - @Override - protected Writer createWriterWrapper() { - this.print = new LoggerPrintWriter(this.wrapped, getExtendedLogger(), LEVEL); - return this.print; - } - - @Test - public void testFormat() throws Exception { - assertSame(this.print, this.print.format("[%s]", FIRST)); - assertMessages(); - this.print.println(); - assertMessages("[" + FIRST + "]"); - assertEquals("[" + FIRST + "]" + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_boolean() throws Exception { - this.print.print(true); - assertMessages(); - this.print.println(); - assertMessages("true"); - assertEquals("true" + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_char() throws Exception { - for (final char c : FIRST.toCharArray()) { - this.print.print(c); - assertMessages(); - } - this.print.println(); - assertMessages(FIRST); - assertEquals(FIRST + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_CharacterArray() throws Exception { - this.print.print(FIRST.toCharArray()); - assertMessages(); - this.print.println(); - assertMessages(FIRST); - assertEquals(FIRST + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_int() throws Exception { - this.print.print(12); - assertMessages(); - this.print.println(); - assertMessages("12"); - assertEquals("12" + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_long() throws Exception { - this.print.print(12L); - assertMessages(); - this.print.println(); - assertMessages("12"); - assertEquals("12" + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_Object() throws Exception { - this.print.print((Object) FIRST); - assertMessages(); - this.print.println(); - assertMessages(FIRST); - assertEquals(FIRST + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrint_String() throws Exception { - this.print.print(FIRST); - assertMessages(); - this.print.println(); - assertMessages(FIRST); - assertEquals(FIRST + NEWLINE, this.wrapped.toString()); - } - - @Test - public void testPrintf() throws Exception { - assertSame(this.print, this.print.printf("<<<%s>>>", FIRST)); - assertMessages(); - this.print.println(); - assertMessages("<<<" + FIRST + ">>>"); - assertEquals("<<<" + FIRST + ">>>" + NEWLINE, this.wrapped.toString()); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java deleted file mode 100644 index 88c2311..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderCallerInfoTest.java +++ /dev/null @@ -1,57 +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 java.io.Reader; -import java.io.StringReader; -import java.nio.CharBuffer; - -import org.junit.Before; -import org.junit.Test; - -public class LoggerReaderCallerInfoTest extends LoggerStreamsCallerInfoTesting { - - LoggerReader logReader; - - @Test - public void read() throws Exception { - this.logReader.read(); - assertMessages("before read int size", 0, "read"); - this.logReader.read(); - assertMessages("after read int size", 1, "read"); - - this.logReader.read(new char[2]); - assertMessages("after read bytes size", 2, "read"); - - this.logReader.read(new char[2], 0, 2); - assertMessages("after read bytes offset size", 3, "read"); - - this.logReader.read(CharBuffer.allocate(2)); - assertMessages("after read charBuffer size", 4, "read"); - - this.logReader.read(); - assertMessages("before close size", 4, "read"); - this.logReader.close(); - assertMessages("after close size", 5, "read"); - } - - @Before - public void setupReader() { - final Reader srcReader = new StringReader("a\nb\nc\nd\ne"); - this.logReader = new LoggerReader(srcReader, getLogger(), LEVEL); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/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 deleted file mode 100644 index 662c8be..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerReaderTest.java +++ /dev/null @@ -1,141 +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.junit.Assert.assertEquals; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.nio.CharBuffer; - -import org.junit.Before; -import org.junit.Test; - -public class LoggerReaderTest extends AbstractStreamTest { - protected StringReader wrapped; - protected StringWriter read; - protected Reader reader; - - protected Reader createReader() { - return new LoggerReader(this.wrapped, getExtendedLogger(), LEVEL); - } - - @Before - public void createStream() { - this.wrapped = new StringReader(FIRST + "\r\n" + LAST); - this.read = new StringWriter(); - this.reader = createReader(); - } - - @Test - public void testClose_HasRemainingData() throws IOException { - final char[] chars = new char[1024]; - this.reader.read(chars); - if (!(this.reader instanceof BufferedReader)) { - assertMessages(FIRST); - } - this.reader.close(); - assertMessages(FIRST, LAST); - } - - @Test - public void testClose_NoRemainingData() throws IOException { - this.wrapped = new StringReader(FIRST + '\n'); - this.reader = createReader(); - - final char[] chars = new char[1024]; - this.reader.read(chars); - assertMessages(FIRST); - this.reader.close(); - assertMessages(FIRST); - } - - @Test - public void testRead_CharArray() throws Exception { - final char[] chars = new char[FIRST.length()]; - assertEquals("len", FIRST.length(), this.reader.read(chars)); - if (!(this.reader instanceof BufferedReader)) { - assertMessages(); - } - this.reader.read(chars); - assertMessages(FIRST); - } - - @Test - public void testRead_CharArray_Offset_Length() throws Exception { - final char[] chars = new char[1024]; - assertEquals("len", FIRST.length(), this.reader.read(chars, 0, FIRST.length())); - if (!(this.reader instanceof BufferedReader)) { - assertMessages(); - } - this.reader.read(chars); - this.reader.close(); - assertMessages(FIRST, LAST); - } - - @Test - public void testRead_CharBuffer() throws Exception { - final CharBuffer chars = CharBuffer.allocate(1024); - assertEquals("len", FIRST.length() + LAST.length() + 2, this.reader.read(chars)); - this.reader.close(); - assertMessages(FIRST, LAST); - } - - @Test - public void testRead_IgnoresWindowsNewline() throws IOException { - final char[] chars = new char[1024]; - final int len = this.reader.read(chars); - this.read.write(chars, 0, len); - if (!(this.reader instanceof BufferedReader)) { - assertMessages(FIRST); - } - assertEquals(FIRST + "\r\n" + LAST, this.read.toString()); - this.reader.close(); - assertMessages(FIRST, LAST); - } - - @Test - public void testRead_int() throws Exception { - for (int i = 0; i < FIRST.length(); i++) { - this.read.write(this.reader.read()); - } - if (!(this.reader instanceof BufferedReader)) { - assertMessages(); - } - assertEquals("carriage return", '\r', this.reader.read()); - if (!(this.reader instanceof BufferedReader)) { - assertMessages(); - } - assertEquals("newline", '\n', this.reader.read()); - assertMessages(FIRST); - } - - @Test - public void testRead_MultipleLines() throws IOException { - this.wrapped = new StringReader(FIRST + "\n" + LAST + '\n'); - this.reader = createReader(); - - final char[] chars = new char[1024]; - final int len = this.reader.read(chars); - this.read.write(chars, 0, len); - assertMessages(FIRST, LAST); - assertEquals(FIRST + '\n' + LAST + '\n', this.read.toString()); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java b/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java deleted file mode 100644 index 0af5a30..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerStreamsCallerInfoTesting.java +++ /dev/null @@ -1,55 +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.junit.Assert.assertEquals; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.core.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 class LoggerStreamsCallerInfoTesting { - - protected static Logger getExtendedLogger() { - return ctx.getLogger("ClassAndMethodLogger"); - } - - protected static Logger getLogger() { - return getExtendedLogger(); - } - - protected final static Level LEVEL = Level.WARN; - - @ClassRule - public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-calling-info.xml"); - - public void assertMessages(final String msg, final int size, final String methodName) { - final ListAppender appender = (ListAppender) ctx.getAppender("ClassAndMethod"); - assertEquals(msg + ".size", size, appender.getMessages().size()); - for (final String message : appender.getMessages()) { - assertEquals(msg + " has incorrect caller info", this.getClass().getName() + '.' + methodName, message); - } - } - - @Before - public void clearAppender() { - ((ListAppender) ctx.getAppender("ClassAndMethod")).clear(); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/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 deleted file mode 100644 index 8378348..0000000 --- a/log4j-streams/src/test/java/org/apache/logging/log4j/streams/LoggerWriterTest.java +++ /dev/null @@ -1,34 +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 java.io.StringWriter; -import java.io.Writer; - -public class LoggerWriterTest extends AbstractLoggerWriterTest { - - @Override - protected StringWriter createWriter() { - return null; - } - - @Override - protected Writer createWriterWrapper() { - return new LoggerWriter(getExtendedLogger(), LEVEL); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml b/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml deleted file mode 100644 index 5f8dfd9..0000000 --- a/log4j-streams/src/test/resources/log4j2-streams-calling-info.xml +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<Configuration name="CallerInformationTest" status="error" packages="org.apache.logging.log4j.test"> - <Appenders> - <List name="ClassAndMethod"> - <PatternLayout pattern="%class.%method"/> - </List> - </Appenders> - <Loggers> - <Logger name="ClassAndMethodLogger" level="info"> - <AppenderRef ref="ClassAndMethod"/> - </Logger> - <Root level="off"/> - </Loggers> -</Configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml ---------------------------------------------------------------------- diff --git a/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml b/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml deleted file mode 100644 index d6f0211..0000000 --- a/log4j-streams/src/test/resources/log4j2-streams-unit-test.xml +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<Configuration name="UnitTest" status="error" packages="org.apache.logging.log4j.test"> - <Appenders> - <List name="UnitTest"> - <PatternLayout pattern="%level %m%n"/> - </List> - </Appenders> - <Loggers> - <Logger name="UnitTestLogger" level="info"> - <AppenderRef ref="UnitTest"/> - </Logger> - <Root level="off"/> - </Loggers> -</Configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffc1a38a/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index d10f730..2abd5b4 100644 --- a/pom.xml +++ b/pom.xml @@ -1003,7 +1003,7 @@ <module>log4j-nosql</module> <module>log4j-web</module> <module>log4j-perf</module> - <module>log4j-streams</module> + <module>log4j-iostreams</module> </modules> <profiles> <profile>
