Search in sources :

Example 21 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project j2objc by google.

the class StreamHandlerTest method testConstructor_NoParameter_NoProperties.

/*
	 * Test the constructor with no parameter, and no relevant log manager
	 * properties are set.
	 */
public void testConstructor_NoParameter_NoProperties() {
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.level"));
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.filter"));
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.formatter"));
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.encoding"));
    StreamHandler h = new StreamHandler();
    assertSame(Level.INFO, h.getLevel());
    assertTrue(h.getFormatter() instanceof SimpleFormatter);
    assertNull(h.getFilter());
    assertNull(h.getEncoding());
}
Also used : StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter)

Example 22 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project j2objc by google.

the class MemoryHandlerTest method testMemoryHandlerInvalidProps.

public void testMemoryHandlerInvalidProps() throws IOException {
    // null target
    try {
        props.remove("java.util.logging.MemoryHandler.target");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        handler = new MemoryHandler();
        fail("should throw RuntimeException: target must be set");
    } catch (RuntimeException e) {
    }
    // invalid target
    try {
        props.put("java.util.logging.MemoryHandler.target", "badname");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        handler = new MemoryHandler();
        fail("should throw RuntimeException: target must be valid");
    } catch (RuntimeException e) {
    }
    // invalid formatter
    initProps();
    props.put("java.util.logging.MemoryHandler.formatter", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertTrue(handler.getFormatter() instanceof SimpleFormatter);
    // invalid level
    initProps();
    props.put("java.util.logging.MemoryHandler.level", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertEquals(handler.getLevel(), Level.ALL);
    // invalid pushlevel
    initProps();
    props.put("java.util.logging.MemoryHandler.push", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertEquals(handler.getPushLevel(), Level.SEVERE);
    // invalid filter
    initProps();
    props.put("java.util.logging.MemoryHandler.filter", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertNull(handler.getFilter());
    // invalid size
    initProps();
    props.put("java.util.logging.MemoryHandler.size", "-1");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    initProps();
    props.put("java.util.logging.MemoryHandler.size", "badsize");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) MemoryHandler(java.util.logging.MemoryHandler)

Example 23 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project j2objc by google.

the class MemoryHandlerTest method testMemoryHandlerDefaultValue.

public void testMemoryHandlerDefaultValue() throws SecurityException, IOException {
    props.clear();
    props.put("java.util.logging.MemoryHandler.target", baseClassName + "$MockHandler");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertNull(handler.getFilter());
    assertTrue(handler.getFormatter() instanceof SimpleFormatter);
    assertNull(handler.getEncoding());
    assertNotNull(handler.getErrorManager());
    assertEquals(handler.getLevel(), Level.ALL);
    assertEquals(handler.getPushLevel(), Level.SEVERE);
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) MemoryHandler(java.util.logging.MemoryHandler)

Example 24 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project j2objc by google.

the class StreamHandlerTest method testSetOutputStream_null.

/*
	 * Test setOutputStream() with null.
	 */
public void testSetOutputStream_null() {
    MockStreamHandler h = new MockStreamHandler(new ByteArrayOutputStream(), new SimpleFormatter());
    try {
        h.setOutputStream(null);
        fail("Should throw NullPointerException!");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 25 with SimpleFormatter

use of java.util.logging.SimpleFormatter in project j2objc by google.

the class StreamHandlerTest method testConstructor_NoParameter_InvalidProperties.

/*
	 * Test the constructor with no parameter, and invalid relevant log manager
	 * properties are set.
	 */
public void testConstructor_NoParameter_InvalidProperties() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.StreamHandler.level", INVALID_LEVEL);
    p.put("java.util.logging.StreamHandler.filter", className + "");
    p.put("java.util.logging.StreamHandler.formatter", className + "");
    p.put("java.util.logging.StreamHandler.encoding", "XXXX");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    assertEquals(INVALID_LEVEL, LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.level"));
    assertEquals("XXXX", LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.encoding"));
    StreamHandler h = new StreamHandler();
    assertSame(Level.INFO, h.getLevel());
    assertTrue(h.getFormatter() instanceof SimpleFormatter);
    assertNull(h.getFilter());
    assertNull(h.getEncoding());
    h.publish(new LogRecord(Level.SEVERE, "test"));
    assertTrue(CallVerificationStack.getInstance().empty());
    assertNull(h.getEncoding());
}
Also used : LogRecord(java.util.logging.LogRecord) StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) Properties(java.util.Properties)

Aggregations

SimpleFormatter (java.util.logging.SimpleFormatter)40 StreamHandler (java.util.logging.StreamHandler)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 Logger (java.util.logging.Logger)13 FileHandler (java.util.logging.FileHandler)9 LogRecord (java.util.logging.LogRecord)8 Handler (java.util.logging.Handler)7 MockResponse (com.google.mockwebserver.MockResponse)6 IOException (java.io.IOException)6 HttpClient (org.apache.http.client.HttpClient)6 HttpGet (org.apache.http.client.methods.HttpGet)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 ConsoleHandler (java.util.logging.ConsoleHandler)4 Level (java.util.logging.Level)3 Test (org.junit.Test)3 Config (edu.neu.ccs.pyramid.configuration.Config)2 File (java.io.File)2 Properties (java.util.Properties)2 MemoryHandler (java.util.logging.MemoryHandler)2 MockResponse (okhttp3.mockwebserver.MockResponse)2