logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1559415 - /logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java
Date Sat, 18 Jan 2014 20:56:00 GMT
Author: ggregory
Date: Sat Jan 18 20:55:59 2014
New Revision: 1559415

URL: http://svn.apache.org/r1559415
Log:
Sort members.

Modified:
    logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java

Modified: logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java?rev=1559415&r1=1559414&r2=1559415&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/LoggerTest.java
Sat Jan 18 20:55:59 2014
@@ -98,46 +98,25 @@ public class LoggerTest {
     }
 
     @Test
-    public void getLoggerByClass() {
-        final Logger classLogger = LogManager.getLogger(LoggerTest.class);
-        assertNotNull(classLogger);
-    }
-
-    @Test
-    public void getLogger_Class_ParameterizedMessageFactory() {
-        // The TestLogger logger was already created in an instance variable for this class.
-        // The message factory is only used when the logger is created.
-        final ParameterizedMessageFactory messageFactory = ParameterizedMessageFactory.INSTANCE;
-        final TestLogger testLogger = (TestLogger) LogManager.getLogger(TestParameterizedMessageFactory.class,
-                messageFactory);
-        assertNotNull(testLogger);
-        assertEquals(messageFactory, testLogger.getMessageFactory());
-        testLogger.debug("{}", Integer.MAX_VALUE);
-        assertEquals(1, testLogger.getEntries().size());
-        assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0));
-    }
-
-    @Test
-    public void getLogger_Object_ParameterizedMessageFactory() {
+    public void getFormatterLogger_Class() {
         // The TestLogger logger was already created in an instance variable for this class.
         // The message factory is only used when the logger is created.
-        final ParameterizedMessageFactory messageFactory =  ParameterizedMessageFactory.INSTANCE;
-        final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestParameterizedMessageFactory(),
-                messageFactory);
+        final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(TestStringFormatterMessageFactory.class);
         assertNotNull(testLogger);
-        assertEquals(messageFactory, testLogger.getMessageFactory());
-        testLogger.debug("{}", Integer.MAX_VALUE);
+        assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory);
+        assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory());
+        testLogger.debug("%,d", Integer.MAX_VALUE);
         assertEquals(1, testLogger.getEntries().size());
-        assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0));
+        assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
     }
 
     @Test
-    public void getLogger_Class_StringFormatterMessageFactory() {
+    public void getFormatterLogger_Object() {
         // The TestLogger logger was already created in an instance variable for this class.
         // The message factory is only used when the logger is created.
-        final TestLogger testLogger = (TestLogger) LogManager.getLogger(TestStringFormatterMessageFactory.class,
-                StringFormatterMessageFactory.INSTANCE);
+        final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(new TestStringFormatterMessageFactory());
         assertNotNull(testLogger);
+        assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory);
         assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory());
         testLogger.debug("%,d", Integer.MAX_VALUE);
         assertEquals(1, testLogger.getEntries().size());
@@ -145,39 +124,38 @@ public class LoggerTest {
     }
 
     @Test
-    public void getFormatterLogger_Class() {
-        // The TestLogger logger was already created in an instance variable for this class.
-        // The message factory is only used when the logger is created.
-        final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(TestStringFormatterMessageFactory.class);
+    public void getFormatterLogger_String() {
+        final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
+        final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger("getLogger_String_StringFormatterMessageFactory");
         assertNotNull(testLogger);
         assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory);
-        assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory());
+        assertEquals(messageFactory, testLogger.getMessageFactory());
         testLogger.debug("%,d", Integer.MAX_VALUE);
         assertEquals(1, testLogger.getEntries().size());
         assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
     }
 
     @Test
-    public void getLogger_Object_StringFormatterMessageFactory() {
+    public void getLogger_Class_ParameterizedMessageFactory() {
         // The TestLogger logger was already created in an instance variable for this class.
         // The message factory is only used when the logger is created.
-        final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
-        final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestStringFormatterMessageFactory(),
+        final ParameterizedMessageFactory messageFactory = ParameterizedMessageFactory.INSTANCE;
+        final TestLogger testLogger = (TestLogger) LogManager.getLogger(TestParameterizedMessageFactory.class,
                 messageFactory);
         assertNotNull(testLogger);
         assertEquals(messageFactory, testLogger.getMessageFactory());
-        testLogger.debug("%,d", Integer.MAX_VALUE);
+        testLogger.debug("{}", Integer.MAX_VALUE);
         assertEquals(1, testLogger.getEntries().size());
-        assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
+        assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0));
     }
 
     @Test
