use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testPublish_NoFilter.
/*
* Test publish(), use no filter, having output stream, normal log record.
*/
public void testPublish_NoFilter() {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFilter");
h.setLevel(Level.INFO);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter", aos.toString());
h.setLevel(Level.WARNING);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter", aos.toString());
h.setLevel(Level.CONFIG);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter" + "testPublish_NoFilter", aos.toString());
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter" + "testPublish_NoFilter", aos.toString());
}
use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testPublish_EmptyMsg.
/*
* Test publish(), a log record with empty msg, having output stream
*/
public void testPublish_EmptyMsg() {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
LogRecord r = new LogRecord(Level.INFO, "");
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head", aos.toString());
}
use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testConstructor_NoParameter_ValidProperties.
/*
* Test the constructor with insufficient privilege.
*
public void testConstructor_NoParameter_InsufficientPrivilege() {
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"));
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
// set a normal value
try {
StreamHandler h = new StreamHandler();
assertSame(Level.INFO, h.getLevel());
assertTrue(h.getFormatter() instanceof SimpleFormatter);
assertNull(h.getFilter());
assertNull(h.getEncoding());
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test the constructor with no parameter, and valid relevant log manager
* properties are set.
*/
public void testConstructor_NoParameter_ValidProperties() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.StreamHandler.level", "FINE");
p.put("java.util.logging.StreamHandler.filter", className + "$MockFilter");
p.put("java.util.logging.StreamHandler.formatter", className + "$MockFormatter");
p.put("java.util.logging.StreamHandler.encoding", "iso-8859-1");
LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
assertEquals("FINE", LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.level"));
assertEquals("iso-8859-1", LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.encoding"));
StreamHandler h = new StreamHandler();
assertSame(h.getLevel(), Level.parse("FINE"));
assertTrue(h.getFormatter() instanceof MockFormatter);
assertTrue(h.getFilter() instanceof MockFilter);
assertEquals("iso-8859-1", h.getEncoding());
}
use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest 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() {
ByteArrayOutputStream aos = new MockOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.publish(new LogRecord(Level.SEVERE, "testClose_SufficientPrivilege_NormalClose msg"));
h.close();
assertEquals("close", CallVerificationStack.getInstance().getCurrentSourceMethod());
assertNull(CallVerificationStack.getInstance().pop());
assertEquals("flush", CallVerificationStack.getInstance().getCurrentSourceMethod());
CallVerificationStack.getInstance().clear();
assertTrue(aos.toString().endsWith("MockFormatter_Tail"));
h.close();
}
use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testConstructor_HasParameters_NoProperties.
/*
* Test the constructor with normal parameter values, and no relevant log
* manager properties are set.
*/
public void testConstructor_HasParameters_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(new ByteArrayOutputStream(), new MockFormatter2());
assertSame(Level.INFO, h.getLevel());
assertTrue(h.getFormatter() instanceof MockFormatter2);
assertNull(h.getFilter());
assertNull(h.getEncoding());
}
Aggregations