use of java.util.logging.ConsoleHandler in project j2objc by google.
the class ConsoleHandlerTest method testClose_SufficientPrivilege_DirectClose.
/*
* Test close() when having sufficient privilege, and no record has been
* written to the output stream.
*/
public void testClose_SufficientPrivilege_DirectClose() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
ConsoleHandler h = new ConsoleHandler();
h.close();
assertEquals("flush", CallVerificationStack.getInstance().getCurrentSourceMethod());
assertNull(CallVerificationStack.getInstance().pop());
assertTrue(CallVerificationStack.getInstance().empty());
}
use of java.util.logging.ConsoleHandler in project j2objc by google.
the class ConsoleHandlerTest method testConstructor_InvalidProperties.
/*
* Test the constructor with invalid relevant log manager properties are
* set.
*/
public void testConstructor_InvalidProperties() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.ConsoleHandler.level", INVALID_LEVEL);
p.put("java.util.logging.ConsoleHandler.filter", className);
p.put("java.util.logging.ConsoleHandler.formatter", className);
p.put("java.util.logging.ConsoleHandler.encoding", "XXXX");
LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
assertEquals(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.level"), INVALID_LEVEL);
assertEquals(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.encoding"), "XXXX");
ConsoleHandler h = new ConsoleHandler();
assertSame(h.getLevel(), Level.INFO);
assertTrue(h.getFormatter() instanceof SimpleFormatter);
assertNull(h.getFilter());
assertNull(h.getEncoding());
h.publish(new LogRecord(Level.SEVERE, "test"));
assertNull(h.getEncoding());
}
use of java.util.logging.ConsoleHandler in project j2objc by google.
the class ConsoleHandlerTest method testClose_SufficientPrivilege_NormalClose.
/*
* Test close() when having sufficient privilege, and a record has been
* written to the output stream.
*/
public void testClose_SufficientPrivilege_NormalClose() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
ConsoleHandler h = new ConsoleHandler();
h.publish(new LogRecord(Level.SEVERE, "testClose_SufficientPrivilege_NormalClose msg"));
h.close();
assertEquals("flush", CallVerificationStack.getInstance().getCurrentSourceMethod());
assertNull(CallVerificationStack.getInstance().pop());
h.close();
}
use of java.util.logging.ConsoleHandler in project j2objc by google.
the class ConsoleHandlerTest method testClose_SufficientPrivilege_Exception.
/*
* Test close() when having sufficient privilege, and an output stream that
* always throws exceptions.
*/
public void testClose_SufficientPrivilege_Exception() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
ConsoleHandler h = new ConsoleHandler();
h.publish(new LogRecord(Level.SEVERE, "testClose_SufficientPrivilege_Exception msg"));
h.flush();
h.close();
}
use of java.util.logging.ConsoleHandler in project j2objc by google.
the class ConsoleHandlerTest method testConstructor_ValidProperties.
/*
* Test the constructor with insufficient privilege.
*
public void testConstructor_InsufficientPrivilege() {
assertNull(LogManager.getLogManager().getProperty(
"java.util.logging.ConsoleHandler.level"));
assertNull(LogManager.getLogManager().getProperty(
"java.util.logging.ConsoleHandler.filter"));
assertNull(LogManager.getLogManager().getProperty(
"java.util.logging.ConsoleHandler.formatter"));
assertNull(LogManager.getLogManager().getProperty(
"java.util.logging.ConsoleHandler.encoding"));
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
// set a normal value
try {
ConsoleHandler h = new ConsoleHandler();
assertSame(h.getLevel(), Level.INFO);
assertTrue(h.getFormatter() instanceof SimpleFormatter);
assertNull(h.getFilter());
assertSame(h.getEncoding(), null);
} finally {
System.setSecurityManager(oldMan);
}
}
*/
/*
* Test the constructor with valid relevant log manager properties are set.
*/
public void testConstructor_ValidProperties() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.ConsoleHandler.level", "FINE");
p.put("java.util.logging.ConsoleHandler.filter", className + "$MockFilter");
p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
p.put("java.util.logging.ConsoleHandler.encoding", "iso-8859-1");
LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
assertEquals(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.level"), "FINE");
assertEquals(LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.encoding"), "iso-8859-1");
ConsoleHandler h = new ConsoleHandler();
assertSame(h.getLevel(), Level.parse("FINE"));
assertTrue(h.getFormatter() instanceof MockFormatter);
assertTrue(h.getFilter() instanceof MockFilter);
assertEquals(h.getEncoding(), "iso-8859-1");
}
Aggregations