blob: f2bd62d5857a7efce2e1f68834e9482bc34e5727 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.harmony.logging.tests.java.util.logging;
import java.security.Permission;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.logging.Filter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.LoggingPermission;
import java.io.File;
import java.io.FileInputStream;
import junit.framework.TestCase;
import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper;
import tests.util.CallVerificationStack;
import dalvik.annotation.SideEffect;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
/**
* Test suite for the class java.util.logging.Logger.
*/
@TestTargetClass(Logger.class)
public class LoggerTest extends TestCase {
private final static String VALID_RESOURCE_BUNDLE = "bundles/java/util/logging/res";
private final static String VALID_RESOURCE_BUNDLE2 = "bundles/java/util/logging/res2";
private final static String VALID_RESOURCE_BUNDLE3 = "bundles/java/util/logging/res3";
private final static String INVALID_RESOURCE_BUNDLE = "impossible_not_existing";
private final static String LOGGING_CONFIG_FILE = "src/test/resources/config/java/util/logging/logging.config";
private final static String VALID_KEY = "LOGGERTEST";
private final static String VALID_VALUE = "Test_ZH_CN";
private final static String VALID_VALUE2 = "Test_NoLocale2";
private Logger sharedLogger = null;
private Locale oldLocale = null;
/*
* @see TestCase#setUp() Notice : Logger constructor is protected =>
* MockLogger
*/
protected void setUp() throws Exception {
super.setUp();
LogManager.getLogManager().reset();
oldLocale = Locale.getDefault();
Locale.setDefault(new Locale("zh", "CN"));
sharedLogger = new MockLogger("SharedLogger", VALID_RESOURCE_BUNDLE);
sharedLogger.addHandler(new MockHandler());
}
/*
* Reset the log manager.
*/
protected void tearDown() throws Exception {
CallVerificationStack.getInstance().clear();
Locale.setDefault(oldLocale);
LogManager.getLogManager().reset();
super.tearDown();
}
/*
* Test the global logger
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "Logger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testGlobalLogger() {
assertNull(Logger.global.getFilter());
assertEquals(0, Logger.global.getHandlers().length);
assertNull(Logger.global.getLevel());
assertEquals("global", Logger.global.getName());
assertNull(Logger.global.getParent().getParent());
assertNull(Logger.global.getResourceBundle());
assertNull(Logger.global.getResourceBundleName());
assertTrue(Logger.global.getUseParentHandlers());
assertSame(Logger.global, Logger.getLogger("global"));
assertSame(Logger.global, LogManager.getLogManager()
.getLogger("global"));
}
/*
* Test constructor under normal conditions.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies constructor under normal conditions.",
method = "Logger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testConstructor_Normal() {
MockLogger mlog = new MockLogger("myname", VALID_RESOURCE_BUNDLE);
assertNull(mlog.getFilter());
assertEquals(0, mlog.getHandlers().length);
assertNull(mlog.getLevel());
assertEquals("myname", mlog.getName());
assertNull(mlog.getParent());
ResourceBundle rb = mlog.getResourceBundle();
assertEquals(VALID_VALUE, rb.getString(VALID_KEY));
assertEquals(mlog.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
assertTrue(mlog.getUseParentHandlers());
}
/*
* Test constructor with null parameters.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies constructor with null parameters.",
method = "Logger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testConstructor_Null() {
MockLogger mlog = new MockLogger(null, null);
assertNull(mlog.getFilter());
assertEquals(0, mlog.getHandlers().length);
assertNull(mlog.getLevel());
assertNull(mlog.getName());
assertNull(mlog.getParent());
assertNull(mlog.getResourceBundle());
assertNull(mlog.getResourceBundleName());
assertTrue(mlog.getUseParentHandlers());
}
/*
* Test constructor with invalid name.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies constructor with invalid name.",
method = "Logger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testConstructor_InvalidName() {
MockLogger mlog = new MockLogger("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|",
null);
assertEquals("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|", mlog.getName());
}
/*
* Test constructor with empty name.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies constructor with empty name.",
method = "Logger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testConstructor_EmptyName() {
MockLogger mlog = new MockLogger("", null);
assertEquals("", mlog.getName());
}
/*
* Test constructor with invalid resource bundle name.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies MissingResourceException.",
method = "Logger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testConstructor_InvalidResourceBundle() {
// try anonymous with invalid resource
try {
new MockLogger(null, INVALID_RESOURCE_BUNDLE);
fail("Should throw MissingResourceException!");
} catch (MissingResourceException e) {
// ok !
}
// try named Logger with invalid resource
try {
new MockLogger("testConstructor_InvalidResourceBundle",
INVALID_RESOURCE_BUNDLE);
fail("Should throw MissingResourceException!");
} catch (MissingResourceException e) {
// ok !
}
// try empty string
try {
new MockLogger(null, "");
fail("Should throw MissingResourceException!");
} catch (MissingResourceException e) {
// ok !
}
}
/*
* Test getAnonymousLogger()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getAnonymousLogger",
args = {}
)
public void testGetAnonymousLogger() {
Logger alog = Logger.getAnonymousLogger();
assertNotSame(alog, Logger.getAnonymousLogger());
assertNull(alog.getFilter());
assertEquals(0, alog.getHandlers().length);
assertNull(alog.getLevel());
assertNull(alog.getName());
assertEquals("", alog.getParent().getName());
assertNull(alog.getParent().getParent());
assertNull(alog.getResourceBundle());
assertNull(alog.getResourceBundleName());
assertTrue(alog.getUseParentHandlers());
}
/*
* Test getAnonymousLogger(String resourceBundleName) with valid resource
* bundle.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getAnonymousLogger(String resourceBundleName) with valid resource bundle.",
method = "getAnonymousLogger",
args = {java.lang.String.class}
)
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());
assertEquals("", alog.getParent().getName());
assertNull(alog.getParent().getParent());
assertEquals(VALID_VALUE, alog.getResourceBundle().getString(VALID_KEY));
assertEquals(alog.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
assertTrue(alog.getUseParentHandlers());
}
/*
* Test getAnonymousLogger(String resourceBundleName) with null resource
* bundle.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getAnonymousLogger(String resourceBundleName) with null resource bundle.",
method = "getAnonymousLogger",
args = {java.lang.String.class}
)
public void testGetAnonymousLogger_NullResourceBundle() {
Logger alog = Logger.getAnonymousLogger(null);
assertNotSame(alog, Logger.getAnonymousLogger(null));
assertNull(alog.getFilter());
assertEquals(0, alog.getHandlers().length);
assertNull(alog.getLevel());
assertNull(alog.getName());
assertEquals("", alog.getParent().getName());
assertNull(alog.getParent().getParent());
assertNull(alog.getResourceBundle());
assertNull(alog.getResourceBundleName());
assertTrue(alog.getUseParentHandlers());
}
/*
* Test getAnonymousLogger(String resourceBundleName) with invalid resource
* bundle.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getAnonymousLogger(String resourceBundleName) with invalid resource bundle.",
method = "getAnonymousLogger",
args = {java.lang.String.class}
)
public void testGetAnonymousLogger_InvalidResourceBundle() {
try {
Logger.getAnonymousLogger(INVALID_RESOURCE_BUNDLE);
fail("Should throw MissingResourceException!");
} catch (MissingResourceException e) {
}
// try empty name
try {
Logger.getAnonymousLogger("");
fail("Should throw MissingResourceException!");
} catch (MissingResourceException e) {
}
}
/*
* Test getLogger(String), getting a logger with no parent.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String), getting a logger with no parent.",
method = "getLogger",
args = {java.lang.String.class}
)
public void testGetLogger_Normal() throws Exception {
// config the level
Properties p = new Properties();
p.put("testGetLogger_Normal_ANewLogger.level", "ALL");
LogManager.getLogManager().readConfiguration(
EnvironmentHelper.PropertiesToInputStream(p));
assertNull(LogManager.getLogManager().getLogger(
"testGetLogger_Normal_ANewLogger"));
// create a new logger
Logger log = Logger.getLogger("testGetLogger_Normal_ANewLogger");
// get an existing logger
assertSame(log, Logger.getLogger("testGetLogger_Normal_ANewLogger"));
// check it has been registered
assertSame(log, LogManager.getLogManager().getLogger(
"testGetLogger_Normal_ANewLogger"));
assertNull(log.getFilter());
assertEquals(0, log.getHandlers().length);
// check it's set to the preconfigured level
assertSame(Level.ALL, log.getLevel());
assertEquals("testGetLogger_Normal_ANewLogger", log.getName());
assertNull(log.getParent().getParent());
assertNull(log.getResourceBundle());
assertNull(log.getResourceBundleName());
assertTrue(log.getUseParentHandlers());
}
/*
* Test getLogger(String), getting a logger with invalid level configured.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String), getting a logger with invalid level configured.",
method = "getLogger",
args = {java.lang.String.class}
)
public void testGetLogger_InvalidLevel() throws Exception {
// config the level
Properties p = new Properties();
p
.put("testGetLogger_InvalidLevel_ANewLogger.level",
"impossible_level");
LogManager.getLogManager().readConfiguration(
EnvironmentHelper.PropertiesToInputStream(p));
assertNull(LogManager.getLogManager().getLogger(
"testGetLogger_InvalidLevel_ANewLogger"));
// create a new logger
Logger log = Logger.getLogger("testGetLogger_InvalidLevel_ANewLogger");
// get an existing logger
assertSame(log, Logger
.getLogger("testGetLogger_InvalidLevel_ANewLogger"));
// check it has been registered
assertSame(log, LogManager.getLogManager().getLogger(
"testGetLogger_InvalidLevel_ANewLogger"));
assertNull(log.getLevel());
}
/*
* Test getLogger(String) with null name.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String) with null name.",
method = "getLogger",
args = {java.lang.String.class}
)
public void testGetLogger_Null() {
try {
Logger.getLogger(null);
fail("Should throw NullPointerException!");
} catch (NullPointerException e) {
// ok !
}
try {
Logger.getLogger(null, null);
fail("Should throw NullPointerException!");
} catch (NullPointerException e) {
// ok !
}
}
/*
* Test getLogger(String) with invalid name.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String) with invalid name.",
method = "getLogger",
args = {java.lang.String.class}
)
public void testGetLogger_Invalid() {
Logger log = Logger.getLogger("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|");
assertEquals("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|", log.getName());
}
/*
* Test getLogger(String) with empty name.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String) with empty name.",
method = "getLogger",
args = {java.lang.String.class}
)
public void testGetLogger_Empty() {
assertNotNull(LogManager.getLogManager().getLogger(""));
Logger log = Logger.getLogger("");
assertSame(log, LogManager.getLogManager().getLogger(""));
assertNull(log.getFilter());
assertEquals(0, log.getHandlers().length);
// check it's set to the preconfigured level
assertSame(Level.INFO, log.getLevel());
assertEquals("", log.getName());
assertNull(log.getParent());
assertTrue(log.getUseParentHandlers());
assertNull(log.getResourceBundle());
assertNull(log.getResourceBundleName());
}
/*
* Test getLogger(String), getting a logger with existing parent.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String), getting a logger with existing parent.",
method = "getLogger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testGetLogger_WithParent() {
assertNull(LogManager.getLogManager().getLogger(
"testGetLogger_WithParent_ParentLogger"));
// get root of hierarchy
Logger root = Logger.getLogger("");
// create the parent logger
Logger pLog = Logger.getLogger("testGetLogger_WithParent_ParentLogger",
VALID_RESOURCE_BUNDLE);
pLog.setLevel(Level.CONFIG);
pLog.addHandler(new MockHandler());
pLog.setFilter(new MockFilter());
pLog.setUseParentHandlers(false);
// check root parent
assertEquals("testGetLogger_WithParent_ParentLogger", pLog.getName());
assertSame(pLog.getParent(), root);
// child part
assertNull(LogManager.getLogManager().getLogger(
"testGetLogger_WithParent_ParentLogger.child"));
// create the child logger
Logger child = Logger
.getLogger("testGetLogger_WithParent_ParentLogger.child");
assertNull(child.getFilter());
assertEquals(0, child.getHandlers().length);
assertNull(child.getLevel());
assertEquals("testGetLogger_WithParent_ParentLogger.child", child
.getName());
assertSame(child.getParent(), pLog);
assertNull(child.getResourceBundle());
assertNull(child.getResourceBundleName());
assertTrue(child.getUseParentHandlers());
// create not valid child
Logger notChild = Logger
.getLogger("testGetLogger_WithParent_ParentLogger1.child");
assertNull(notChild.getFilter());
assertEquals(0, notChild.getHandlers().length);
assertNull(notChild.getLevel());
assertEquals("testGetLogger_WithParent_ParentLogger1.child", notChild
.getName());
assertNotSame(notChild.getParent(), pLog);
assertNull(notChild.getResourceBundle());
assertNull(notChild.getResourceBundleName());
assertTrue(notChild.getUseParentHandlers());
// verify two level root.parent
assertEquals("testGetLogger_WithParent_ParentLogger.child", child
.getName());
assertSame(child.getParent().getParent(), root);
// create three level child
Logger childOfChild = Logger
.getLogger("testGetLogger_WithParent_ParentLogger.child.child");
assertNull(childOfChild.getFilter());
assertEquals(0, childOfChild.getHandlers().length);
assertSame(child.getParent().getParent(), root);
assertNull(childOfChild.getLevel());
assertEquals("testGetLogger_WithParent_ParentLogger.child.child",
childOfChild.getName());
assertSame(childOfChild.getParent(), child);
assertSame(childOfChild.getParent().getParent(), pLog);
assertSame(childOfChild.getParent().getParent().getParent(), root);
assertNull(childOfChild.getResourceBundle());
assertNull(childOfChild.getResourceBundleName());
assertTrue(childOfChild.getUseParentHandlers());
// abnormal case : lookup to root parent in a hierarchy without a logger
// parent created between
assertEquals("testGetLogger_WithParent_ParentLogger1.child", notChild
.getName());
assertSame(child.getParent().getParent(), root);
assertNotSame(child.getParent(), root);
// abnormal cases
assertNotSame(root.getParent(), root);
Logger twoDot = Logger.getLogger("..");
assertSame(twoDot.getParent(), root);
}
/*
* Test getLogger(String, String), getting a logger with no parent.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String, String), getting a logger with no parent.",
method = "getLogger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testGetLoggerWithRes_Normal() throws Exception {
// config the level
Properties p = new Properties();
p.put("testGetLoggerWithRes_Normal_ANewLogger.level", "ALL");
LogManager.getLogManager().readConfiguration(
EnvironmentHelper.PropertiesToInputStream(p));
assertNull(LogManager.getLogManager().getLogger(
"testGetLoggerWithRes_Normal_ANewLogger"));
// create a new logger
Logger log = Logger.getLogger("testGetLoggerWithRes_Normal_ANewLogger",
VALID_RESOURCE_BUNDLE);
// get an existing logger
assertSame(log, Logger
.getLogger("testGetLoggerWithRes_Normal_ANewLogger"));
// check it has been registered
assertSame(log, LogManager.getLogManager().getLogger(
"testGetLoggerWithRes_Normal_ANewLogger"));
assertNull(log.getFilter());
assertEquals(0, log.getHandlers().length);
// check it's set to the preconfigured level
assertSame(Level.ALL, log.getLevel());
assertEquals("testGetLoggerWithRes_Normal_ANewLogger", log.getName());
assertNull(log.getParent().getParent());
assertEquals(VALID_VALUE, log.getResourceBundle().getString(VALID_KEY));
assertEquals(log.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
assertTrue(log.getUseParentHandlers());
}
/*
* Test getLogger(String, String) with null parameters.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String, String) with null parameters.",
method = "getLogger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testGetLoggerWithRes_Null() {
Logger.getLogger("testGetLoggerWithRes_Null_ANewLogger", null);
try {
Logger.getLogger(null, VALID_RESOURCE_BUNDLE);
fail("Should throw NullPointerException!");
} catch (NullPointerException e) {
}
}
/*
* Test getLogger(String, String) with invalid resource bundle.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String, String) with invalid resource bundle.",
method = "getLogger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testGetLoggerWithRes_InvalidResourceBundle() {
assertNull(LogManager.getLogManager().getLogger(
"testMissingResourceException"));
try {
Logger.getLogger("testMissingResourceException",
INVALID_RESOURCE_BUNDLE);
fail("Should throw MissingResourceException!");
} catch (MissingResourceException e) {
// correct
}
assertNull(Logger.getLogger("testMissingResourceException")
.getResourceBundle());
assertNull(Logger.getLogger("testMissingResourceException")
.getResourceBundleName());
// try empty string
try {
Logger.getLogger("testMissingResourceException", "");
fail("Should throw MissingResourceException!");
} catch (MissingResourceException e) {
// correct
}
assertNotNull(LogManager.getLogManager().getLogger(""));
// The root logger always exists TODO
try {
Logger.getLogger("", INVALID_RESOURCE_BUNDLE);
} catch (MissingResourceException e) {
//correct
}
}
/*
* Test getLogger(String, String) with valid resource bundle, to get an
* existing logger with no associated resource bundle.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String, String) with valid resource bundle, to get an existing logger with no associated resource bundle.",
method = "getLogger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testGetLoggerWithRes_ExistingLoggerWithNoRes() {
assertNull(LogManager.getLogManager().getLogger(
"testGetLoggerWithRes_ExistingLoggerWithNoRes_ANewLogger"));
// create a new logger
Logger log1 = Logger
.getLogger("testGetLoggerWithRes_ExistingLoggerWithNoRes_ANewLogger");
// get an existing logger
Logger log2 = Logger.getLogger(
"testGetLoggerWithRes_ExistingLoggerWithNoRes_ANewLogger",
VALID_RESOURCE_BUNDLE);
assertSame(log1, log2);
assertEquals(VALID_VALUE, log1.getResourceBundle().getString(VALID_KEY));
assertEquals(log1.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
}
/*
* Test getLogger(String, String) with valid resource bundle, to get an
* existing logger with the same associated resource bundle.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String, String) with valid resource bundle, to get an existing logger with the same associated resource bundle.",
method = "getLogger",
args = {java.lang.String.class, java.lang.String.class}
)
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);
}
/*
* Test getLogger(String, String) with valid resource bundle, to get an
* existing logger with different associated resource bundle.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String, String) with valid resource bundle, to get an existing logger with different associated resource bundle.",
method = "getLogger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testGetLoggerWithRes_ExistingLoggerWithDiffRes() {
assertNull(LogManager.getLogManager().getLogger(
"testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger"));
// create a new logger
Logger log1 = Logger.getLogger(
"testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger",
VALID_RESOURCE_BUNDLE);
assertNotNull(log1);
// get an existing logger
try {
Logger
.getLogger(
"testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger",
VALID_RESOURCE_BUNDLE2);
fail("Should throw IllegalArgumentException!");
} catch (IllegalArgumentException e) {
}
try {
Logger
.getLogger(
"testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger",
null);
fail("Should throw IllegalArgumentException!");
} catch (IllegalArgumentException e) {
}
}
/*
* Test getLogger(String, String) with invalid name.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String, String) with invalid name.",
method = "getLogger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testGetLoggerWithRes_InvalidName() {
Logger log = Logger.getLogger(
"...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|WithRes",
VALID_RESOURCE_BUNDLE);
assertEquals("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|WithRes", log
.getName());
}
/*
* Test getLogger(String, String) with empty name.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String, String) with empty name.",
method = "getLogger",
args = {java.lang.String.class, java.lang.String.class}
)
@SideEffect("Attaches ResourceBundle to anonymous logger; irreversible")
public void testGetLoggerWithRes_Empty() {
Logger log = Logger.getLogger("", VALID_RESOURCE_BUNDLE);
assertSame(log, LogManager.getLogManager().getLogger(""));
assertNull(log.getFilter());
assertEquals(0, log.getHandlers().length);
// check it's set to the preconfigured level
assertSame(Level.INFO, log.getLevel());
assertEquals("", log.getName());
assertNull(log.getParent());
assertEquals(VALID_VALUE, log.getResourceBundle().getString(VALID_KEY));
assertEquals(log.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
assertTrue(log.getUseParentHandlers());
}
/*
* Test getLogger(String, String), getting a logger with existing parent.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getLogger(String, String), getting a logger with existing parent.",
method = "getLogger",
args = {java.lang.String.class, java.lang.String.class}
)
public void testGetLoggerWithRes_WithParentNormal() {
assertNull(LogManager.getLogManager().getLogger(
"testGetLoggerWithRes_WithParent_ParentLogger"));
// create the parent logger
Logger pLog = Logger
.getLogger("testGetLoggerWithRes_WithParent_ParentLogger");
pLog.setLevel(Level.CONFIG);
pLog.addHandler(new MockHandler());
pLog.setFilter(new MockFilter());
pLog.setUseParentHandlers(false);
assertNull(LogManager.getLogManager().getLogger(
"testGetLoggerWithRes_WithParent_ParentLogger.child"));
// create the child logger
Logger log = Logger.getLogger(
"testGetLoggerWithRes_WithParent_ParentLogger.child",
VALID_RESOURCE_BUNDLE);
assertNull(log.getFilter());
assertEquals(0, log.getHandlers().length);
assertNull(log.getLevel());
assertEquals("testGetLoggerWithRes_WithParent_ParentLogger.child", log
.getName());
assertSame(log.getParent(), pLog);
assertEquals(VALID_VALUE, log.getResourceBundle().getString(VALID_KEY));
assertEquals(log.getResourceBundleName(), VALID_RESOURCE_BUNDLE);
assertTrue(log.getUseParentHandlers());
}
/*
* Test addHandler(Handler) for a named logger with sufficient privilege.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "addHandler",
args = {java.util.logging.Handler.class}
)
public void testAddHandler_NamedLoggerSufficientPrivilege() {
Logger log = Logger
.getLogger("testAddHandler_NamedLoggerSufficientPrivilege");
MockHandler h = new MockHandler();
assertEquals(log.getHandlers().length, 0);
log.addHandler(h);
assertEquals(log.getHandlers().length, 1);
}
/*
* Test addHandler(Handler) for a named logger with sufficient privilege,
* add duplicate handlers.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "addHandler",
args = {java.util.logging.Handler.class}
)
public void testAddHandler_NamedLoggerSufficientPrivilegeDuplicate() {
Logger log = Logger
.getLogger("testAddHandler_NamedLoggerSufficientPrivilegeDuplicate");
MockHandler h = new MockHandler();
assertEquals(log.getHandlers().length, 0);
for (int i = 0; i < 12; i++) {
log.addHandler(h);
}
assertEquals(log.getHandlers().length, 12);
assertSame(log.getHandlers()[0], h);
assertSame(log.getHandlers()[5], h);
assertSame(log.getHandlers()[11], h);
}
/*
* Test addHandler(Handler) with a null handler.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies NullPointerException.",
method = "addHandler",
args = {java.util.logging.Handler.class}
)
public void testAddHandler_Null() {
Logger log = Logger.getLogger("testAddHandler_Null");
try {
log.addHandler(null);
fail("Should throw NullPointerException!");
} catch (NullPointerException e) {
}
assertEquals(log.getHandlers().length, 0);
}
/*
* Test addHandler(Handler) for a named logger with insufficient privilege.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "addHandler",
args = {java.util.logging.Handler.class}
)
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.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "addHandler",
args = {java.util.logging.Handler.class}
)
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.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "addHandler",
args = {java.util.logging.Handler.class}
)
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);
}
/*
* Test addHandler(Handler) for an anonymous logger with insufficient
* privilege.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "addHandler",
args = {java.util.logging.Handler.class}
)
public void testAddHandler_AnonyLoggerInsufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
MockHandler h = new MockHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
assertEquals(log.getHandlers().length, 0);
log.addHandler(h);
assertEquals(log.getHandlers().length, 1);
assertSame(log.getHandlers()[0], h);
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test addHandler(Handler) for a null-named mock logger with insufficient
* privilege.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies addHandler(Handler) for a null-named mock logger with insufficient privilege, SecurityException.",
method = "addHandler",
args = {java.util.logging.Handler.class}
)
public void testAddHandler_NullNamedMockLoggerInsufficientPrivilege() {
MockLogger mlog = new MockLogger(null, null);
MockHandler h = new MockHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
mlog.addHandler(h);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test removeHandler(Handler) for a named logger with sufficient privilege,
* remove an existing handler.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "addHandler",
args = {java.util.logging.Handler.class}
)
public void testRemoveHandler_NamedLoggerSufficientPrivilege() {
Logger log = Logger
.getLogger("testRemoveHandler_NamedLoggerSufficientPrivilege");
MockHandler h = new MockHandler();
log.addHandler(h);
assertEquals(log.getHandlers().length, 1);
log.removeHandler(h);
assertEquals(log.getHandlers().length, 0);
}
/*
* Test removeHandler(Handler) for a named logger with sufficient privilege,
* remove a non-existing handler.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "removeHandler",
args = {java.util.logging.Handler.class}
)
public void testRemoveHandler_NamedLoggerSufficientPrivilegeNotExisting() {
Logger log = Logger
.getLogger("testRemoveHandler_NamedLoggerSufficientPrivilegeNotExisting");
MockHandler h = new MockHandler();
assertEquals(log.getHandlers().length, 0);
log.removeHandler(h);
assertEquals(log.getHandlers().length, 0);
}
/*
* Test removeHandler(Handler) with a null handler.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "removeHandler",
args = {java.util.logging.Handler.class}
)
public void testRemoveHandler_Null() {
Logger log = Logger.getLogger("testRemoveHandler_Null");
log.removeHandler(null);
assertEquals(log.getHandlers().length, 0);
}
/*
* Test removeHandler(Handler) for a named logger with insufficient
* privilege.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "removeHandler",
args = {java.util.logging.Handler.class}
)
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.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "removeHandler",
args = {java.util.logging.Handler.class}
)
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.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "removeHandler",
args = {java.util.logging.Handler.class}
)
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);
}
/*
* Test removeHandler(Handler) for an anonymous logger with insufficient
* privilege.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "removeHandler",
args = {java.util.logging.Handler.class}
)
public void testRemoveHandler_AnonyLoggerInsufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
MockHandler h = new MockHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.addHandler(h);
assertEquals(log.getHandlers().length, 1);
log.removeHandler(h);
assertEquals(log.getHandlers().length, 0);
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test removeHandler(Handler) for a null-named mock logger with
* insufficient privilege.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "removeHandler",
args = {java.util.logging.Handler.class}
)
public void testRemoveHandler_NullNamedMockLoggerInsufficientPrivilege() {
MockLogger mlog = new MockLogger(null, null);
MockHandler h = new MockHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
mlog.removeHandler(h);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test getHandlers() when there's no handler.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getHandlers() when there's no handler.",
method = "getHandlers",
args = {}
)
public void testGetHandlers_None() {
Logger log = Logger.getLogger("testGetHandlers_None");
assertEquals(log.getHandlers().length, 0);
}
/*
* Test getHandlers() when there are several handlers.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getHandlers() when there are several handlers.",
method = "getHandlers",
args = {}
)
public void testGetHandlers_Several() {
Logger log = Logger.getLogger("testGetHandlers_None");
assertEquals(log.getHandlers().length, 0);
MockHandler h1 = new MockHandler();
MockHandler h2 = new MockHandler();
MockHandler h3 = new MockHandler();
log.addHandler(h1);
log.addHandler(h2);
log.addHandler(h3);
assertEquals(log.getHandlers().length, 3);
assertSame(log.getHandlers()[0], h1);
assertSame(log.getHandlers()[1], h2);
assertSame(log.getHandlers()[2], h3);
// remove one
log.removeHandler(h2);
assertEquals(log.getHandlers().length, 2);
assertSame(log.getHandlers()[0], h1);
assertSame(log.getHandlers()[1], h3);
}
/*
* Test getFilter & setFilter with normal value for a named logger, having
* sufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies getFilter & setFilter with normal value for a named logger, having sufficient privilege.",
method = "getFilter",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies getFilter & setFilter with normal value for a named logger, having sufficient privilege.",
method = "setFilter",
args = {java.util.logging.Filter.class}
)
})
public void testGetSetFilter_NamedLoggerSufficientPrivilege() {
Logger log = Logger
.getLogger("testGetSetFilter_NamedLoggerSufficientPrivilege");
Filter f = new MockFilter();
assertNull(log.getFilter());
log.setFilter(f);
assertSame(f, log.getFilter());
}
/*
* Test getFilter & setFilter with null value, having sufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies getFilter & setFilter with null value, having sufficient privilege.",
method = "getFilter",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies getFilter & setFilter with null value, having sufficient privilege.",
method = "setFilter",
args = {java.util.logging.Filter.class}
)
})
public void testGetSetFilter_Null() {
Logger log = Logger.getLogger("testGetSetFilter_Null");
assertNull(log.getFilter());
log.setFilter(null);
assertNull(log.getFilter());
log.setFilter(new MockFilter());
log.setFilter(null);
assertNull(log.getFilter());
}
/*
* Test setFilter with normal value for a named logger, having insufficient
* privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies setFilter with normal value for a named logger, having insufficient privilege.",
method = "getFilter",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies setFilter with normal value for a named logger, having insufficient privilege.",
method = "setFilter",
args = {java.util.logging.Filter.class}
)
})
public void testGetSetFilter_NamedLoggerInsufficientPrivilege() {
Logger log = Logger
.getLogger("testGetSetFilter_NamedLoggerInsufficientPrivilege");
Filter f = new MockFilter();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.setFilter(f);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test setFilter for an anonymous logger with sufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getFilter",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setFilter",
args = {java.util.logging.Filter.class}
)
})
public void testSetFilter_AnonyLoggerSufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
Filter f = new MockFilter();
assertNull(log.getFilter());
log.setFilter(f);
assertSame(f, log.getFilter());
}
/*
* Test setFilter for an anonymous logger with insufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getFilter",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setFilter",
args = {java.util.logging.Filter.class}
)
})
public void testSetFilter_AnonyLoggerInsufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
Filter f = new MockFilter();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
assertNull(log.getFilter());
log.setFilter(f);
assertSame(f, log.getFilter());
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test setFilter for a null-named mock logger with insufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getFilter",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setFilter",
args = {java.util.logging.Filter.class}
)
})
public void testSetFilter_NullNamedMockLoggerInsufficientPrivilege() {
MockLogger mlog = new MockLogger(null, null);
Filter f = new MockFilter();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
mlog.setFilter(f);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test getLevel & setLevel with normal value for a named logger, having
* sufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies getLevel & setLevel with normal value for a named logger, having sufficient privilege.",
method = "setLevel",
args = {java.util.logging.Level.class}
),
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies getLevel & setLevel with normal value for a named logger, having sufficient privilege.",
method = "getLevel",
args = {}
)
})
public void testGetSetLevel_NamedLoggerSufficientPrivilege() {
Logger log = Logger
.getLogger("testGetSetLevel_NamedLoggerSufficientPrivilege");
assertNull(log.getLevel());
log.setLevel(Level.CONFIG);
assertSame(Level.CONFIG, log.getLevel());
}
/*
* Test getLevel & setLevel with null value, having sufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies getLevel & setLevel with null value, having sufficient privilege.",
method = "getLevel",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies getLevel & setLevel with null value, having sufficient privilege.",
method = "setLevel",
args = {java.util.logging.Level.class}
)
})
public void testGetSetLevel_Null() {
Logger log = Logger.getLogger("testGetSetLevel_Null");
assertNull(log.getLevel());
log.setLevel(null);
assertNull(log.getLevel());
log.setLevel(Level.CONFIG);
log.setLevel(null);
assertNull(log.getLevel());
}
/*
* Test setLevel with normal value for a named logger, having insufficient
* privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies setLevel with normal value for a named logger, having insufficient privilege.",
method = "setLevel",
args = {java.util.logging.Level.class}
),
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies setLevel with normal value for a named logger, having insufficient privilege.",
method = "getLevel",
args = {}
)
})
public void testGetSetLevel_NamedLoggerInsufficientPrivilege() {
Logger log = Logger
.getLogger("testGetSetLevel_NamedLoggerInsufficientPrivilege");
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.setLevel(Level.CONFIG);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test setLevel for an anonymous logger with sufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getLevel",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setLevel",
args = {java.util.logging.Level.class}
)
})
public void testSetLevel_AnonyLoggerSufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
assertNull(log.getLevel());
log.setLevel(Level.CONFIG);
assertSame(Level.CONFIG, log.getLevel());
}
/*
* Test setLevel for an anonymous logger with insufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getLevel",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setLevel",
args = {java.util.logging.Level.class}
)
})
public void testSetLevel_AnonyLoggerInsufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
assertNull(log.getLevel());
log.setLevel(Level.CONFIG);
assertSame(Level.CONFIG, log.getLevel());
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test setLevel for a null-named mock logger with insufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getLevel",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setLevel",
args = {java.util.logging.Level.class}
)
})
public void testSetLevel_NullNamedMockLoggerInsufficientPrivilege() {
MockLogger mlog = new MockLogger(null, null);
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
mlog.setLevel(Level.CONFIG);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test getUseParentHandlers & setUseParentHandlers with normal value for a
* named logger, having sufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getUseParentHandlers",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setUseParentHandlers",
args = {boolean.class}
)
})
public void testGetSetUseParentHandlers_NamedLoggerSufficientPrivilege() {
Logger log = Logger
.getLogger("testGetSetUseParentHandlers_NamedLoggerSufficientPrivilege");
assertTrue(log.getUseParentHandlers());
log.setUseParentHandlers(false);
assertFalse(log.getUseParentHandlers());
}
/*
* Test setUseParentHandlers with normal value for a named logger, having
* insufficient privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getUseParentHandlers",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setUseParentHandlers",
args = {boolean.class}
)
})
public void testGetSetUseParentHandlers_NamedLoggerInsufficientPrivilege() {
Logger log = Logger
.getLogger("testGetSetUseParentHandlers_NamedLoggerInsufficientPrivilege");
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
log.setUseParentHandlers(true);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test setUseParentHandlers for an anonymous logger with sufficient
* privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getUseParentHandlers",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setUseParentHandlers",
args = {boolean.class}
)
})
public void testSetUseParentHandlers_AnonyLoggerSufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
assertTrue(log.getUseParentHandlers());
log.setUseParentHandlers(false);
assertFalse(log.getUseParentHandlers());
}
/*
* Test setUseParentHandlers for an anonymous logger with insufficient
* privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getUseParentHandlers",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setUseParentHandlers",
args = {boolean.class}
)
})
public void testSetUseParentHandlers_AnonyLoggerInsufficientPrivilege() {
Logger log = Logger.getAnonymousLogger();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
assertTrue(log.getUseParentHandlers());
log.setUseParentHandlers(false);
assertFalse(log.getUseParentHandlers());
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test setUseParentHandlers for a null-named mock logger with insufficient
* privilege.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getUseParentHandlers",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setUseParentHandlers",
args = {boolean.class}
)
})
public void testSetUseParentHandlers_NullNamedMockLoggerInsufficientPrivilege() {
MockLogger mlog = new MockLogger(null, null);
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
mlog.setUseParentHandlers(true);
fail("Should throw SecurityException!");
} catch (SecurityException e) {
} finally {
System.setSecurityManager(oldMan);
}
}
/*
* Test getParent() for root logger.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getParent() for root logger.",
method = "getParent",
args = {}
)
public void testGetParent_Root() {
assertNull(Logger.getLogger("").getParent());
}
/*
* Test getParent() for normal named loggers.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getParent() for normal named loggers.",
method = "getParent",
args = {}
)
public void testGetParent_NormalNamed() {
Logger log = Logger.getLogger("testGetParent_NormalNamed");
assertSame(log.getParent(), Logger.getLogger(""));
Logger child = Logger.getLogger("testGetParent_NormalNamed.child");
assertSame(child.getParent(), log);
Logger child2 = Logger.getLogger("testGetParent_NormalNamed.a.b.c");
assertSame(child2.getParent(), log);
}
/*
* Test getParent() for anonymous loggers.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getParent() for anonymous loggers.",
method = "getParent",
args = {}
)
public void testGetParent_Anonymous() {
assertSame(Logger.getAnonymousLogger().getParent(), Logger
.getLogger(""));
}
/*
* Test setParent(Logger) for the mock logger since it is advised not to
* call this method on named loggers. Test normal conditions.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setParent",
args = {java.util.logging.Logger.class}
)
public void testSetParent_Normal() {
Logger log = new MockLogger(null, null);
Logger parent = new MockLogger(null, null);
assertNull(log.getParent());
log.setParent(parent);
assertSame(log.getParent(), parent);
}
/*
* Test setParent(Logger) with null.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setParent",
args = {java.util.logging.Logger.class}
)
public void testSetParent_Null() {
try {
(new MockLogger(null, null)).setParent(null);
fail("Should throw NullPointerException!");
} catch (NullPointerException e) {
}
}
/*
* Test setParent(Logger), having insufficient privilege.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setParent",
args = {java.util.logging.Logger.class}
)
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.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setParent",
args = {java.util.logging.Logger.class}
)
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.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setParent",
args = {java.util.logging.Logger.class}
)
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.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getName() for normal names.",
method = "getName",
args = {}
)
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());
}
/*
* Test getName() for empty name.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getName() for empty name.",
method = "getName",
args = {}
)
public void testGetName_Empty() {
Logger log = Logger.getLogger("");
assertEquals("", log.getName());
Logger mlog = new MockLogger("", null);
assertEquals("", mlog.getName());
}
/*
* Test getName() for null name.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getName() for null name.",
method = "getName",
args = {}
)
public void testGetName_Null() {
Logger log = Logger.getAnonymousLogger();
assertNull(log.getName());
Logger mlog = new MockLogger(null, null);
assertNull(mlog.getName());
}
/*
* Test getResourceBundle() when it it not null.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getResourceBundle() when it it not null.",
method = "getResourceBundle",
args = {}
)
public void testGetResourceBundle_Normal() {
Logger log = Logger.getLogger("testGetResourceBundle_Normal",
VALID_RESOURCE_BUNDLE);
assertEquals(VALID_VALUE, log.getResourceBundle().getString(VALID_KEY));
Logger mlog = new MockLogger(null, VALID_RESOURCE_BUNDLE);
assertEquals(VALID_VALUE, mlog.getResourceBundle().getString(VALID_KEY));
}
/*
* Test getResourceBundle() when it it null.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getResourceBundle() when it it null.",
method = "getResourceBundle",
args = {}
)
public void testGetResourceBundle_Null() {
Logger log = Logger.getLogger("testGetResourceBundle_Null", null);
assertNull(log.getResourceBundle());
Logger mlog = new MockLogger(null, null);
assertNull(mlog.getResourceBundle());
}
/*
* Test getResourceBundleName() when it it not null.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getResourceBundleName() when it it not null.",
method = "getResourceBundleName",
args = {}
)
public void testGetResourceBundleName_Normal() {
Logger log = Logger.getLogger("testGetResourceBundleName_Normal",
VALID_RESOURCE_BUNDLE);
assertEquals(VALID_RESOURCE_BUNDLE, log.getResourceBundleName());
Logger mlog = new MockLogger(null, null);
assertNull(mlog.getResourceBundleName());
}
/*
* Test getResourceBundleName() when it it null.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies getResourceBundleName() when it it null.",
method = "getResourceBundleName",
args = {}
)
public void testGetResourceBundleName_Null() {
Logger log = Logger.getLogger("testGetResourceBundleName_Null", null);
assertNull(log.getResourceBundleName());
Logger mlog = new MockLogger(null, null);
assertNull(mlog.getResourceBundleName());
}
/*
* Test isLoggable(Level).
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "isLoggable",
args = {java.util.logging.Level.class}
)
public void testIsLoggable() {
MockLogger mlog = new MockLogger(null, null);
assertNull(mlog.getLevel());
assertNull(mlog.getParent());
assertTrue(mlog.isLoggable(Level.SEVERE));
assertTrue(mlog.isLoggable(Level.WARNING));
assertTrue(mlog.isLoggable(Level.INFO));
assertFalse(mlog.isLoggable(Level.CONFIG));
assertFalse(mlog.isLoggable(Level.FINE));
assertFalse(mlog.isLoggable(Level.ALL));
assertTrue(mlog.isLoggable(Level.OFF));
mlog.setLevel(Level.CONFIG);
assertTrue(mlog.isLoggable(Level.SEVERE));
assertTrue(mlog.isLoggable(Level.CONFIG));
assertFalse(mlog.isLoggable(Level.ALL));
assertTrue(mlog.isLoggable(Level.OFF));
mlog.setLevel(Level.ALL);
assertTrue(mlog.isLoggable(Level.ALL));
assertTrue(mlog.isLoggable(Level.SEVERE));
assertTrue(mlog.isLoggable(Level.OFF));
mlog.setLevel(Level.OFF);
assertFalse(mlog.isLoggable(Level.ALL));
assertFalse(mlog.isLoggable(Level.SEVERE));
assertFalse(mlog.isLoggable(Level.OFF));
}
/*
* Test throwing(String, String, Throwable) with normal values.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "throwing",
args = {java.lang.String.class, java.lang.String.class, java.lang.Throwable.class}
)
public void testThrowing_Normal() {
Throwable t = new Throwable();
this.sharedLogger.setLevel(Level.FINER);
this.sharedLogger.throwing("sourceClass", "sourceMethod", t);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), this.sharedLogger.getName());
assertEquals(r.getMessage(), "THROW");
assertSame(r.getResourceBundleName(), this.sharedLogger
.getResourceBundleName());
assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
assertSame(r.getSourceClassName(), "sourceClass");
assertSame(r.getSourceMethodName(), "sourceMethod");
assertSame(r.getLevel(), Level.FINER);
assertSame(r.getParameters(), null);
assertSame(r.getThrown(), t);
this.sharedLogger.setLevel(Level.FINE);
this.sharedLogger.throwing("sourceClass", "sourceMethod", t);
// FINE is a level too low, message will be lost => empty
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test throwing(String, String, Throwable) with null values.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "throwing",
args = {java.lang.String.class, java.lang.String.class, java.lang.Throwable.class}
)
public void testThrowing_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.FINER);
child.throwing(null, null, null);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), child.getName());
assertEquals(r.getMessage(), "THROW");
assertSame(r.getResourceBundleName(), parent.getResourceBundleName());
assertSame(r.getResourceBundle(), parent.getResourceBundle());
assertSame(r.getSourceClassName(), null);
assertSame(r.getSourceMethodName(), null);
assertSame(r.getLevel(), Level.FINER);
assertSame(r.getParameters(), null);
assertSame(r.getThrown(), null);
}
/*
* Test entering(String, String) with normal values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies entering(String, String) with normal values.",
method = "entering",
args = {java.lang.String.class, java.lang.String.class}
)
public void testEntering_StringString_Normal() {
this.sharedLogger.setLevel(Level.FINER);
this.sharedLogger.entering("sourceClass", "sourceMethod");
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), this.sharedLogger.getName());
assertEquals(r.getMessage(), "ENTRY");
assertSame(r.getResourceBundleName(), this.sharedLogger
.getResourceBundleName());
assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
assertSame(r.getSourceClassName(), "sourceClass");
assertSame(r.getSourceMethodName(), "sourceMethod");
assertSame(r.getLevel(), Level.FINER);
assertSame(r.getParameters(), null);
assertSame(r.getThrown(), null);
this.sharedLogger.setLevel(Level.FINE);
this.sharedLogger.entering("sourceClass", "sourceMethod");
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test entering(String, String) with null values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies entering(String, String) with null values.",
method = "entering",
args = {java.lang.String.class, java.lang.String.class}
)
public void testEntering_StringString_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.FINER);
child.entering(null, null);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), child.getName());
assertEquals(r.getMessage(), "ENTRY");
assertSame(r.getResourceBundleName(), parent.getResourceBundleName());
assertSame(r.getResourceBundle(), parent.getResourceBundle());
assertSame(r.getSourceClassName(), null);
assertSame(r.getSourceMethodName(), null);
assertSame(r.getLevel(), Level.FINER);
assertSame(r.getParameters(), null);
assertSame(r.getThrown(), null);
}
/*
* Test entering(String, String, Object) with normal values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies entering(String, String, Object) with normal values.",
method = "entering",
args = {java.lang.String.class, java.lang.String.class, java.lang.Object.class}
)
public void testEntering_StringStringObject_Normal() {
Object param = new Object();
this.sharedLogger.setLevel(Level.FINER);
this.sharedLogger.entering("sourceClass", "sourceMethod", param);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), this.sharedLogger.getName());
assertEquals(r.getMessage(), "ENTRY {0}");
assertSame(r.getResourceBundleName(), this.sharedLogger
.getResourceBundleName());
assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
assertSame(r.getSourceClassName(), "sourceClass");
assertSame(r.getSourceMethodName(), "sourceMethod");
assertSame(r.getLevel(), Level.FINER);
assertSame(r.getParameters()[0], param);
assertEquals(1, r.getParameters().length);
assertSame(r.getThrown(), null);
this.sharedLogger.setLevel(Level.FINE);
this.sharedLogger.entering("sourceClass", "sourceMethod", param);
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test entering(String, String, Object) with null values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies entering(String, String, Object) with null values.",
method = "entering",
args = {java.lang.String.class, java.lang.String.class, java.lang.Object.class}
)
public void testEntering_StringStringObject_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.FINER);
child.entering(null, null, (Object) null);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), child.getName());
assertEquals(r.getMessage(), "ENTRY {0}");
assertSame(r.getResourceBundleName(), parent.getResourceBundleName());
assertSame(r.getResourceBundle(), parent.getResourceBundle());
assertSame(r.getSourceClassName(), null);
assertSame(r.getSourceMethodName(), null);
assertSame(r.getLevel(), Level.FINER);
assertEquals(r.getParameters().length, 1);
assertNull(r.getParameters()[0]);
assertSame(r.getThrown(), null);
}
/*
* Test entering(String, String, Object[]) with normal values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies entering(String, String, Object[]) with normal values.",
method = "entering",
args = {java.lang.String.class, java.lang.String.class, java.lang.Object[].class}
)
public void testEntering_StringStringObjects_Normal() {
Object[] params = new Object[2];
params[0] = new Object();
params[1] = new Object();
this.sharedLogger.setLevel(Level.FINER);
this.sharedLogger.entering("sourceClass", "sourceMethod", params);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), this.sharedLogger.getName());
assertEquals(r.getMessage(), "ENTRY {0} {1}");
assertSame(r.getResourceBundleName(), this.sharedLogger
.getResourceBundleName());
assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
assertSame(r.getSourceClassName(), "sourceClass");
assertSame(r.getSourceMethodName(), "sourceMethod");
assertSame(r.getLevel(), Level.FINER);
assertSame(r.getParameters()[0], params[0]);
assertSame(r.getParameters()[1], params[1]);
assertEquals(2, r.getParameters().length);
assertSame(r.getThrown(), null);
this.sharedLogger.setLevel(Level.FINE);
this.sharedLogger.entering("sourceClass", "sourceMethod", params);
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test entering(String, String, Object[]) with null class name and method
* name and empty parameter array.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies entering(String, String, Object[]) with null class name and method name and empty parameter array.",
method = "entering",
args = {java.lang.String.class, java.lang.String.class, java.lang.Object[].class}
)
public void testEntering_StringStringObjects_NullEmpty() {
Logger child = new MockLogger("childLogger", null);
Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2);
child.addHandler(new MockHandler());
child.setParent(parent);
child.setLevel(Level.FINER);
child.entering(null, null, new Object[0]);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), child.getName());
assertEquals(r.getMessage(), "ENTRY");
assertSame(r.getResourceBundleName(), parent.getResourceBundleName());
assertSame(r.getResourceBundle(), parent.getResourceBundle());
assertSame(r.getSourceClassName(), null);
assertSame(r.getSourceMethodName(), null);
assertSame(r.getLevel(), Level.FINER);
assertEquals(0, r.getParameters().length);
assertSame(r.getThrown(), null);
}
/*
* Test entering(String, String, Object[]) with null values with appropriate
* logging level set.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies entering(String, String, Object[]) with null values with appropriate logging level set.",
method = "entering",
args = {java.lang.String.class, java.lang.String.class, java.lang.Object[].class}
)
public void testEntering_StringStringObjects_Null() {
sharedLogger.setLevel(Level.FINER);
sharedLogger.entering(null, null, (Object[]) null);
// regression test for Harmony-1265
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(sharedLogger.getName(), r.getLoggerName());
assertEquals("ENTRY", r.getMessage());
assertSame(sharedLogger.getResourceBundleName(), r
.getResourceBundleName());
assertSame(sharedLogger.getResourceBundle(), r.getResourceBundle());
assertNull(r.getSourceClassName());
assertNull(r.getSourceMethodName());
assertSame(Level.FINER, r.getLevel());
assertNull(r.getParameters());
assertNull(r.getThrown());
}
/*
* Test entering(String, String, Object[]) with null values with
* inappropriate logging level set.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies entering(String, String, Object[]) with null values with inappropriate logging level set.",
method = "entering",
args = {java.lang.String.class, java.lang.String.class, java.lang.Object[].class}
)
public void testEntering_StringStringObjects_NullDisabled() {
this.sharedLogger.setLevel(Level.FINE);
this.sharedLogger.entering(null, null, (Object[]) null);
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test exiting(String, String) with normal values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies exiting(String, String) with normal values.",
method = "exiting",
args = {java.lang.String.class, java.lang.String.class}
)
public void testExiting_StringString_Normal() {
this.sharedLogger.setLevel(Level.FINER);
this.sharedLogger.exiting("sourceClass", "sourceMethod");
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), this.sharedLogger.getName());
assertEquals(r.getMessage(), "RETURN");
assertSame(r.getResourceBundleName(), this.sharedLogger
.getResourceBundleName());
assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
assertSame(r.getSourceClassName(), "sourceClass");
assertSame(r.getSourceMethodName(), "sourceMethod");
assertSame(r.getLevel(), Level.FINER);
assertNull(r.getParameters());
assertSame(r.getThrown(), null);
this.sharedLogger.setLevel(Level.FINE);
this.sharedLogger.exiting("sourceClass", "sourceMethod");
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test exiting(String, String) with null values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies exiting(String, String) with null values.",
method = "exiting",
args = {java.lang.String.class, java.lang.String.class}
)
public void testExiting_StringString_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.FINER);
child.exiting(null, null);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), child.getName());
assertEquals(r.getMessage(), "RETURN");
assertSame(r.getResourceBundleName(), parent.getResourceBundleName());
assertSame(r.getResourceBundle(), parent.getResourceBundle());
assertSame(r.getSourceClassName(), null);
assertSame(r.getSourceMethodName(), null);
assertSame(r.getLevel(), Level.FINER);
assertSame(r.getParameters(), null);
assertSame(r.getThrown(), null);
}
/*
* Test exiting(String, String, Object) with normal values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies exiting(String, String, Object) with normal values.",
method = "exiting",
args = {java.lang.String.class, java.lang.String.class, java.lang.Object.class}
)
public void testExiting_StringStringObject_Normal() {
Object param = new Object();
this.sharedLogger.setLevel(Level.FINER);
this.sharedLogger.exiting("sourceClass", "sourceMethod", param);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), this.sharedLogger.getName());
assertEquals(r.getMessage(), "RETURN {0}");
assertSame(r.getResourceBundleName(), this.sharedLogger
.getResourceBundleName());
assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
assertSame(r.getSourceClassName(), "sourceClass");
assertSame(r.getSourceMethodName(), "sourceMethod");
assertSame(r.getLevel(), Level.FINER);
assertSame(r.getParameters()[0], param);
assertEquals(1, r.getParameters().length);
assertSame(r.getThrown(), null);
this.sharedLogger.setLevel(Level.FINE);
this.sharedLogger.exiting("sourceClass", "sourceMethod", param);
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test exiting(String, String, Object) with null values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies exiting(String, String, Object) with null values.",
method = "exiting",
args = {java.lang.String.class, java.lang.String.class, java.lang.Object.class}
)
public void testExiting_StringStringObject_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.FINER);
child.exiting(null, null, (Object) null);
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), child.getName());
assertEquals(r.getMessage(), "RETURN {0}");
assertSame(r.getResourceBundleName(), parent.getResourceBundleName());
assertSame(r.getResourceBundle(), parent.getResourceBundle());
assertSame(r.getSourceClassName(), null);
assertSame(r.getSourceMethodName(), null);
assertSame(r.getLevel(), Level.FINER);
assertEquals(r.getParameters().length, 1);
assertNull(r.getParameters()[0]);
assertSame(r.getThrown(), null);
}
/*
* Test config(String) with normal values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "config",
args = {java.lang.String.class}
)
public void testConfig_Normal() {
this.sharedLogger.setLevel(Level.CONFIG);
this.sharedLogger.config("config msg");
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), this.sharedLogger.getName());
assertEquals(r.getMessage(), "config msg");
assertSame(r.getResourceBundleName(), this.sharedLogger
.getResourceBundleName());
assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
assertSame(r.getSourceClassName(), null);
assertSame(r.getSourceMethodName(), null);
assertSame(r.getLevel(), Level.CONFIG);
assertNull(r.getParameters());
assertSame(r.getThrown(), null);
this.sharedLogger.setLevel(Level.INFO);
this.sharedLogger.config("config again");
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test config(String) with null values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies null as a parameter.",
method = "config",
args = {java.lang.String.class}
)
public void testConfig_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.CONFIG);
child.config(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.CONFIG);
assertNull(r.getParameters());
assertSame(r.getThrown(), null);
this.sharedLogger.setLevel(Level.INFO);
this.sharedLogger.config(null);
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test fine(String) with normal values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "fine",
args = {java.lang.String.class}
)
public void testFine_Normal() {
this.sharedLogger.setLevel(Level.FINE);
this.sharedLogger.fine("fine msg");
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), this.sharedLogger.getName());
assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
assertEquals(r.getMessage(), "fine msg");
assertSame(r.getResourceBundleName(), this.sharedLogger
.getResourceBundleName());
assertSame(r.getSourceClassName(), null);
assertSame(r.getSourceMethodName(), null);
assertSame(r.getLevel(), Level.FINE);
assertNull(r.getParameters());
assertSame(r.getThrown(), null);
this.sharedLogger.setLevel(Level.CONFIG);
this.sharedLogger.fine("fine again");
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test fine(String) with null values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies fine(String) with null values.",
method = "fine",
args = {java.lang.String.class}
)
public void testFine_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.FINE);
child.fine(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.FINE);
assertNull(r.getParameters());
assertSame(r.getThrown(), null);
this.sharedLogger.setLevel(Level.CONFIG);
this.sharedLogger.fine(null);
assertTrue(CallVerificationStack.getInstance().empty());
}
/*
* Test finer(String) with normal values.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies finer(String) with normal values.",
method = "finer",
args = {java.lang.String.class}
)
public void testFiner_Normal() {
this.sharedLogger.setLevel(Level.FINER);
this.sharedLogger.finer("finer msg");
LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
assertTrue(CallVerificationStack.getInstance().empty());
assertSame(r.getLoggerName(), this.sharedLogger.getName());
assertEquals(r.getMessage(), "finer msg");
assertSame(r.getResourceBundleName(), this.sharedLogger
.<