use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testPublish_Null.
/*
* Test publish(), null log record, handler should call ErrorManager to
* handle exceptional case
*/
public void testPublish_Null() {
StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), new SimpleFormatter());
h.publish(null);
}
use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testSetEncoding_FlushBeforeSetting.
/*
* Test setEncoding() with insufficient privilege.
*
public void testSetEncoding_InsufficientPrivilege() throws Exception {
StreamHandler h = new StreamHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
// set a normal value
try {
h.setEncoding("iso-8859-1");
fail("Should throw SecurityException!");
} catch (SecurityException e) {
// expected
} finally {
System.setSecurityManager(oldMan);
}
assertNull(h.getEncoding());
System.setSecurityManager(new MockSecurityManager());
// set an invalid value
try {
h.setEncoding("impossible");
fail("Should throw SecurityException!");
} catch (SecurityException e) {
// expected
} finally {
System.setSecurityManager(oldMan);
}
assertNull(h.getEncoding());
}
/*
* Test setEncoding() methods will flush a stream before setting.
*/
public void testSetEncoding_FlushBeforeSetting() throws Exception {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
LogRecord r = new LogRecord(Level.INFO, "abcd");
h.publish(r);
assertFalse(aos.toString().indexOf("abcd") > 0);
h.setEncoding("iso-8859-1");
assertTrue(aos.toString().indexOf("abcd") > 0);
}
use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testPublish_Null_NoOutputStream.
/*
* Test publish(), null log record, without output stream
*/
public void testPublish_Null_NoOutputStream() {
StreamHandler h = new StreamHandler();
h.publish(null);
// regression test for Harmony-1279
MockFilter filter = new MockFilter();
h.setLevel(Level.FINER);
h.setFilter(filter);
LogRecord record = new LogRecord(Level.FINE, "abc");
h.publish(record);
// verify that filter.isLoggable is not called, because there's no
// associated output stream.
assertTrue(CallVerificationStack.getInstance().empty());
}
use of java.util.logging.StreamHandler in project j2objc by google.
the class StreamHandlerTest method testConstructor_HasParameters_ValidProperties.
/*
* Test the constructor with insufficient privilege.
*
public void testConstructor_HasParameter_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(new ByteArrayOutputStream(),
new MockFormatter2());
assertSame(Level.INFO, h.getLevel());
assertTrue(h.getFormatter() instanceof MockFormatter2);
assertNull(h.getFilter());
assertNull(h.getEncoding());
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test the constructor with normal parameter values, and valid relevant log
* manager properties are set.
*/
public void testConstructor_HasParameters_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(new ByteArrayOutputStream(), new MockFormatter2());
assertSame(h.getLevel(), Level.parse("FINE"));
assertTrue(h.getFormatter() instanceof MockFormatter2);
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 testIsLoggable_Null.
/*
* Test isLoggable(), null log record, having output stream. Handler should
* call ErrorManager to handle exceptional case
*/
public void testIsLoggable_Null() {
StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), new SimpleFormatter());
assertFalse(h.isLoggable(null));
}
Aggregations