use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testConstructor_HasParameters_InvalidProperties.
/*
* Test the constructor with normal parameter, and invalid relevant log
* manager properties are set.
*/
public void testConstructor_HasParameters_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(new ByteArrayOutputStream(), new MockFormatter2());
assertSame(Level.INFO, h.getLevel());
assertTrue(h.getFormatter() instanceof MockFormatter2);
assertNull(h.getFilter());
assertNull(h.getEncoding());
}
use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testPublish_WithFilter.
/*
* Test publish(), use a filter, having output stream, normal log record.
*/
public void testPublish_WithFilter() {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.setFilter(new MockFilter());
LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
h.setLevel(Level.INFO);
h.publish(r);
h.flush();
assertEquals("", aos.toString());
assertSame(r, CallVerificationStack.getInstance().pop());
h.setLevel(Level.WARNING);
h.publish(r);
h.flush();
assertEquals("", aos.toString());
assertTrue(CallVerificationStack.getInstance().empty());
h.setLevel(Level.CONFIG);
h.publish(r);
h.flush();
assertEquals("", aos.toString());
assertSame(r, CallVerificationStack.getInstance().pop());
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
h.publish(r);
h.flush();
assertEquals("", aos.toString());
assertTrue(CallVerificationStack.getInstance().empty());
}
use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testSetEncoding_Unsupported.
/*
* Test setEncoding() methods with unsupported encoding.
*/
public void testSetEncoding_Unsupported() {
StreamHandler h = new StreamHandler();
try {
h.setEncoding("impossible");
fail("Should throw UnsupportedEncodingException!");
} catch (UnsupportedEncodingException e) {
// expected
}
assertNull(h.getEncoding());
}
use of java.util.logging.StreamHandler 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());
}
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());
}
Aggregations