use of java.util.logging.Logger in project j2objc by google.
the class LoggerTest method testRemoveHandler_AnonyLoggerSufficientPrivilege.
/*
* Test removeHandler(Handler) for a named logger with insufficient
* privilege.
*
public void testRemoveHandler_NamedLoggerInsufficientPrivilege() {
Logger log = Logger
.getLogger("testRemoveHandler_NamedLoggerInsufficientPrivilege");
MockHandler h = new MockHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.removeHandler(h);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test removeHandler(Handler) for a named logger with insufficient
* privilege, using a null handler.
*
public void testRemoveHandler_NamedLoggerInsufficientPrivilegeNull() {
Logger log = Logger
.getLogger("testRemoveHandler_NamedLoggerInsufficientPrivilege");
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.removeHandler(null);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test removeHandler(Handler) for an anonymous logger with sufficient
* privilege.
*/
public void testRemoveHandler_AnonyLoggerSufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
MockHandler h = new MockHandler();
log.addHandler(h);
assertEquals(log.getHandlers().length, 1);
log.removeHandler(h);
assertEquals(log.getHandlers().length, 0);
}
use of java.util.logging.Logger in project j2objc by google.
the class LoggerTest method testGetName_Empty.
/*
* Test getName() for empty name.
*/
public void testGetName_Empty() {
Logger log = Logger.getLogger("");
assertEquals("", log.getName());
Logger mlog = new MockLogger("", null);
assertEquals("", mlog.getName());
}
use of java.util.logging.Logger in project j2objc by google.
the class LoggerTest method testGetResourceBundle_Null.
/*
* Test getResourceBundle() when it it null.
*/
public void testGetResourceBundle_Null() {
Logger log = Logger.getLogger("testGetResourceBundle_Null", null);
assertNull(log.getResourceBundle());
Logger mlog = new MockLogger(null, null);
assertNull(mlog.getResourceBundle());
}
use of java.util.logging.Logger in project j2objc by google.
the class LoggerTest method testGetLoggerWithRes_ExistingLoggerWithSameRes.
/*
* Test getLogger(String, String) with valid resource bundle, to get an
* existing logger with the same associated resource bundle.
*/
public void testGetLoggerWithRes_ExistingLoggerWithSameRes() {
assertNull(LogManager.getLogManager().getLogger("testGetLoggerWithRes_ExistingLoggerWithSameRes_ANewLogger"));
// create a new logger
Logger log1 = Logger.getLogger("testGetLoggerWithRes_ExistingLoggerWithSameRes_ANewLogger", VALID_RESOURCE_BUNDLE);
// get an existing logger
Logger log2 = Logger.getLogger("testGetLoggerWithRes_ExistingLoggerWithSameRes_ANewLogger", VALID_RESOURCE_BUNDLE);
assertSame(log1, log2);
assertEquals(VALID_VALUE, log1.getResourceBundle().getString(VALID_KEY));
assertEquals(log1.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
}
use of java.util.logging.Logger in project j2objc by google.
the class LoggerTest method testFinest_Null.
/*
* Test finest(String) with null values.
*/
public void testFinest_Null() {
Logger child = new MockLogger("childLogger", null);
Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
child.addHandler(new MockHandler());
child.setParent(parent);
child.setLevel(Level.FINEST);
child.finest(null);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), child.getName());
assertNull(r.getMessage());
assertSame(r.getResourceBundleName(), parent.getResourceBundleName());
assertSame(r.getResourceBundle(), parent.getResourceBundle());
assertSame(r.getSourceClassName(), null);
assertSame(r.getSourceMethodName(), null);
assertSame(r.getLevel(), Level.FINEST);
assertNull(r.getParameters());
assertSame(r.getThrown(), null);
this.sharedLogger.setLevel(Level.FINER);
this.sharedLogger.finest(null);
assertTrue(CallVerificationStack.getInstance().empty());
}
Aggregations