Search in sources :

Example 1 with NullOutputStream

use of org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream in project j2objc by google.

the class MemoryHandlerTest method setUp.

/*
	 * @see TestCase#setUp()
	 */
protected void setUp() throws Exception {
    super.setUp();
    manager.reset();
    initProps();
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    errSubstituteStream = new NullOutputStream();
    System.setErr(new PrintStream(errSubstituteStream));
}
Also used : PrintStream(java.io.PrintStream) MemoryHandler(java.util.logging.MemoryHandler) NullOutputStream(org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream)

Example 2 with NullOutputStream

use of org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream in project j2objc by google.

the class StreamHandlerTest method setUp.

/*
	 * @see TestCase#setUp()
	 */
protected void setUp() throws Exception {
    super.setUp();
    errSubstituteStream = new NullOutputStream();
    System.setErr(new PrintStream(errSubstituteStream));
}
Also used : PrintStream(java.io.PrintStream) NullOutputStream(org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream)

Example 3 with NullOutputStream

use of org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream in project j2objc by google.

the class LogManagerTest method testGlobalPropertyConfig.

public void testGlobalPropertyConfig() throws Exception {
    PrintStream err = System.err;
    try {
        System.setErr(new PrintStream(new NullOutputStream()));
        // before add config property, root has two handler
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        assertEquals(2, manager.getLogger("").getHandlers().length);
        // one valid config class
        props.setProperty("config", className + "$MockValidConfig");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        assertEquals(3, manager.getLogger("").getHandlers().length);
        // two config class take effect orderly
        props.setProperty("config", className + "$MockValidConfig " + className + "$MockValidConfig2");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        assertEquals(2, manager.getLogger("").getHandlers().length);
        props.setProperty("config", className + "$MockValidConfig2 " + className + "$MockValidConfig");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        assertEquals(3, manager.getLogger("").getHandlers().length);
        // invalid config class which throw exception, just print exception
        // and
        // message
        props.setProperty("config", className + "$MockInvalidConfigException");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        // invalid config class without default constructor, just print
        // exception and message
        props.setProperty("config", className + "$MockInvalidConfigNoDefaultConstructor");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        // bad config class name, just print exception and message
        props.setProperty("config", "badname");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        // invalid separator, nothing happened
        props.setProperty("config", className + "$MockValidConfig2;" + className + "$MockValidConfig");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        assertEquals(2, manager.getLogger("").getHandlers().length);
        props.setProperty("config", className + "$MockValidConfig2;" + className + "$MockValidConfig " + className + "$MockValidConfig");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        assertEquals(3, manager.getLogger("").getHandlers().length);
        // duplicate config class, take effect twice
        props.setProperty("config", className + "$MockValidConfig " + className + "$MockValidConfig");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        assertEquals(4, manager.getLogger("").getHandlers().length);
        // invalid config classes mixed with valid config classes, valid
        // config
        // classes take effect
        props.setProperty("config", "badname " + className + "$MockValidConfig " + className + "$MockInvalidConfigNoDefaultConstructor " + className + "$MockValidConfig");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        assertEquals(4, manager.getLogger("").getHandlers().length);
        // global property take effect before logger specified property
        props.setProperty("config", className + "$MockValidConfig");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        assertEquals(Level.FINE, manager.getLogger("").getLevel());
    } finally {
        System.setErr(err);
    }
}
Also used : PrintStream(java.io.PrintStream) NullOutputStream(org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream)

Example 4 with NullOutputStream

use of org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream in project j2objc by google.

the class ErrorManagerTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    errSubstituteStream = new NullOutputStream();
    System.setErr(new PrintStream(errSubstituteStream));
}
Also used : PrintStream(java.io.PrintStream) NullOutputStream(org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream)

Aggregations

PrintStream (java.io.PrintStream)4 NullOutputStream (org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream)4 MemoryHandler (java.util.logging.MemoryHandler)1