-    public void getFormatterLogger_Object() {
+    public void getLogger_Class_StringFormatterMessageFactory() {
         // The TestLogger logger was already created in an instance variable for this class.
         // The message factory is only used when the logger is created.
-        final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(new TestStringFormatterMessageFactory());
+        final TestLogger testLogger = (TestLogger) LogManager.getLogger(TestStringFormatterMessageFactory.class,
+                StringFormatterMessageFactory.INSTANCE);
         assertNotNull(testLogger);
-        assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory);
         assertEquals(StringFormatterMessageFactory.INSTANCE, testLogger.getMessageFactory());
         testLogger.debug("%,d", Integer.MAX_VALUE);
         assertEquals(1, testLogger.getEntries().size());
@@ -185,9 +163,11 @@ public class LoggerTest {
     }
 
     @Test
-    public void getLogger_String_ParameterizedMessageFactory() {
+    public void getLogger_Object_ParameterizedMessageFactory() {
+        // The TestLogger logger was already created in an instance variable for this class.
+        // The message factory is only used when the logger is created.
         final ParameterizedMessageFactory messageFactory =  ParameterizedMessageFactory.INSTANCE;
-        final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_ParameterizedMessageFactory",
+        final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestParameterizedMessageFactory(),
                 messageFactory);
         assertNotNull(testLogger);
         assertEquals(messageFactory, testLogger.getMessageFactory());
@@ -197,9 +177,11 @@ public class LoggerTest {
     }
 
     @Test
-    public void getLogger_String_StringFormatterMessageFactory() {
+    public void getLogger_Object_StringFormatterMessageFactory() {
+        // The TestLogger logger was already created in an instance variable for this class.
+        // The message factory is only used when the logger is created.
         final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
-        final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_StringFormatterMessageFactory",
+        final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestStringFormatterMessageFactory(),
                 messageFactory);
         assertNotNull(testLogger);
         assertEquals(messageFactory, testLogger.getMessageFactory());
@@ -209,18 +191,6 @@ public class LoggerTest {
     }
 
     @Test
-    public void getFormatterLogger_String() {
-        final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
-        final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger("getLogger_String_StringFormatterMessageFactory");
-        assertNotNull(testLogger);
-        assertTrue(testLogger.getMessageFactory() instanceof StringFormatterMessageFactory);
-        assertEquals(messageFactory, testLogger.getMessageFactory());
-        testLogger.debug("%,d", Integer.MAX_VALUE);
-        assertEquals(1, testLogger.getEntries().size());
-        assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
-    }
-
-    @Test
     public void getLogger_String_MessageFactoryMismatch() {
         final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
         final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch",
@@ -238,41 +208,33 @@ public class LoggerTest {
     }
 
     @Test
-    public void getStream() {
-        final LoggerStream stream = logger.getStream(Level.DEBUG);
-        stream.println("Debug message 1");
-        stream.print("Debug message 2");
-        stream.println();
-        stream.println(); // verify blank log message
-        stream.print("Debug message 3\n");
-        stream.print("\r\n"); // verify windows EOL works
-        assertEquals(5, results.size());
-        assertThat("Incorrect message", results.get(0), startsWith(" DEBUG Debug message
1"));
-        assertThat("Incorrect message", results.get(1), startsWith(" DEBUG Debug message
2"));
-        assertEquals("Message should be blank-ish", " DEBUG ", results.get(2));
-        assertThat("Incorrect message", results.get(3), startsWith(" DEBUG Debug message
3"));
-        assertEquals("Message should be blank-ish", " DEBUG ", results.get(4));
+    public void getLogger_String_ParameterizedMessageFactory() {
+        final ParameterizedMessageFactory messageFactory =  ParameterizedMessageFactory.INSTANCE;
+        final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_ParameterizedMessageFactory",
+                messageFactory);
+        assertNotNull(testLogger);
+        assertEquals(messageFactory, testLogger.getMessageFactory());
+        testLogger.debug("{}", Integer.MAX_VALUE);
+        assertEquals(1, testLogger.getEntries().size());
+        assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0));
     }
 
     @Test
-    public void getStream_Marker() {
-        final LoggerStream stream = logger.getStream(MarkerManager.getMarker("HI"), Level.INFO);
-        stream.println("Hello, world!");
-        stream.print("How about this?\n");
-        stream.println("Is this thing on?");
-        assertEquals(3, results.size());
-        assertThat("Incorrect message.", results.get(0), startsWith("HI INFO Hello"));
-        assertThat("Incorrect message.", results.get(1), startsWith("HI INFO How about"));
-        assertThat("Incorrect message.", results.get(2), startsWith("HI INFO Is this"));
+    public void getLogger_String_StringFormatterMessageFactory() {
+        final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
+        final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_StringFormatterMessageFactory",
+                messageFactory);
+        assertNotNull(testLogger);
+        assertEquals(messageFactory, testLogger.getMessageFactory());
+        testLogger.debug("%,d", Integer.MAX_VALUE);
+        assertEquals(1, testLogger.getEntries().size());
+        assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
     }
 
     @Test
-    public void printf() {
-        logger.printf(Level.DEBUG, "Debug message %d", 1);
-        logger.printf(Level.DEBUG, MarkerManager.getMarker("Test"), "Debug message %d", 2);
-        assertEquals(2, results.size());
-        assertThat("Incorrect message", results.get(0), startsWith(" DEBUG Debug message
1"));
-        assertThat("Incorrect message", results.get(1), startsWith("Test DEBUG Debug message
2"));
+    public void getLoggerByClass() {
+        final Logger classLogger = LogManager.getLogger(LoggerTest.class);
+        assertNotNull(classLogger);
     }
 
     @Test
@@ -310,6 +272,35 @@ public class LoggerTest {
     }
 
     @Test
+    public void getStream() {
+        final LoggerStream stream = logger.getStream(Level.DEBUG);
+        stream.println("Debug message 1");
+        stream.print("Debug message 2");
+        stream.println();
+        stream.println(); // verify blank log message
+        stream.print("Debug message 3\n");
+        stream.print("\r\n"); // verify windows EOL works
+        assertEquals(5, results.size());
+        assertThat("Incorrect message", results.get(0), startsWith(" DEBUG Debug message
1"));
+        assertThat("Incorrect message", results.get(1), startsWith(" DEBUG Debug message
2"));
+        assertEquals("Message should be blank-ish", " DEBUG ", results.get(2));
+        assertThat("Incorrect message", results.get(3), startsWith(" DEBUG Debug message
3"));
+        assertEquals("Message should be blank-ish", " DEBUG ", results.get(4));
+    }
+
+    @Test
+    public void getStream_Marker() {
+        final LoggerStream stream = logger.getStream(MarkerManager.getMarker("HI"), Level.INFO);
+        stream.println("Hello, world!");
+        stream.print("How about this?\n");
+        stream.println("Is this thing on?");
+        assertEquals(3, results.size());
+        assertThat("Incorrect message.", results.get(0), startsWith("HI INFO Hello"));
+        assertThat("Incorrect message.", results.get(1), startsWith("HI INFO How about"));
+        assertThat("Incorrect message.", results.get(2), startsWith("HI INFO Is this"));
+    }
+
+    @Test
     public void isAllEnabled() {
         assertTrue("Incorrect level", logger.isEnabled(Level.ALL));
     }
@@ -369,6 +360,15 @@ public class LoggerTest {
             results.get(1).startsWith(" DEBUG Debug message"));
     }
 
+    @Test
+    public void printf() {
+        logger.printf(Level.DEBUG, "Debug message %d", 1);
+        logger.printf(Level.DEBUG, MarkerManager.getMarker("Test"), "Debug message %d", 2);
+        assertEquals(2, results.size());
+        assertThat("Incorrect message", results.get(0), startsWith(" DEBUG Debug message
1"));
+        assertThat("Incorrect message", results.get(1), startsWith("Test DEBUG Debug message
2"));
+    }
+
     @Before
     public void setup() {
         results.clear();



Mime
View raw message