use of java.util.logging.Logger in project j2objc by google.
the class LoggerTest method testLog_ParentNotInformed.
/*
* Test that the parent's handler is notified for a new log record when
* getUseParentHandlers() is false.
*/
public void testLog_ParentNotInformed() {
Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE);
Logger parent = new MockParentLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
child.setParent(parent);
child.setLevel(Level.INFO);
parent.setLevel(Level.INFO);
parent.addHandler(new MockHandler());
LogRecord r = new LogRecord(Level.INFO, "testLog_ParentInformed");
child.setUseParentHandlers(false);
child.log(r);
assertFalse(child.getUseParentHandlers());
assertTrue(CallVerificationStack.getInstance().empty());
}
use of java.util.logging.Logger in project j2objc by google.
the class LoggerTest method testGetName_Normal.
/*
* Test setParent(Logger), having insufficient privilege.
*
public void testSetParent_InsufficientPrivilege() {
MockLogger log = new MockLogger(null, null);
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.setParent(log);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test setParent(Logger) with null, having insufficient privilege.
*
public void testSetParent_InsufficientPrivilegeNull() {
MockLogger log = new MockLogger(null, null);
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.setParent(null);
fail("Should throw NullPointerException!");
} catch (NullPointerException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test setParent(Logger) for an anonymous logger with insufficient
* privilege.
*
public void testSetParent_AnonyLoggerInsufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.setParent(log);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test getName() for normal names.
*/
public void testGetName_Normal() {
Logger log = Logger.getLogger("testGetName_Normal");
assertEquals("testGetName_Normal", log.getName());
Logger mlog = new MockLogger("testGetName_Normal", null);
assertEquals("testGetName_Normal", mlog.getName());
}
use of java.util.logging.Logger in project j2objc by google.
the class LoggerTest method testAddHandler_AnonyLoggerSufficientPrivilege.
/*
* Test addHandler(Handler) for a named logger with insufficient privilege.
*
public void testAddHandler_NamedLoggerInsufficientPrivilege() {
Logger log = Logger
.getLogger("testAddHandler_NamedLoggerInsufficientPrivilege");
MockHandler h = new MockHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.addHandler(h);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test addHandler(Handler) for a named logger with insufficient privilege,
* using a null handler.
*
public void testAddHandler_NamedLoggerInsufficientPrivilegeNull() {
Logger log = Logger
.getLogger("testAddHandler_NamedLoggerInsufficientPrivilege");
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.addHandler(null);
fail("Should throw NullPointerException!");
} catch (NullPointerException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test addHandler(Handler) for an anonymous logger with sufficient
* privilege.
*/
public void testAddHandler_AnonyLoggerSufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
MockHandler h = new MockHandler();
assertEquals(log.getHandlers().length, 0);
log.addHandler(h);
assertEquals(log.getHandlers().length, 1);
assertSame(log.getHandlers()[0], h);
}
use of java.util.logging.Logger in project j2objc by google.
the class LoggerTest method testGetAnonymousLogger_ValidResourceBundle.
/*
* Test getAnonymousLogger(String resourceBundleName) with valid resource
* bundle.
*/
public void testGetAnonymousLogger_ValidResourceBundle() {
Logger alog = Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE);
assertNotSame(alog, Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE));
assertNull(alog.getFilter());
assertEquals(0, alog.getHandlers().length);
assertNull(alog.getLevel());
assertNull(alog.getName());
assertNull(alog.getParent().getParent());
assertEquals(VALID_VALUE, alog.getResourceBundle().getString(VALID_KEY));
assertEquals(alog.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
assertTrue(alog.getUseParentHandlers());
}
use of java.util.logging.Logger in project j2objc by google.
the class LoggerTest method testLog_NullResHasParent.
/*
* Test that a logger inherits its parent resource bundle when its resource
* bundle is null.
*/
public void testLog_NullResHasParent() {
Logger child = new MockLogger("childLogger", null);
Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
child.addHandler(new MockHandler());
child.setParent(parent);
parent.setLevel(Level.FINER);
assertNull(child.getResourceBundle());
assertNull(child.getResourceBundleName());
child.log(Level.FINE, "testLog_NullResHasParent");
// pop only once, pushed by the child logger's handler
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), "childLogger");
assertEquals(r.getMessage(), "testLog_NullResHasParent");
assertSame(r.getResourceBundleName(), VALID_RESOURCE_BUNDLE2);
assertSame(r.getSourceClassName(), null);
assertSame(r.getSourceMethodName(), null);
assertSame(r.getLevel(), Level.FINE);
assertNull(r.getParameters());
assertSame(r.getThrown(), null);
assertNull(child.getResourceBundle());
assertNull(child.getResourceBundleName());
}
Aggregations