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();
}
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);
}
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
}
}
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());
}
use of java.util.logging.SimpleFormatter in project j2objc by google.
the class StreamHandlerTest method testIsLoggable_NoFilter.
/*
* Test isLoggable(), use no filter, having output stream
*/
public void testIsLoggable_NoFilter() {
StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), new SimpleFormatter());
LogRecord r = new LogRecord(Level.INFO, null);
assertTrue(h.isLoggable(r));
h.setLevel(Level.WARNING);
assertFalse(h.isLoggable(r));
h.setLevel(Level.CONFIG);
assertTrue(h.isLoggable(r));
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
assertFalse(h.isLoggable(r));
}
Aggregations