1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.harmony.logging.tests.java.util.logging; 19 20 import java.io.File; 21 import java.io.FileInputStream; 22 import java.security.Permission; 23 import java.util.Locale; 24 import java.util.MissingResourceException; 25 import java.util.Properties; 26 import java.util.ResourceBundle; 27 import java.util.logging.Filter; 28 import java.util.logging.Handler; 29 import java.util.logging.Level; 30 import java.util.logging.LogManager; 31 import java.util.logging.LogRecord; 32 import java.util.logging.Logger; 33 import java.util.logging.LoggingPermission; 34 35 import junit.framework.TestCase; 36 37 import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper; 38 39 import tests.util.CallVerificationStack; 40 41 /** 42 * Test suite for the class java.util.logging.Logger. 43 * 44 */ 45 public class LoggerTest extends TestCase { 46 47 private final static String VALID_RESOURCE_BUNDLE = "bundles/java/util/logging/res"; 48 49 private final static String VALID_RESOURCE_BUNDLE2 = "bundles/java/util/logging/res2"; 50 51 private final static String VALID_RESOURCE_BUNDLE3 = "bundles/java/util/logging/res3"; 52 53 private final static String INVALID_RESOURCE_BUNDLE = "impossible_not_existing"; 54 55 private final static String LOGGING_CONFIG_FILE= "resources/config/java/util/logging/logging.config"; 56 57 private final static String VALID_KEY = "LOGGERTEST"; 58 59 private final static String VALID_VALUE = "Test_ZH_CN"; 60 61 private final static String VALID_VALUE2 = "Test_NoLocale2"; 62 63 private Logger sharedLogger = null; 64 65 private Locale oldLocale = null; 66 67 /* 68 * @see TestCase#setUp() 69 */ 70 protected void setUp() throws Exception { 71 super.setUp(); 72 oldLocale = Locale.getDefault(); 73 Locale.setDefault(new Locale("zh", "CN")); 74 sharedLogger = new MockLogger("SharedLogger", VALID_RESOURCE_BUNDLE); 75 sharedLogger.addHandler(new MockHandler()); 76 } 77 78 /* 79 * Reset the log manager. 80 */ 81 protected void tearDown() throws Exception { 82 CallVerificationStack.getInstance().clear(); 83 Locale.setDefault(oldLocale); 84 super.tearDown(); 85 } 86 87 /** 88 * Constructor for LoggerTest. 89 * 90 * @param arg0 91 */ 92 public LoggerTest(String arg0) { 93 super(arg0); 94 } 95 96 /* 97 * Test the global logger 98 */ 99 public void testGlobalLogger() { 100 assertNull(Logger.global.getFilter()); 101 assertEquals(0, Logger.global.getHandlers().length); 102 assertNull(Logger.global.getLevel()); 103 assertEquals("global", Logger.global.getName()); 104 assertNull(Logger.global.getParent().getParent()); 105 assertNull(Logger.global.getResourceBundle()); 106 assertNull(Logger.global.getResourceBundleName()); 107 assertTrue(Logger.global.getUseParentHandlers()); 108 assertSame(Logger.global, Logger.getLogger("global")); 109 assertSame(Logger.global, LogManager.getLogManager() 110 .getLogger("global")); 111 } 112 113 /* 114 * Test constructor under normal conditions. 115 * 116 * TODO: using a series of class loaders to load resource bundles 117 */ 118 public void testConstructor_Normal() { 119 MockLogger mlog = new MockLogger("myname", VALID_RESOURCE_BUNDLE); 120 assertNull(mlog.getFilter()); 121 assertEquals(0, mlog.getHandlers().length); 122 assertNull(mlog.getLevel()); 123 assertEquals("myname", mlog.getName()); 124 assertNull(mlog.getParent()); 125 ResourceBundle rb = mlog.getResourceBundle(); 126 assertEquals(VALID_VALUE, rb.getString(VALID_KEY)); 127 assertEquals(mlog.getResourceBundleName(), VALID_RESOURCE_BUNDLE); 128 assertTrue(mlog.getUseParentHandlers()); 129 } 130 131 /* 132 * Test constructor with null parameters. 133 */ 134 public void testConstructor_Null() { 135 MockLogger mlog = new MockLogger(null, null); 136 assertNull(mlog.getFilter()); 137 assertEquals(0, mlog.getHandlers().length); 138 assertNull(mlog.getLevel()); 139 assertNull(mlog.getName()); 140 assertNull(mlog.getParent()); 141 assertNull(mlog.getResourceBundle()); 142 assertNull(mlog.getResourceBundleName()); 143 assertTrue(mlog.getUseParentHandlers()); 144 } 145 146 /* 147 * Test constructor with invalid name. 148 */ 149 public void testConstructor_InvalidName() { 150 MockLogger mlog = new MockLogger("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|", 151 null); 152 assertEquals("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|", mlog.getName()); 153 } 154 155 /* 156 * Test constructor with empty name. 157 */ 158 public void testConstructor_EmptyName() { 159 MockLogger mlog = new MockLogger("", null); 160 assertEquals("", mlog.getName()); 161 } 162 163 /* 164 * Test constructor with invalid resource bundle name. 165 */ 166 public void testConstructor_InvalidResourceBundle() { 167 try { 168 new MockLogger(null, INVALID_RESOURCE_BUNDLE); 169 fail("Should throw MissingResourceException!"); 170 } catch (MissingResourceException e) { 171 } 172 // try empty string 173 try { 174 new MockLogger(null, ""); 175 fail("Should throw MissingResourceException!"); 176 } catch (MissingResourceException e) { 177 } 178 } 179 180 /* 181 * Test getAnonymousLogger(String resourceBundleName) with valid resource 182 * bundle. 183 */ 184 public void testGetAnonymousLogger_ValidResourceBundle() { 185 Logger alog = Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE); 186 assertNotSame(alog, Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE)); 187 assertNull(alog.getFilter()); 188 assertEquals(0, alog.getHandlers().length); 189 assertNull(alog.getLevel()); 190 assertNull(alog.getName()); 191 assertNull(alog.getParent().getParent()); 192 assertEquals(VALID_VALUE, alog.getResourceBundle().getString(VALID_KEY)); 193 assertEquals(alog.getResourceBundleName(), VALID_RESOURCE_BUNDLE); 194 assertTrue(alog.getUseParentHandlers()); 195 } 196 197 /* 198 * Test getAnonymousLogger(String resourceBundleName) with null resource 199 * bundle. 200 */ 201 public void testGetAnonymousLogger_NullResourceBundle() { 202 Logger alog = Logger.getAnonymousLogger(null); 203 assertNotSame(alog, Logger.getAnonymousLogger(null)); 204 assertNull(alog.getFilter()); 205 assertEquals(0, alog.getHandlers().length); 206 assertNull(alog.getLevel()); 207 assertNull(alog.getName()); 208 assertNull(alog.getParent().getParent()); 209 assertNull(alog.getResourceBundle()); 210 assertNull(alog.getResourceBundleName()); 211 assertTrue(alog.getUseParentHandlers()); 212 } 213 214 /* 215 * Test getAnonymousLogger(String resourceBundleName) with invalid resource 216 * bundle. 217 */ 218 public void testGetAnonymousLogger_InvalidResourceBundle() { 219 try { 220 Logger.getAnonymousLogger(INVALID_RESOURCE_BUNDLE); 221 fail("Should throw MissingResourceException!"); 222 } catch (MissingResourceException e) { 223 } 224 // try empty name 225 try { 226 Logger.getAnonymousLogger(""); 227 fail("Should throw MissingResourceException!"); 228 } catch (MissingResourceException e) { 229 } 230 } 231 232 /* 233 * Test getLogger(String), getting a logger with no parent. 234 */ 235 public void testGetLogger_Normal() throws Exception { 236 // config the level 237 Properties p = new Properties(); 238 p.put("testGetLogger_Normal_ANewLogger.level", "ALL"); 239 LogManager.getLogManager().readConfiguration( 240 EnvironmentHelper.PropertiesToInputStream(p)); 241 242 assertNull(LogManager.getLogManager().getLogger( 243 "testGetLogger_Normal_ANewLogger")); 244 // create a new logger 245 Logger log = Logger.getLogger("testGetLogger_Normal_ANewLogger"); 246 // get an existing logger 247 assertSame(log, Logger.getLogger("testGetLogger_Normal_ANewLogger")); 248 // check it has been registered 249 assertSame(log, LogManager.getLogManager().getLogger( 250 "testGetLogger_Normal_ANewLogger")); 251 252 assertNull(log.getFilter()); 253 assertEquals(0, log.getHandlers().length); 254 // check it's set to the preconfigured level 255 assertSame(Level.ALL, log.getLevel()); 256 assertEquals("testGetLogger_Normal_ANewLogger", log.getName()); 257 assertNull(log.getParent().getParent()); 258 assertNull(log.getResourceBundle()); 259 assertNull(log.getResourceBundleName()); 260 assertTrue(log.getUseParentHandlers()); 261 } 262 263 /* 264 * Test getLogger(String), getting a logger with invalid level configured. 265 */ 266 public void testGetLogger_InvalidLevel() throws Exception { 267 // config the level 268 Properties p = new Properties(); 269 p 270 .put("testGetLogger_InvalidLevel_ANewLogger.level", 271 "impossible_level"); 272 LogManager.getLogManager().readConfiguration( 273 EnvironmentHelper.PropertiesToInputStream(p)); 274 275 assertNull(LogManager.getLogManager().getLogger( 276 "testGetLogger_InvalidLevel_ANewLogger")); 277 // create a new logger 278 Logger log = Logger.getLogger("testGetLogger_InvalidLevel_ANewLogger"); 279 // get an existing logger 280 assertSame(log, Logger 281 .getLogger("testGetLogger_InvalidLevel_ANewLogger")); 282 // check it has been registered 283 assertSame(log, LogManager.getLogManager().getLogger( 284 "testGetLogger_InvalidLevel_ANewLogger")); 285 assertNull(log.getLevel()); 286 } 287 288 /* 289 * Test getLogger(String) with null name. 290 */ 291 public void testGetLogger_Null() { 292 try { 293 Logger.getLogger(null); 294 fail("Should throw NullPointerException!"); 295 } catch (NullPointerException e) { 296 } 297 Logger logger = Logger.getLogger("", null); 298 assertNull(logger.getResourceBundleName()); 299 assertNull(logger.getResourceBundle()); 300 } 301 302 /* 303 * Test getLogger(String) with invalid name. 304 */ 305 public void testGetLogger_Invalid() { 306 Logger log = Logger.getLogger("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|"); 307 assertEquals("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|", log.getName()); 308 } 309 310 /* 311 * Test getLogger(String) with empty name. 312 */ 313 public void testGetLogger_Empty() { 314 assertNotNull(LogManager.getLogManager().getLogger("")); 315 Logger log = Logger.getLogger(""); 316 assertSame(log, LogManager.getLogManager().getLogger("")); 317 assertNull(log.getFilter()); 318 assertEquals(0, log.getHandlers().length); 319 // check it's set to the preconfigured level 320 assertSame(Level.INFO, log.getLevel()); 321 assertEquals("", log.getName()); 322 assertNull(log.getParent()); 323 assertNull(log.getResourceBundle()); 324 assertNull(log.getResourceBundleName()); 325 assertTrue(log.getUseParentHandlers()); 326 } 327 328 /* 329 * Test getLogger(String), getting a logger with existing parent. 330 */ 331 public void testGetLogger_WithParentNormal() { 332 assertNull(LogManager.getLogManager().getLogger( 333 "testGetLogger_WithParent_ParentLogger")); 334 // create the parent logger 335 Logger pLog = Logger.getLogger("testGetLogger_WithParent_ParentLogger", 336 VALID_RESOURCE_BUNDLE); 337 pLog.setLevel(Level.CONFIG); 338 pLog.addHandler(new MockHandler()); 339 pLog.setFilter(new MockFilter()); 340 pLog.setUseParentHandlers(false); 341 342 assertNull(LogManager.getLogManager().getLogger( 343 "testGetLogger_WithParent_ParentLogger.child")); 344 // create the child logger 345 Logger log = Logger 346 .getLogger("testGetLogger_WithParent_ParentLogger.child"); 347 assertNull(log.getFilter()); 348 assertEquals(0, log.getHandlers().length); 349 assertNull(log.getLevel()); 350 assertEquals("testGetLogger_WithParent_ParentLogger.child", log 351 .getName()); 352 assertSame(log.getParent(), pLog); 353 assertNull(log.getResourceBundle()); 354 assertNull(log.getResourceBundleName()); 355 assertTrue(log.getUseParentHandlers()); 356 } 357 358 // /* 359 // * Test getLogger(String), getting a logger with existing parent, using 360 // * abnormal names (containing '.'). 361 // */ 362 // public void testGetLogger_WithParentAbnormal() { 363 // Logger log = Logger.getLogger("."); 364 // assertSame(log.getParent(), Logger.getLogger("")); 365 // Logger log2 = Logger.getLogger(".."); 366 // assertSame(log2.getParent(), Logger.getLogger("")); 367 // //TODO: a lot more can be tested 368 // } 369 370 /* 371 * Test getLogger(String, String), getting a logger with no parent. 372 */ 373 public void testGetLoggerWithRes_Normal() throws Exception { 374 // config the level 375 Properties p = new Properties(); 376 p.put("testGetLoggerWithRes_Normal_ANewLogger.level", "ALL"); 377 LogManager.getLogManager().readConfiguration( 378 EnvironmentHelper.PropertiesToInputStream(p)); 379 380 assertNull(LogManager.getLogManager().getLogger( 381 "testGetLoggerWithRes_Normal_ANewLogger")); 382 // create a new logger 383 Logger log = Logger.getLogger("testGetLoggerWithRes_Normal_ANewLogger", 384 VALID_RESOURCE_BUNDLE); 385 // get an existing logger 386 assertSame(log, Logger 387 .getLogger("testGetLoggerWithRes_Normal_ANewLogger")); 388 // check it has been registered 389 assertSame(log, LogManager.getLogManager().getLogger( 390 "testGetLoggerWithRes_Normal_ANewLogger")); 391 392 assertNull(log.getFilter()); 393 assertEquals(0, log.getHandlers().length); 394 // check it's set to the preconfigured level 395 assertSame(Level.ALL, log.getLevel()); 396 assertEquals("testGetLoggerWithRes_Normal_ANewLogger", log.getName()); 397 assertNull(log.getParent().getParent()); 398 assertEquals(VALID_VALUE, log.getResourceBundle().getString(VALID_KEY)); 399 assertEquals(log.getResourceBundleName(), VALID_RESOURCE_BUNDLE); 400 assertTrue(log.getUseParentHandlers()); 401 } 402 403 /* 404 * Test getLogger(String, String) with null parameters. 405 */ 406 public void testGetLoggerWithRes_Null() { 407 Logger.getLogger("testGetLoggerWithRes_Null_ANewLogger", null); 408 try { 409 Logger.getLogger(null, VALID_RESOURCE_BUNDLE); 410 fail("Should throw NullPointerException!"); 411 } catch (NullPointerException e) { 412 } 413 } 414 415 /* 416 * Test getLogger(String, String) with invalid resource bundle. 417 */ 418 public void testGetLoggerWithRes_InvalidRes() { 419 try { 420 Logger.getLogger("", INVALID_RESOURCE_BUNDLE); 421 fail("Should throw MissingResourceException!"); 422 } catch (MissingResourceException e) { 423 } 424 assertNull(Logger.getLogger("").getResourceBundle()); 425 assertNull(Logger.getLogger("").getResourceBundleName()); 426 // try empty string 427 try { 428 Logger.getLogger("", ""); 429 fail("Should throw MissingResourceException!"); 430 } catch (MissingResourceException e) { 431 } 432 } 433 434 /* 435 * Test getLogger(String, String) with valid resource bundle, to get an 436 * existing logger with no associated resource bundle. 437 */ 438 public void testGetLoggerWithRes_ExistingLoggerWithNoRes() { 439 assertNull(LogManager.getLogManager().getLogger( 440 "testGetLoggerWithRes_ExistingLoggerWithNoRes_ANewLogger")); 441 // create a new logger 442 Logger log1 = Logger 443 .getLogger("testGetLoggerWithRes_ExistingLoggerWithNoRes_ANewLogger"); 444 // get an existing logger 445 Logger log2 = Logger.getLogger( 446 "testGetLoggerWithRes_ExistingLoggerWithNoRes_ANewLogger", 447 VALID_RESOURCE_BUNDLE); 448 assertSame(log1, log2); 449 assertEquals(VALID_VALUE, log1.getResourceBundle().getString(VALID_KEY)); 450 assertEquals(log1.getResourceBundleName(), VALID_RESOURCE_BUNDLE); 451 } 452 453 /* 454 * Test getLogger(String, String) with valid resource bundle, to get an 455 * existing logger with the same associated resource bundle. 456 */ 457 public void testGetLoggerWithRes_ExistingLoggerWithSameRes() { 458 assertNull(LogManager.getLogManager().getLogger( 459 "testGetLoggerWithRes_ExistingLoggerWithSameRes_ANewLogger")); 460 // create a new logger 461 Logger log1 = Logger.getLogger( 462 "testGetLoggerWithRes_ExistingLoggerWithSameRes_ANewLogger", 463 VALID_RESOURCE_BUNDLE); 464 // get an existing logger 465 Logger log2 = Logger.getLogger( 466 "testGetLoggerWithRes_ExistingLoggerWithSameRes_ANewLogger", 467 VALID_RESOURCE_BUNDLE); 468 assertSame(log1, log2); 469 assertEquals(VALID_VALUE, log1.getResourceBundle().getString(VALID_KEY)); 470 assertEquals(log1.getResourceBundleName(), VALID_RESOURCE_BUNDLE); 471 } 472 473 /* 474 * Test getLogger(String, String) with valid resource bundle, to get an 475 * existing logger with different associated resource bundle. 476 */ 477 public void testGetLoggerWithRes_ExistingLoggerWithDiffRes() { 478 assertNull(LogManager.getLogManager().getLogger( 479 "testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger")); 480 // create a new logger 481 Logger log1 = Logger.getLogger( 482 "testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger", 483 VALID_RESOURCE_BUNDLE); 484 assertNotNull(log1); 485 // get an existing logger 486 try { 487 Logger.getLogger("testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger", 488 VALID_RESOURCE_BUNDLE2); 489 fail("Should throw IllegalArgumentException!"); 490 } catch (IllegalArgumentException e) { 491 } 492 493 try { 494 Logger.getLogger("testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger", null); 495 fail("Should throw IllegalArgumentException!"); 496 } catch (IllegalArgumentException e) { 497 } 498 } 499 500 /* 501 * Test getLogger(String, String) with invalid name. 502 */ 503 public void testGetLoggerWithRes_InvalidName() { 504 Logger log = Logger.getLogger( 505 "...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|WithRes", 506 VALID_RESOURCE_BUNDLE); 507 assertEquals("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|WithRes", log 508 .getName()); 509 } 510 511 /* 512 * Test getLogger(String, String) with empty name. 513 */ 514 public void testGetLoggerWithRes_Empty() { 515 Logger log = Logger.getLogger("", VALID_RESOURCE_BUNDLE); 516 assertSame(log, LogManager.getLogManager().getLogger("")); 517 assertNull(log.getFilter()); 518 assertEquals(0, log.getHandlers().length); 519 // check it's set to the preconfigured level 520 assertSame(Level.INFO, log.getLevel()); 521 assertEquals("", log.getName()); 522 assertNull(log.getParent()); 523 assertEquals(VALID_VALUE, log.getResourceBundle().getString(VALID_KEY)); 524 assertEquals(log.getResourceBundleName(), VALID_RESOURCE_BUNDLE); 525 assertTrue(log.getUseParentHandlers()); 526 } 527 528 /* 529 * Test getLogger(String, String), getting a logger with existing parent. 530 */ 531 public void testGetLoggerWithRes_WithParentNormal() { 532 assertNull(LogManager.getLogManager().getLogger( 533 "testGetLoggerWithRes_WithParent_ParentLogger")); 534 // create the parent logger 535 Logger pLog = Logger 536 .getLogger("testGetLoggerWithRes_WithParent_ParentLogger"); 537 pLog.setLevel(Level.CONFIG); 538 pLog.addHandler(new MockHandler()); 539 pLog.setFilter(new MockFilter()); 540 pLog.setUseParentHandlers(false); 541 542 assertNull(LogManager.getLogManager().getLogger( 543 "testGetLoggerWithRes_WithParent_ParentLogger.child")); 544 // create the child logger 545 Logger log = Logger.getLogger( 546 "testGetLoggerWithRes_WithParent_ParentLogger.child", 547 VALID_RESOURCE_BUNDLE); 548 assertNull(log.getFilter()); 549 assertEquals(0, log.getHandlers().length); 550 assertNull(log.getLevel()); 551 assertEquals("testGetLoggerWithRes_WithParent_ParentLogger.child", log 552 .getName()); 553 assertSame(log.getParent(), pLog); 554 assertEquals(VALID_VALUE, log.getResourceBundle().getString(VALID_KEY)); 555 assertEquals(log.getResourceBundleName(), VALID_RESOURCE_BUNDLE); 556 assertTrue(log.getUseParentHandlers()); 557 } 558 559 /* 560 * Test addHandler(Handler) for a named logger with sufficient privilege. 561 */ 562 public void testAddHandler_NamedLoggerSufficientPrivilege() { 563 Logger log = Logger 564 .getLogger("testAddHandler_NamedLoggerSufficientPrivilege"); 565 MockHandler h = new MockHandler(); 566 assertEquals(log.getHandlers().length, 0); 567 log.addHandler(h); 568 assertEquals(log.getHandlers().length, 1); 569 assertSame(log.getHandlers()[0], h); 570 } 571 572 /* 573 * Test addHandler(Handler) for a named logger with sufficient privilege, 574 * add duplicate handlers. 575 */ 576 public void testAddHandler_NamedLoggerSufficientPrivilegeDuplicate() { 577 Logger log = Logger 578 .getLogger("testAddHandler_NamedLoggerSufficientPrivilegeDuplicate"); 579 MockHandler h = new MockHandler(); 580 assertEquals(log.getHandlers().length, 0); 581 log.addHandler(h); 582 log.addHandler(h); 583 assertEquals(log.getHandlers().length, 2); 584 assertSame(log.getHandlers()[0], h); 585 assertSame(log.getHandlers()[1], h); 586 } 587 588 /* 589 * Test addHandler(Handler) with a null handler. 590 */ 591 public void testAddHandler_Null() { 592 Logger log = Logger.getLogger("testAddHandler_Null"); 593 try { 594 log.addHandler(null); 595 fail("Should throw NullPointerException!"); 596 } catch (NullPointerException e) { 597 } 598 assertEquals(log.getHandlers().length, 0); 599 } 600 601 /* 602 * Test addHandler(Handler) for an anonymous logger with sufficient 603 * privilege. 604 */ 605 public void testAddHandler_AnonyLoggerSufficientPrivilege() { 606 Logger log = Logger.getAnonymousLogger(); 607 MockHandler h = new MockHandler(); 608 assertEquals(log.getHandlers().length, 0); 609 log.addHandler(h); 610 assertEquals(log.getHandlers().length, 1); 611 assertSame(log.getHandlers()[0], h); 612 } 613 614 /* 615 * Test removeHandler(Handler) for a named logger with sufficient privilege, 616 * remove an existing handler. 617 */ 618 public void testRemoveHandler_NamedLoggerSufficientPrivilege() { 619 Logger log = Logger 620 .getLogger("testRemoveHandler_NamedLoggerSufficientPrivilege"); 621 MockHandler h = new MockHandler(); 622 log.addHandler(h); 623 assertEquals(log.getHandlers().length, 1); 624 log.removeHandler(h); 625 assertEquals(log.getHandlers().length, 0); 626 } 627 628 /* 629 * Test removeHandler(Handler) for a named logger with sufficient privilege, 630 * remove a non-existing handler. 631 */ 632 public void testRemoveHandler_NamedLoggerSufficientPrivilegeNotExisting() { 633 Logger log = Logger 634 .getLogger("testRemoveHandler_NamedLoggerSufficientPrivilegeNotExisting"); 635 MockHandler h = new MockHandler(); 636 assertEquals(log.getHandlers().length, 0); 637 log.removeHandler(h); 638 assertEquals(log.getHandlers().length, 0); 639 } 640 641 /* 642 * Test removeHandler(Handler) with a null handler. 643 */ 644 public void testRemoveHandler_Null() { 645 Logger log = Logger.getLogger("testRemoveHandler_Null"); 646 log.removeHandler(null); 647 assertEquals(log.getHandlers().length, 0); 648 } 649 650 /* 651 * Test removeHandler(Handler) for an anonymous logger with sufficient 652 * privilege. 653 */ 654 public void testRemoveHandler_AnonyLoggerSufficientPrivilege() { 655 Logger log = Logger.getAnonymousLogger(); 656 MockHandler h = new MockHandler(); 657 log.addHandler(h); 658 assertEquals(log.getHandlers().length, 1); 659 log.removeHandler(h); 660 assertEquals(log.getHandlers().length, 0); 661 } 662 663 /* 664 * Test getHandlers() when there's no handler. 665 */ 666 public void testGetHandlers_None() { 667 Logger log = Logger.getLogger("testGetHandlers_None"); 668 assertEquals(log.getHandlers().length, 0); 669 } 670 671 /* 672 * Test getHandlers() when there are several handlers. 673 */ 674 public void testGetHandlers_Several() { 675 Logger log = Logger.getLogger("testGetHandlers_None"); 676 assertEquals(log.getHandlers().length, 0); 677 MockHandler h1 = new MockHandler(); 678 MockHandler h2 = new MockHandler(); 679 MockHandler h3 = new MockHandler(); 680 log.addHandler(h1); 681 log.addHandler(h2); 682 log.addHandler(h3); 683 assertEquals(log.getHandlers().length, 3); 684 assertSame(log.getHandlers()[0], h1); 685 assertSame(log.getHandlers()[1], h2); 686 assertSame(log.getHandlers()[2], h3); 687 // remove one 688 log.removeHandler(h2); 689 assertEquals(log.getHandlers().length, 2); 690 assertSame(log.getHandlers()[0], h1); 691 assertSame(log.getHandlers()[1], h3); 692 } 693 694 /* 695 * Test getFilter & setFilter with normal value for a named logger, having 696 * sufficient privilege. 697 */ 698 public void testGetSetFilter_NamedLoggerSufficientPrivilege() { 699 Logger log = Logger 700 .getLogger("testGetSetFilter_NamedLoggerSufficientPrivilege"); 701 Filter f = new MockFilter(); 702 703 assertNull(log.getFilter()); 704 log.setFilter(f); 705 assertSame(f, log.getFilter()); 706 } 707 708 /* 709 * Test getFilter & setFilter with null value, having sufficient privilege. 710 */ 711 public void testGetSetFilter_Null() { 712 Logger log = Logger.getLogger("testGetSetFilter_Null"); 713 714 assertNull(log.getFilter()); 715 log.setFilter(null); 716 assertNull(log.getFilter()); 717 log.setFilter(new MockFilter()); 718 log.setFilter(null); 719 assertNull(log.getFilter()); 720 } 721 722 /* 723 * Test setFilter for an anonymous logger with sufficient privilege. 724 */ 725 public void testSetFilter_AnonyLoggerSufficientPrivilege() { 726 Logger log = Logger.getAnonymousLogger(); 727 Filter f = new MockFilter(); 728 assertNull(log.getFilter()); 729 log.setFilter(f); 730 assertSame(f, log.getFilter()); 731 } 732 733 /* 734 * Test getLevel & setLevel with normal value for a named logger, having 735 * sufficient privilege. 736 */ 737 public void testGetSetLevel_NamedLoggerSufficientPrivilege() { 738 Logger log = Logger 739 .getLogger("testGetSetLevel_NamedLoggerSufficientPrivilege"); 740 741 assertNull(log.getLevel()); 742 log.setLevel(Level.CONFIG); 743 assertSame(Level.CONFIG, log.getLevel()); 744 } 745 746 /* 747 * Test getLevel & setLevel with null value, having sufficient privilege. 748 */ 749 public void testGetSetLevel_Null() { 750 Logger log = Logger.getLogger("testGetSetLevel_Null"); 751 752 assertNull(log.getLevel()); 753 log.setLevel(null); 754 assertNull(log.getLevel()); 755 log.setLevel(Level.CONFIG); 756 log.setLevel(null); 757 assertNull(log.getLevel()); 758 } 759 760 /* 761 * Test setLevel for an anonymous logger with sufficient privilege. 762 */ 763 public void testSetLevel_AnonyLoggerSufficientPrivilege() { 764 Logger log = Logger.getAnonymousLogger(); 765 assertNull(log.getLevel()); 766 log.setLevel(Level.CONFIG); 767 assertSame(Level.CONFIG, log.getLevel()); 768 } 769 770 /* 771 * Test getUseParentHandlers & setUseParentHandlers with normal value for a 772 * named logger, having sufficient privilege. 773 */ 774 public void testGetSetUseParentHandlers_NamedLoggerSufficientPrivilege() { 775 Logger log = Logger 776 .getLogger("testGetSetUseParentHandlers_NamedLoggerSufficientPrivilege"); 777 778 assertTrue(log.getUseParentHandlers()); 779 log.setUseParentHandlers(false); 780 assertFalse(log.getUseParentHandlers()); 781 } 782 783 /* 784 * Test setUseParentHandlers for an anonymous logger with sufficient 785 * privilege. 786 */ 787 public void testSetUseParentHandlers_AnonyLoggerSufficientPrivilege() { 788 Logger log = Logger.getAnonymousLogger(); 789 assertTrue(log.getUseParentHandlers()); 790 log.setUseParentHandlers(false); 791 assertFalse(log.getUseParentHandlers()); 792 } 793 794 /* 795 * Test getParent() for root logger. 796 */ 797 public void testGetParent_Root() { 798 assertNull(Logger.getLogger("").getParent()); 799 } 800 801 /* 802 * Test getParent() for normal named loggers. 803 */ 804 public void testGetParent_NormalNamed() { 805 Logger log = Logger.getLogger("testGetParent_NormalNamed"); 806 assertSame(log.getParent(), Logger.getLogger("")); 807 Logger child = Logger.getLogger("testGetParent_NormalNamed.child"); 808 assertSame(child.getParent(), log); 809 Logger child2 = Logger.getLogger("testGetParent_NormalNamed.a.b.c"); 810 assertSame(child2.getParent(), log); 811 } 812 813 /* 814 * Test getParent() for anonymous loggers. 815 */ 816 public void testGetParent_Anonymous() { 817 assertSame(Logger.getAnonymousLogger().getParent(), Logger 818 .getLogger("")); 819 } 820 821 /* 822 * Test setParent(Logger) for the mock logger since it is advised not to 823 * call this method on named loggers. Test normal conditions. 824 */ 825 public void testSetParent_Normal() { 826 Logger log = new MockLogger(null, null); 827 Logger parent = new MockLogger(null, null); 828 assertNull(log.getParent()); 829 log.setParent(parent); 830 assertSame(log.getParent(), parent); 831 } 832 833 /* 834 * Test setParent(Logger) with null. 835 */ 836 public void testSetParent_Null() { 837 try { 838 (new MockLogger(null, null)).setParent(null); 839 fail("Should throw NullPointerException!"); 840 } catch (NullPointerException e) { 841 } 842 } 843 844 /* 845 * Test getName() for normal names. 846 */ 847 public void testGetName_Normal() { 848 Logger log = Logger.getLogger("testGetName_Normal"); 849 assertEquals("testGetName_Normal", log.getName()); 850 851 Logger mlog = new MockLogger("testGetName_Normal", null); 852 assertEquals("testGetName_Normal", mlog.getName()); 853 } 854 855 /* 856 * Test getName() for empty name. 857 */ 858 public void testGetName_Empty() { 859 Logger log = Logger.getLogger(""); 860 assertEquals("", log.getName()); 861 862 Logger mlog = new MockLogger("", null); 863 assertEquals("", mlog.getName()); 864 } 865 866 /* 867 * Test getName() for null name. 868 */ 869 public void testGetName_Null() { 870 Logger log = Logger.getAnonymousLogger(); 871 assertNull(log.getName()); 872 873 Logger mlog = new MockLogger(null, null); 874 assertNull(mlog.getName()); 875 } 876 877 /* 878 * Test getResourceBundle() when it it not null. 879 */ 880 public void testGetResourceBundle_Normal() { 881 Logger log = Logger.getLogger("testGetResourceBundle_Normal", 882 VALID_RESOURCE_BUNDLE); 883 assertEquals(VALID_VALUE, log.getResourceBundle().getString(VALID_KEY)); 884 885 Logger mlog = new MockLogger(null, VALID_RESOURCE_BUNDLE); 886 assertEquals(VALID_VALUE, mlog.getResourceBundle().getString(VALID_KEY)); 887 } 888 889 /* 890 * Test getResourceBundle() when it it null. 891 */ 892 public void testGetResourceBundle_Null() { 893 Logger log = Logger.getLogger("testGetResourceBundle_Null", null); 894 assertNull(log.getResourceBundle()); 895 896 Logger mlog = new MockLogger(null, null); 897 assertNull(mlog.getResourceBundle()); 898 } 899 900 /* 901 * Test getResourceBundleName() when it it not null. 902 */ 903 public void testGetResourceBundleName_Normal() { 904 Logger log = Logger.getLogger("testGetResourceBundleName_Normal", 905 VALID_RESOURCE_BUNDLE); 906 assertEquals(VALID_RESOURCE_BUNDLE, log.getResourceBundleName()); 907 908 Logger mlog = new MockLogger(null, null); 909 assertNull(mlog.getResourceBundleName()); 910 } 911 912 /* 913 * Test getResourceBundleName() when it it null. 914 */ 915 public void testGetResourceBundleName_Null() { 916 Logger log = Logger.getLogger("testGetResourceBundleName_Null", null); 917 assertNull(log.getResourceBundleName()); 918 919 Logger mlog = new MockLogger(null, null); 920 assertNull(mlog.getResourceBundleName()); 921 } 922 923 /* 924 * Test isLoggable(Level). 925 */ 926 public void testIsLoggable() { 927 MockLogger mlog = new MockLogger(null, null); 928 assertNull(mlog.getLevel()); 929 assertNull(mlog.getParent()); 930 931 assertTrue(mlog.isLoggable(Level.SEVERE)); 932 assertTrue(mlog.isLoggable(Level.WARNING)); 933 assertTrue(mlog.isLoggable(Level.INFO)); 934 assertFalse(mlog.isLoggable(Level.CONFIG)); 935 assertFalse(mlog.isLoggable(Level.FINE)); 936 assertFalse(mlog.isLoggable(Level.ALL)); 937 assertTrue(mlog.isLoggable(Level.OFF)); 938 939 mlog.setLevel(Level.CONFIG); 940 assertTrue(mlog.isLoggable(Level.SEVERE)); 941 assertTrue(mlog.isLoggable(Level.CONFIG)); 942 assertFalse(mlog.isLoggable(Level.ALL)); 943 assertTrue(mlog.isLoggable(Level.OFF)); 944 945 mlog.setLevel(Level.ALL); 946 assertTrue(mlog.isLoggable(Level.ALL)); 947 assertTrue(mlog.isLoggable(Level.SEVERE)); 948 assertTrue(mlog.isLoggable(Level.OFF)); 949 950 mlog.setLevel(Level.OFF); 951 assertFalse(mlog.isLoggable(Level.ALL)); 952 assertFalse(mlog.isLoggable(Level.SEVERE)); 953 assertFalse(mlog.isLoggable(Level.OFF)); 954 } 955 956 /* 957 * Test throwing(String, String, Throwable) with normal values. 958 */ 959 public void testThrowing_Normal() { 960 Throwable t = new Throwable(); 961 this.sharedLogger.setLevel(Level.FINER); 962 this.sharedLogger.throwing("sourceClass", "sourceMethod", t); 963 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 964 assertTrue(CallVerificationStack.getInstance().empty()); 965 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 966 assertEquals(r.getMessage(), "THROW"); 967 assertSame(r.getResourceBundleName(), this.sharedLogger 968 .getResourceBundleName()); 969 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 970 assertSame(r.getSourceClassName(), "sourceClass"); 971 assertSame(r.getSourceMethodName(), "sourceMethod"); 972 assertSame(r.getLevel(), Level.FINER); 973 assertSame(r.getParameters(), null); 974 assertSame(r.getThrown(), t); 975 976 this.sharedLogger.setLevel(Level.FINE); 977 this.sharedLogger.throwing("sourceClass", "sourceMethod", t); 978 assertTrue(CallVerificationStack.getInstance().empty()); 979 } 980 981 /* 982 * Test throwing(String, String, Throwable) with null values. 983 */ 984 public void testThrowing_Null() { 985 Logger child = new MockLogger("childLogger", null); 986 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 987 child.addHandler(new MockHandler()); 988 child.setParent(parent); 989 990 child.setLevel(Level.FINER); 991 child.throwing(null, null, null); 992 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 993 assertTrue(CallVerificationStack.getInstance().empty()); 994 assertSame(r.getLoggerName(), child.getName()); 995 assertEquals(r.getMessage(), "THROW"); 996 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 997 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 998 assertSame(r.getSourceClassName(), null); 999 assertSame(r.getSourceMethodName(), null); 1000 assertSame(r.getLevel(), Level.FINER); 1001 assertSame(r.getParameters(), null); 1002 assertSame(r.getThrown(), null); 1003 } 1004 1005 /* 1006 * Test entering(String, String) with normal values. 1007 */ 1008 public void testEntering_StringString_Normal() { 1009 this.sharedLogger.setLevel(Level.FINER); 1010 this.sharedLogger.entering("sourceClass", "sourceMethod"); 1011 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1012 assertTrue(CallVerificationStack.getInstance().empty()); 1013 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1014 assertEquals(r.getMessage(), "ENTRY"); 1015 assertSame(r.getResourceBundleName(), this.sharedLogger 1016 .getResourceBundleName()); 1017 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1018 assertSame(r.getSourceClassName(), "sourceClass"); 1019 assertSame(r.getSourceMethodName(), "sourceMethod"); 1020 assertSame(r.getLevel(), Level.FINER); 1021 assertSame(r.getParameters(), null); 1022 assertSame(r.getThrown(), null); 1023 1024 this.sharedLogger.setLevel(Level.FINE); 1025 this.sharedLogger.entering("sourceClass", "sourceMethod"); 1026 assertTrue(CallVerificationStack.getInstance().empty()); 1027 } 1028 1029 /* 1030 * Test entering(String, String) with null values. 1031 */ 1032 public void testEntering_StringString_Null() { 1033 Logger child = new MockLogger("childLogger", null); 1034 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1035 child.addHandler(new MockHandler()); 1036 child.setParent(parent); 1037 1038 child.setLevel(Level.FINER); 1039 child.entering(null, null); 1040 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1041 assertTrue(CallVerificationStack.getInstance().empty()); 1042 assertSame(r.getLoggerName(), child.getName()); 1043 assertEquals(r.getMessage(), "ENTRY"); 1044 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1045 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1046 assertSame(r.getSourceClassName(), null); 1047 assertSame(r.getSourceMethodName(), null); 1048 assertSame(r.getLevel(), Level.FINER); 1049 assertSame(r.getParameters(), null); 1050 assertSame(r.getThrown(), null); 1051 } 1052 1053 /* 1054 * Test entering(String, String, Object) with normal values. 1055 */ 1056 public void testEntering_StringStringObject_Normal() { 1057 Object param = new Object(); 1058 this.sharedLogger.setLevel(Level.FINER); 1059 this.sharedLogger.entering("sourceClass", "sourceMethod", param); 1060 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1061 assertTrue(CallVerificationStack.getInstance().empty()); 1062 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1063 assertEquals(r.getMessage(), "ENTRY {0}"); 1064 assertSame(r.getResourceBundleName(), this.sharedLogger 1065 .getResourceBundleName()); 1066 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1067 assertSame(r.getSourceClassName(), "sourceClass"); 1068 assertSame(r.getSourceMethodName(), "sourceMethod"); 1069 assertSame(r.getLevel(), Level.FINER); 1070 assertSame(r.getParameters()[0], param); 1071 assertEquals(1, r.getParameters().length); 1072 assertSame(r.getThrown(), null); 1073 1074 this.sharedLogger.setLevel(Level.FINE); 1075 this.sharedLogger.entering("sourceClass", "sourceMethod", param); 1076 assertTrue(CallVerificationStack.getInstance().empty()); 1077 } 1078 1079 /* 1080 * Test entering(String, String, Object) with null values. 1081 */ 1082 public void testEntering_StringStringObject_Null() { 1083 Logger child = new MockLogger("childLogger", null); 1084 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1085 child.addHandler(new MockHandler()); 1086 child.setParent(parent); 1087 1088 child.setLevel(Level.FINER); 1089 child.entering(null, null, (Object) null); 1090 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1091 assertTrue(CallVerificationStack.getInstance().empty()); 1092 assertSame(r.getLoggerName(), child.getName()); 1093 assertEquals(r.getMessage(), "ENTRY {0}"); 1094 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1095 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1096 assertSame(r.getSourceClassName(), null); 1097 assertSame(r.getSourceMethodName(), null); 1098 assertSame(r.getLevel(), Level.FINER); 1099 assertEquals(r.getParameters().length, 1); 1100 assertNull(r.getParameters()[0]); 1101 assertSame(r.getThrown(), null); 1102 } 1103 1104 /* 1105 * Test entering(String, String, Object[]) with normal values. 1106 */ 1107 public void testEntering_StringStringObjects_Normal() { 1108 Object[] params = new Object[2]; 1109 params[0] = new Object(); 1110 params[1] = new Object(); 1111 this.sharedLogger.setLevel(Level.FINER); 1112 this.sharedLogger.entering("sourceClass", "sourceMethod", params); 1113 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1114 assertTrue(CallVerificationStack.getInstance().empty()); 1115 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1116 assertEquals(r.getMessage(), "ENTRY {0} {1}"); 1117 assertSame(r.getResourceBundleName(), this.sharedLogger 1118 .getResourceBundleName()); 1119 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1120 assertSame(r.getSourceClassName(), "sourceClass"); 1121 assertSame(r.getSourceMethodName(), "sourceMethod"); 1122 assertSame(r.getLevel(), Level.FINER); 1123 assertSame(r.getParameters()[0], params[0]); 1124 assertSame(r.getParameters()[1], params[1]); 1125 assertEquals(2, r.getParameters().length); 1126 assertSame(r.getThrown(), null); 1127 1128 this.sharedLogger.setLevel(Level.FINE); 1129 this.sharedLogger.entering("sourceClass", "sourceMethod", params); 1130 assertTrue(CallVerificationStack.getInstance().empty()); 1131 } 1132 1133 /* 1134 * Test entering(String, String, Object[]) with null class name and method 1135 * name and empty parameter array. 1136 */ 1137 public void testEntering_StringStringObjects_NullEmpty() { 1138 Logger child = new MockLogger("childLogger", null); 1139 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1140 child.addHandler(new MockHandler()); 1141 child.setParent(parent); 1142 1143 child.setLevel(Level.FINER); 1144 child.entering(null, null, new Object[0]); 1145 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1146 assertTrue(CallVerificationStack.getInstance().empty()); 1147 assertSame(r.getLoggerName(), child.getName()); 1148 assertEquals(r.getMessage(), "ENTRY"); 1149 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1150 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1151 assertSame(r.getSourceClassName(), null); 1152 assertSame(r.getSourceMethodName(), null); 1153 assertSame(r.getLevel(), Level.FINER); 1154 assertEquals(0, r.getParameters().length); 1155 assertSame(r.getThrown(), null); 1156 } 1157 1158 /* 1159 * Test entering(String, String, Object[]) with null values with appropriate 1160 * logging level set. 1161 */ 1162 public void testEntering_StringStringObjects_Null() { 1163 sharedLogger.setLevel(Level.FINER); 1164 sharedLogger.entering(null, null, (Object[]) null); 1165 // regression test for Harmony-1265 1166 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1167 assertTrue(CallVerificationStack.getInstance().empty()); 1168 assertSame(sharedLogger.getName(), r.getLoggerName()); 1169 assertEquals("ENTRY", r.getMessage()); 1170 assertSame(sharedLogger.getResourceBundleName(), r 1171 .getResourceBundleName()); 1172 assertSame(sharedLogger.getResourceBundle(), r.getResourceBundle()); 1173 assertNull(r.getSourceClassName()); 1174 assertNull(r.getSourceMethodName()); 1175 assertSame(Level.FINER, r.getLevel()); 1176 assertNull(r.getParameters()); 1177 assertNull(r.getThrown()); 1178 } 1179 1180 /* 1181 * Test entering(String, String, Object[]) with null values with 1182 * inappropriate logging level set. 1183 */ 1184 public void testEntering_StringStringObjects_NullDisabled() { 1185 this.sharedLogger.setLevel(Level.FINE); 1186 this.sharedLogger.entering(null, null, (Object[]) null); 1187 assertTrue(CallVerificationStack.getInstance().empty()); 1188 } 1189 1190 /* 1191 * Test exiting(String, String) with normal values. 1192 */ 1193 public void testExiting_StringString_Normal() { 1194 this.sharedLogger.setLevel(Level.FINER); 1195 this.sharedLogger.exiting("sourceClass", "sourceMethod"); 1196 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1197 assertTrue(CallVerificationStack.getInstance().empty()); 1198 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1199 assertEquals(r.getMessage(), "RETURN"); 1200 assertSame(r.getResourceBundleName(), this.sharedLogger 1201 .getResourceBundleName()); 1202 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1203 assertSame(r.getSourceClassName(), "sourceClass"); 1204 assertSame(r.getSourceMethodName(), "sourceMethod"); 1205 assertSame(r.getLevel(), Level.FINER); 1206 assertNull(r.getParameters()); 1207 assertSame(r.getThrown(), null); 1208 1209 this.sharedLogger.setLevel(Level.FINE); 1210 this.sharedLogger.exiting("sourceClass", "sourceMethod"); 1211 assertTrue(CallVerificationStack.getInstance().empty()); 1212 } 1213 1214 /* 1215 * Test exiting(String, String) with null values. 1216 */ 1217 public void testExiting_StringString_Null() { 1218 Logger child = new MockLogger("childLogger", null); 1219 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1220 child.addHandler(new MockHandler()); 1221 child.setParent(parent); 1222 1223 child.setLevel(Level.FINER); 1224 child.exiting(null, null); 1225 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1226 assertTrue(CallVerificationStack.getInstance().empty()); 1227 assertSame(r.getLoggerName(), child.getName()); 1228 assertEquals(r.getMessage(), "RETURN"); 1229 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1230 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1231 assertSame(r.getSourceClassName(), null); 1232 assertSame(r.getSourceMethodName(), null); 1233 assertSame(r.getLevel(), Level.FINER); 1234 assertSame(r.getParameters(), null); 1235 assertSame(r.getThrown(), null); 1236 } 1237 1238 /* 1239 * Test exiting(String, String, Object) with normal values. 1240 */ 1241 public void testExiting_StringStringObject_Normal() { 1242 Object param = new Object(); 1243 this.sharedLogger.setLevel(Level.FINER); 1244 this.sharedLogger.exiting("sourceClass", "sourceMethod", param); 1245 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1246 assertTrue(CallVerificationStack.getInstance().empty()); 1247 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1248 assertEquals(r.getMessage(), "RETURN {0}"); 1249 assertSame(r.getResourceBundleName(), this.sharedLogger 1250 .getResourceBundleName()); 1251 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1252 assertSame(r.getSourceClassName(), "sourceClass"); 1253 assertSame(r.getSourceMethodName(), "sourceMethod"); 1254 assertSame(r.getLevel(), Level.FINER); 1255 assertSame(r.getParameters()[0], param); 1256 assertEquals(1, r.getParameters().length); 1257 assertSame(r.getThrown(), null); 1258 1259 this.sharedLogger.setLevel(Level.FINE); 1260 this.sharedLogger.exiting("sourceClass", "sourceMethod", param); 1261 assertTrue(CallVerificationStack.getInstance().empty()); 1262 } 1263 1264 /* 1265 * Test exiting(String, String, Object) with null values. 1266 */ 1267 public void testExiting_StringStringObject_Null() { 1268 Logger child = new MockLogger("childLogger", null); 1269 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1270 child.addHandler(new MockHandler()); 1271 child.setParent(parent); 1272 1273 child.setLevel(Level.FINER); 1274 child.exiting(null, null, (Object) null); 1275 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1276 assertTrue(CallVerificationStack.getInstance().empty()); 1277 assertSame(r.getLoggerName(), child.getName()); 1278 assertEquals(r.getMessage(), "RETURN {0}"); 1279 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1280 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1281 assertSame(r.getSourceClassName(), null); 1282 assertSame(r.getSourceMethodName(), null); 1283 assertSame(r.getLevel(), Level.FINER); 1284 assertEquals(r.getParameters().length, 1); 1285 assertNull(r.getParameters()[0]); 1286 assertSame(r.getThrown(), null); 1287 } 1288 1289 /* 1290 * Test config(String) with normal values. 1291 */ 1292 public void testConfig_Normal() { 1293 this.sharedLogger.setLevel(Level.CONFIG); 1294 this.sharedLogger.config("config msg"); 1295 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1296 assertTrue(CallVerificationStack.getInstance().empty()); 1297 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1298 assertEquals(r.getMessage(), "config msg"); 1299 assertSame(r.getResourceBundleName(), this.sharedLogger 1300 .getResourceBundleName()); 1301 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1302 assertSame(r.getSourceClassName(), null); 1303 assertSame(r.getSourceMethodName(), null); 1304 assertSame(r.getLevel(), Level.CONFIG); 1305 assertNull(r.getParameters()); 1306 assertSame(r.getThrown(), null); 1307 1308 this.sharedLogger.setLevel(Level.INFO); 1309 this.sharedLogger.config("config again"); 1310 assertTrue(CallVerificationStack.getInstance().empty()); 1311 } 1312 1313 /* 1314 * Test config(String) with null values. 1315 */ 1316 public void testConfig_Null() { 1317 Logger child = new MockLogger("childLogger", null); 1318 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1319 child.addHandler(new MockHandler()); 1320 child.setParent(parent); 1321 1322 child.setLevel(Level.CONFIG); 1323 child.config(null); 1324 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1325 assertTrue(CallVerificationStack.getInstance().empty()); 1326 assertSame(r.getLoggerName(), child.getName()); 1327 assertNull(r.getMessage()); 1328 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1329 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1330 assertSame(r.getSourceClassName(), null); 1331 assertSame(r.getSourceMethodName(), null); 1332 assertSame(r.getLevel(), Level.CONFIG); 1333 assertNull(r.getParameters()); 1334 assertSame(r.getThrown(), null); 1335 1336 this.sharedLogger.setLevel(Level.INFO); 1337 this.sharedLogger.config(null); 1338 assertTrue(CallVerificationStack.getInstance().empty()); 1339 } 1340 1341 /* 1342 * Test fine(String) with normal values. 1343 */ 1344 public void testFine_Normal() { 1345 this.sharedLogger.setLevel(Level.FINE); 1346 this.sharedLogger.fine("fine msg"); 1347 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1348 assertTrue(CallVerificationStack.getInstance().empty()); 1349 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1350 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1351 assertEquals(r.getMessage(), "fine msg"); 1352 assertSame(r.getResourceBundleName(), this.sharedLogger 1353 .getResourceBundleName()); 1354 assertSame(r.getSourceClassName(), null); 1355 assertSame(r.getSourceMethodName(), null); 1356 assertSame(r.getLevel(), Level.FINE); 1357 assertNull(r.getParameters()); 1358 assertSame(r.getThrown(), null); 1359 1360 this.sharedLogger.setLevel(Level.CONFIG); 1361 this.sharedLogger.fine("fine again"); 1362 assertTrue(CallVerificationStack.getInstance().empty()); 1363 } 1364 1365 /* 1366 * Test fine(String) with null values. 1367 */ 1368 public void testFine_Null() { 1369 Logger child = new MockLogger("childLogger", null); 1370 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1371 child.addHandler(new MockHandler()); 1372 child.setParent(parent); 1373 1374 child.setLevel(Level.FINE); 1375 child.fine(null); 1376 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1377 assertTrue(CallVerificationStack.getInstance().empty()); 1378 assertSame(r.getLoggerName(), child.getName()); 1379 assertNull(r.getMessage()); 1380 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1381 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1382 assertSame(r.getSourceClassName(), null); 1383 assertSame(r.getSourceMethodName(), null); 1384 assertSame(r.getLevel(), Level.FINE); 1385 assertNull(r.getParameters()); 1386 assertSame(r.getThrown(), null); 1387 1388 this.sharedLogger.setLevel(Level.CONFIG); 1389 this.sharedLogger.fine(null); 1390 assertTrue(CallVerificationStack.getInstance().empty()); 1391 } 1392 1393 /* 1394 * Test finer(String) with normal values. 1395 */ 1396 public void testFiner_Normal() { 1397 this.sharedLogger.setLevel(Level.FINER); 1398 this.sharedLogger.finer("finer msg"); 1399 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1400 assertTrue(CallVerificationStack.getInstance().empty()); 1401 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1402 assertEquals(r.getMessage(), "finer msg"); 1403 assertSame(r.getResourceBundleName(), this.sharedLogger 1404 .getResourceBundleName()); 1405 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1406 assertSame(r.getSourceClassName(), null); 1407 assertSame(r.getSourceMethodName(), null); 1408 assertSame(r.getLevel(), Level.FINER); 1409 assertNull(r.getParameters()); 1410 assertSame(r.getThrown(), null); 1411 1412 this.sharedLogger.setLevel(Level.FINE); 1413 this.sharedLogger.finer("finer again"); 1414 assertTrue(CallVerificationStack.getInstance().empty()); 1415 } 1416 1417 /* 1418 * Test finer(String) with null values. 1419 */ 1420 public void testFiner_Null() { 1421 Logger child = new MockLogger("childLogger", null); 1422 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1423 child.addHandler(new MockHandler()); 1424 child.setParent(parent); 1425 1426 child.setLevel(Level.FINER); 1427 child.finer(null); 1428 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1429 assertTrue(CallVerificationStack.getInstance().empty()); 1430 assertSame(r.getLoggerName(), child.getName()); 1431 assertNull(r.getMessage()); 1432 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1433 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1434 assertSame(r.getSourceClassName(), null); 1435 assertSame(r.getSourceMethodName(), null); 1436 assertSame(r.getLevel(), Level.FINER); 1437 assertNull(r.getParameters()); 1438 assertSame(r.getThrown(), null); 1439 1440 this.sharedLogger.setLevel(Level.FINE); 1441 this.sharedLogger.finer(null); 1442 assertTrue(CallVerificationStack.getInstance().empty()); 1443 } 1444 1445 /* 1446 * Test finest(String) with normal values. 1447 */ 1448 public void testFinest_Normal() { 1449 this.sharedLogger.setLevel(Level.FINEST); 1450 this.sharedLogger.finest("finest msg"); 1451 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1452 assertTrue(CallVerificationStack.getInstance().empty()); 1453 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1454 assertEquals(r.getMessage(), "finest msg"); 1455 assertSame(r.getResourceBundleName(), this.sharedLogger 1456 .getResourceBundleName()); 1457 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1458 assertSame(r.getSourceClassName(), null); 1459 assertSame(r.getSourceMethodName(), null); 1460 assertSame(r.getLevel(), Level.FINEST); 1461 assertNull(r.getParameters()); 1462 assertSame(r.getThrown(), null); 1463 1464 this.sharedLogger.setLevel(Level.FINER); 1465 this.sharedLogger.finest("finest again"); 1466 assertTrue(CallVerificationStack.getInstance().empty()); 1467 } 1468 1469 /* 1470 * Test finest(String) with null values. 1471 */ 1472 public void testFinest_Null() { 1473 Logger child = new MockLogger("childLogger", null); 1474 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1475 child.addHandler(new MockHandler()); 1476 child.setParent(parent); 1477 1478 child.setLevel(Level.FINEST); 1479 child.finest(null); 1480 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1481 assertTrue(CallVerificationStack.getInstance().empty()); 1482 assertSame(r.getLoggerName(), child.getName()); 1483 assertNull(r.getMessage()); 1484 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1485 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1486 assertSame(r.getSourceClassName(), null); 1487 assertSame(r.getSourceMethodName(), null); 1488 assertSame(r.getLevel(), Level.FINEST); 1489 assertNull(r.getParameters()); 1490 assertSame(r.getThrown(), null); 1491 1492 this.sharedLogger.setLevel(Level.FINER); 1493 this.sharedLogger.finest(null); 1494 assertTrue(CallVerificationStack.getInstance().empty()); 1495 } 1496 1497 /* 1498 * Test info(String) with normal values. 1499 */ 1500 public void testInfo_Normal() { 1501 this.sharedLogger.setLevel(Level.INFO); 1502 this.sharedLogger.info("info msg"); 1503 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1504 assertTrue(CallVerificationStack.getInstance().empty()); 1505 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1506 assertEquals(r.getMessage(), "info msg"); 1507 assertSame(r.getResourceBundleName(), this.sharedLogger 1508 .getResourceBundleName()); 1509 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1510 assertSame(r.getSourceClassName(), null); 1511 assertSame(r.getSourceMethodName(), null); 1512 assertSame(r.getLevel(), Level.INFO); 1513 assertNull(r.getParameters()); 1514 assertSame(r.getThrown(), null); 1515 1516 this.sharedLogger.setLevel(Level.WARNING); 1517 this.sharedLogger.info("info again"); 1518 assertTrue(CallVerificationStack.getInstance().empty()); 1519 } 1520 1521 /* 1522 * Test info(String) with null values. 1523 */ 1524 public void testInfo_Null() { 1525 Logger child = new MockLogger("childLogger", null); 1526 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1527 child.addHandler(new MockHandler()); 1528 child.setParent(parent); 1529 1530 child.setLevel(Level.INFO); 1531 child.info(null); 1532 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1533 assertTrue(CallVerificationStack.getInstance().empty()); 1534 assertSame(r.getLoggerName(), child.getName()); 1535 assertNull(r.getMessage()); 1536 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1537 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1538 assertSame(r.getSourceClassName(), null); 1539 assertSame(r.getSourceMethodName(), null); 1540 assertSame(r.getLevel(), Level.INFO); 1541 assertNull(r.getParameters()); 1542 assertSame(r.getThrown(), null); 1543 1544 this.sharedLogger.setLevel(Level.WARNING); 1545 this.sharedLogger.info(null); 1546 assertTrue(CallVerificationStack.getInstance().empty()); 1547 } 1548 1549 /* 1550 * Test warning(String) with normal values. 1551 */ 1552 public void testWarning_Normal() { 1553 this.sharedLogger.setLevel(Level.WARNING); 1554 this.sharedLogger.warning("warning msg"); 1555 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1556 assertTrue(CallVerificationStack.getInstance().empty()); 1557 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1558 assertEquals(r.getMessage(), "warning msg"); 1559 assertSame(r.getResourceBundleName(), this.sharedLogger 1560 .getResourceBundleName()); 1561 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1562 assertSame(r.getSourceClassName(), null); 1563 assertSame(r.getSourceMethodName(), null); 1564 assertSame(r.getLevel(), Level.WARNING); 1565 assertNull(r.getParameters()); 1566 assertSame(r.getThrown(), null); 1567 1568 this.sharedLogger.setLevel(Level.SEVERE); 1569 this.sharedLogger.warning("warning again"); 1570 assertTrue(CallVerificationStack.getInstance().empty()); 1571 } 1572 1573 /* 1574 * Test warning(String) with null values. 1575 */ 1576 public void testWarning_Null() { 1577 Logger child = new MockLogger("childLogger", null); 1578 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1579 child.addHandler(new MockHandler()); 1580 child.setParent(parent); 1581 1582 child.setLevel(Level.WARNING); 1583 child.warning(null); 1584 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1585 assertTrue(CallVerificationStack.getInstance().empty()); 1586 assertSame(r.getLoggerName(), child.getName()); 1587 assertNull(r.getMessage()); 1588 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1589 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1590 assertSame(r.getSourceClassName(), null); 1591 assertSame(r.getSourceMethodName(), null); 1592 assertSame(r.getLevel(), Level.WARNING); 1593 assertNull(r.getParameters()); 1594 assertSame(r.getThrown(), null); 1595 1596 this.sharedLogger.setLevel(Level.SEVERE); 1597 this.sharedLogger.warning(null); 1598 assertTrue(CallVerificationStack.getInstance().empty()); 1599 } 1600 1601 /* 1602 * Test severe(String) with normal values. 1603 */ 1604 public void testSevere_Normal() { 1605 this.sharedLogger.setLevel(Level.SEVERE); 1606 this.sharedLogger.severe("severe msg"); 1607 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1608 assertTrue(CallVerificationStack.getInstance().empty()); 1609 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1610 assertEquals(r.getMessage(), "severe msg"); 1611 assertSame(r.getResourceBundleName(), this.sharedLogger 1612 .getResourceBundleName()); 1613 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1614 assertSame(r.getSourceClassName(), null); 1615 assertSame(r.getSourceMethodName(), null); 1616 assertSame(r.getLevel(), Level.SEVERE); 1617 assertNull(r.getParameters()); 1618 assertSame(r.getThrown(), null); 1619 1620 this.sharedLogger.setLevel(Level.OFF); 1621 this.sharedLogger.severe("severe again"); 1622 assertTrue(CallVerificationStack.getInstance().empty()); 1623 } 1624 1625 /* 1626 * Test severe(String) with null values. 1627 */ 1628 public void testSevere_Null() { 1629 Logger child = new MockLogger("childLogger", null); 1630 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1631 child.addHandler(new MockHandler()); 1632 child.setParent(parent); 1633 1634 child.setLevel(Level.SEVERE); 1635 child.severe(null); 1636 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1637 assertTrue(CallVerificationStack.getInstance().empty()); 1638 assertSame(r.getLoggerName(), child.getName()); 1639 assertNull(r.getMessage()); 1640 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1641 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1642 assertSame(r.getSourceClassName(), null); 1643 assertSame(r.getSourceMethodName(), null); 1644 assertSame(r.getLevel(), Level.SEVERE); 1645 assertNull(r.getParameters()); 1646 assertSame(r.getThrown(), null); 1647 1648 this.sharedLogger.setLevel(Level.OFF); 1649 this.sharedLogger.severe(null); 1650 assertTrue(CallVerificationStack.getInstance().empty()); 1651 } 1652 1653 /* 1654 * Test log(Level, String) with normal values. 1655 */ 1656 public void testLog_LevelString_Normal() { 1657 this.sharedLogger.setLevel(Level.INFO); 1658 this.sharedLogger.log(Level.INFO, "log(Level, String) msg"); 1659 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1660 assertTrue(CallVerificationStack.getInstance().empty()); 1661 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1662 assertEquals(r.getMessage(), "log(Level, String) msg"); 1663 assertSame(r.getResourceBundleName(), this.sharedLogger 1664 .getResourceBundleName()); 1665 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1666 assertSame(r.getSourceClassName(), null); 1667 assertSame(r.getSourceMethodName(), null); 1668 assertSame(r.getLevel(), Level.INFO); 1669 assertNull(r.getParameters()); 1670 assertSame(r.getThrown(), null); 1671 1672 this.sharedLogger.log(Level.CONFIG, "log(Level, String) msg"); 1673 assertTrue(CallVerificationStack.getInstance().empty()); 1674 this.sharedLogger.setLevel(Level.OFF); 1675 this.sharedLogger.log(Level.OFF, "log(Level, String) msg"); 1676 assertTrue(CallVerificationStack.getInstance().empty()); 1677 } 1678 1679 /* 1680 * Test log(Level, String) with null message. 1681 */ 1682 public void testLog_LevelString_NullMsg() { 1683 Logger child = new MockLogger("childLogger", null); 1684 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1685 child.addHandler(new MockHandler()); 1686 child.setParent(parent); 1687 1688 child.setLevel(Level.INFO); 1689 child.log(Level.INFO, null); 1690 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1691 assertTrue(CallVerificationStack.getInstance().empty()); 1692 assertSame(r.getLoggerName(), child.getName()); 1693 assertNull(r.getMessage()); 1694 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1695 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1696 assertSame(r.getSourceClassName(), null); 1697 assertSame(r.getSourceMethodName(), null); 1698 assertSame(r.getLevel(), Level.INFO); 1699 assertNull(r.getParameters()); 1700 assertSame(r.getThrown(), null); 1701 } 1702 1703 /* 1704 * Test log(Level, String) with null level. 1705 */ 1706 public void testLog_LevelString_NullLevel() { 1707 // this.sharedLogger.setLevel(Level.OFF); 1708 try { 1709 this.sharedLogger.log(null, "log(Level, String) msg"); 1710 fail("Should throw NullPointerException!"); 1711 } catch (NullPointerException e) { 1712 } 1713 } 1714 1715 /* 1716 * Test log(Level, String, Object) with normal values. 1717 */ 1718 public void testLog_LevelStringObject_Normal() { 1719 Object param = new Object(); 1720 this.sharedLogger.setLevel(Level.INFO); 1721 this.sharedLogger.log(Level.INFO, "log(Level, String, Object) msg", 1722 param); 1723 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1724 assertTrue(CallVerificationStack.getInstance().empty()); 1725 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1726 assertEquals(r.getMessage(), "log(Level, String, Object) msg"); 1727 assertSame(r.getResourceBundleName(), this.sharedLogger 1728 .getResourceBundleName()); 1729 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1730 assertSame(r.getSourceClassName(), null); 1731 assertSame(r.getSourceMethodName(), null); 1732 assertSame(r.getLevel(), Level.INFO); 1733 assertEquals(1, r.getParameters().length); 1734 assertSame(param, r.getParameters()[0]); 1735 assertSame(r.getThrown(), null); 1736 1737 this.sharedLogger.log(Level.CONFIG, "log(Level, String, Object) msg", 1738 param); 1739 assertTrue(CallVerificationStack.getInstance().empty()); 1740 this.sharedLogger.setLevel(Level.OFF); 1741 this.sharedLogger.log(Level.OFF, "log(Level, String, Object) msg", 1742 param); 1743 assertTrue(CallVerificationStack.getInstance().empty()); 1744 } 1745 1746 /* 1747 * Test log(Level, String, Object) with null message and object. 1748 */ 1749 public void testLog_LevelStringObject_NullMsgObj() { 1750 Logger child = new MockLogger("childLogger", null); 1751 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1752 child.addHandler(new MockHandler()); 1753 child.setParent(parent); 1754 1755 child.setLevel(Level.INFO); 1756 child.log(Level.INFO, null, (Object) null); 1757 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1758 assertTrue(CallVerificationStack.getInstance().empty()); 1759 assertSame(r.getLoggerName(), child.getName()); 1760 assertNull(r.getMessage()); 1761 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1762 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1763 assertSame(r.getSourceClassName(), null); 1764 assertSame(r.getSourceMethodName(), null); 1765 assertSame(r.getLevel(), Level.INFO); 1766 assertEquals(1, r.getParameters().length); 1767 assertNull(r.getParameters()[0]); 1768 assertSame(r.getThrown(), null); 1769 } 1770 1771 /* 1772 * Test log(Level, String, Object) with null level. 1773 */ 1774 public void testLog_LevelStringObject_NullLevel() { 1775 // this.sharedLogger.setLevel(Level.OFF); 1776 try { 1777 this.sharedLogger.log(null, "log(Level, String, Object) msg", 1778 new Object()); 1779 fail("Should throw NullPointerException!"); 1780 } catch (NullPointerException e) { 1781 } 1782 } 1783 1784 /* 1785 * Test log(Level, String, Object[]) with normal values. 1786 */ 1787 public void testLog_LevelStringObjects_Normal() { 1788 Object[] params = new Object[2]; 1789 params[0] = new Object(); 1790 params[1] = new Object(); 1791 this.sharedLogger.setLevel(Level.INFO); 1792 this.sharedLogger.log(Level.INFO, "log(Level, String, Object[]) msg", 1793 params); 1794 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1795 assertTrue(CallVerificationStack.getInstance().empty()); 1796 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1797 assertEquals(r.getMessage(), "log(Level, String, Object[]) msg"); 1798 assertSame(r.getResourceBundleName(), this.sharedLogger 1799 .getResourceBundleName()); 1800 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1801 assertSame(r.getSourceClassName(), null); 1802 assertSame(r.getSourceMethodName(), null); 1803 assertSame(r.getLevel(), Level.INFO); 1804 assertEquals(2, r.getParameters().length); 1805 assertSame(params[0], r.getParameters()[0]); 1806 assertSame(params[1], r.getParameters()[1]); 1807 assertSame(r.getThrown(), null); 1808 1809 this.sharedLogger.log(Level.CONFIG, "log(Level, String, Object[]) msg", 1810 params); 1811 assertTrue(CallVerificationStack.getInstance().empty()); 1812 this.sharedLogger.setLevel(Level.OFF); 1813 this.sharedLogger.log(Level.OFF, "log(Level, String, Object[]) msg", 1814 params); 1815 assertTrue(CallVerificationStack.getInstance().empty()); 1816 } 1817 1818 /* 1819 * Test log(Level, String, Object[]) with null message and object. 1820 */ 1821 public void testLog_LevelStringObjects_NullMsgObj() { 1822 Logger child = new MockLogger("childLogger", null); 1823 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1824 child.addHandler(new MockHandler()); 1825 child.setParent(parent); 1826 1827 child.setLevel(Level.INFO); 1828 child.log(Level.INFO, null, (Object[]) null); 1829 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1830 assertTrue(CallVerificationStack.getInstance().empty()); 1831 assertSame(r.getLoggerName(), child.getName()); 1832 assertNull(r.getMessage()); 1833 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1834 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1835 assertSame(r.getSourceClassName(), null); 1836 assertSame(r.getSourceMethodName(), null); 1837 assertSame(r.getLevel(), Level.INFO); 1838 assertNull(r.getParameters()); 1839 assertSame(r.getThrown(), null); 1840 } 1841 1842 /* 1843 * Test log(Level, String, Object[]) with null level. 1844 */ 1845 public void testLog_LevelStringObjects_NullLevel() { 1846 // this.sharedLogger.setLevel(Level.OFF); 1847 try { 1848 this.sharedLogger.log(null, "log(Level, String, Object[]) msg", 1849 new Object[0]); 1850 fail("Should throw NullPointerException!"); 1851 } catch (NullPointerException e) { 1852 } 1853 } 1854 1855 /* 1856 * Test log(Level, String, Throwable) with normal values. 1857 */ 1858 public void testLog_LevelStringThrowable_Normal() { 1859 Throwable t = new Throwable(); 1860 this.sharedLogger.setLevel(Level.INFO); 1861 this.sharedLogger.log(Level.INFO, "log(Level, String, Throwable) msg", 1862 t); 1863 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1864 assertTrue(CallVerificationStack.getInstance().empty()); 1865 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1866 assertEquals(r.getMessage(), "log(Level, String, Throwable) msg"); 1867 assertSame(r.getResourceBundleName(), this.sharedLogger 1868 .getResourceBundleName()); 1869 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1870 assertSame(r.getSourceClassName(), null); 1871 assertSame(r.getSourceMethodName(), null); 1872 assertSame(r.getLevel(), Level.INFO); 1873 assertNull(r.getParameters()); 1874 assertSame(r.getThrown(), t); 1875 1876 this.sharedLogger.log(Level.CONFIG, 1877 "log(Level, String, Throwable) msg", t); 1878 assertTrue(CallVerificationStack.getInstance().empty()); 1879 this.sharedLogger.setLevel(Level.OFF); 1880 this.sharedLogger 1881 .log(Level.OFF, "log(Level, String, Throwable) msg", t); 1882 assertTrue(CallVerificationStack.getInstance().empty()); 1883 } 1884 1885 /* 1886 * Test log(Level, String, Throwable) with null message and throwable. 1887 */ 1888 public void testLog_LevelStringThrowable_Null() { 1889 Logger child = new MockLogger("childLogger", null); 1890 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1891 child.addHandler(new MockHandler()); 1892 child.setParent(parent); 1893 1894 child.setLevel(Level.INFO); 1895 child.log(Level.INFO, null, (Throwable) null); 1896 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1897 assertTrue(CallVerificationStack.getInstance().empty()); 1898 assertSame(r.getLoggerName(), child.getName()); 1899 assertNull(r.getMessage()); 1900 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1901 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1902 assertSame(r.getSourceClassName(), null); 1903 assertSame(r.getSourceMethodName(), null); 1904 assertSame(r.getLevel(), Level.INFO); 1905 assertNull(r.getParameters()); 1906 assertSame(r.getThrown(), null); 1907 } 1908 1909 /* 1910 * Test log(Level, String, Throwable) with null level. 1911 */ 1912 public void testLog_LevelStringThrowable_NullLevel() { 1913 // this.sharedLogger.setLevel(Level.OFF); 1914 try { 1915 this.sharedLogger.log(null, "log(Level, String, Throwable) msg", 1916 new Throwable()); 1917 fail("Should throw NullPointerException!"); 1918 } catch (NullPointerException e) { 1919 } 1920 } 1921 1922 /* 1923 * Test logp(Level, String, String, String) with normal values. 1924 */ 1925 public void testLogp_LevelStringStringString_Normal() { 1926 this.sharedLogger.setLevel(Level.INFO); 1927 this.sharedLogger.logp(Level.INFO, "sourceClass", "sourceMethod", 1928 "logp(Level, String, String, String) msg"); 1929 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1930 assertTrue(CallVerificationStack.getInstance().empty()); 1931 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1932 assertEquals(r.getMessage(), "logp(Level, String, String, String) msg"); 1933 assertSame(r.getResourceBundleName(), this.sharedLogger 1934 .getResourceBundleName()); 1935 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 1936 assertSame(r.getSourceClassName(), "sourceClass"); 1937 assertSame(r.getSourceMethodName(), "sourceMethod"); 1938 assertSame(r.getLevel(), Level.INFO); 1939 assertNull(r.getParameters()); 1940 assertSame(r.getThrown(), null); 1941 1942 this.sharedLogger.logp(Level.CONFIG, "sourceClass", "sourceMethod", 1943 "logp(Level, String, String, String) msg"); 1944 assertTrue(CallVerificationStack.getInstance().empty()); 1945 this.sharedLogger.setLevel(Level.OFF); 1946 this.sharedLogger.logp(Level.OFF, "sourceClass", "sourceMethod", 1947 "logp(Level, String, String, String) msg"); 1948 assertTrue(CallVerificationStack.getInstance().empty()); 1949 } 1950 1951 /* 1952 * Test logp(Level, String, String, String) with null message. 1953 */ 1954 public void testLogp_LevelStringStringString_NullMsg() { 1955 Logger child = new MockLogger("childLogger", null); 1956 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 1957 child.addHandler(new MockHandler()); 1958 child.setParent(parent); 1959 1960 child.setLevel(Level.INFO); 1961 child.logp(Level.INFO, null, null, null); 1962 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1963 assertTrue(CallVerificationStack.getInstance().empty()); 1964 assertSame(r.getLoggerName(), child.getName()); 1965 assertNull(r.getMessage()); 1966 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 1967 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 1968 assertSame(r.getSourceClassName(), null); 1969 assertSame(r.getSourceMethodName(), null); 1970 assertSame(r.getLevel(), Level.INFO); 1971 assertNull(r.getParameters()); 1972 assertSame(r.getThrown(), null); 1973 } 1974 1975 /* 1976 * Test logp(Level, String, String, String) with null level. 1977 */ 1978 public void testLogp_LevelStringStringString_NullLevel() { 1979 // this.sharedLogger.setLevel(Level.OFF); 1980 try { 1981 this.sharedLogger.logp(null, "sourceClass", "sourceMethod", 1982 "logp(Level, String, String, String) msg"); 1983 fail("Should throw NullPointerException!"); 1984 } catch (NullPointerException e) { 1985 } 1986 } 1987 1988 /* 1989 * Test logp(Level, String, String, String, Object) with normal values. 1990 */ 1991 public void testLogp_LevelStringStringStringObject_Normal() { 1992 Object param = new Object(); 1993 this.sharedLogger.setLevel(Level.INFO); 1994 this.sharedLogger.logp(Level.INFO, "sourceClass", "sourceMethod", 1995 "logp(Level, String, String, String, Object) msg", param); 1996 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 1997 assertTrue(CallVerificationStack.getInstance().empty()); 1998 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 1999 assertEquals(r.getMessage(), 2000 "logp(Level, String, String, String, Object) msg"); 2001 assertSame(r.getResourceBundleName(), this.sharedLogger 2002 .getResourceBundleName()); 2003 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 2004 assertSame(r.getSourceClassName(), "sourceClass"); 2005 assertSame(r.getSourceMethodName(), "sourceMethod"); 2006 assertSame(r.getLevel(), Level.INFO); 2007 assertEquals(1, r.getParameters().length); 2008 assertSame(param, r.getParameters()[0]); 2009 assertSame(r.getThrown(), null); 2010 2011 this.sharedLogger.logp(Level.CONFIG, "sourceClass", "sourceMethod", 2012 "logp(Level, String, String, String, Object) msg", param); 2013 assertTrue(CallVerificationStack.getInstance().empty()); 2014 this.sharedLogger.setLevel(Level.OFF); 2015 this.sharedLogger.logp(Level.OFF, "sourceClass", "sourceMethod", 2016 "logp(Level, String, String, String, Object) msg", param); 2017 assertTrue(CallVerificationStack.getInstance().empty()); 2018 } 2019 2020 /* 2021 * Test logp(Level, String, String, String, Object) with null message and 2022 * object. 2023 */ 2024 public void testLogp_LevelStringStringStringObject_NullMsgObj() { 2025 Logger child = new MockLogger("childLogger", null); 2026 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 2027 child.addHandler(new MockHandler()); 2028 child.setParent(parent); 2029 2030 child.setLevel(Level.INFO); 2031 child.logp(Level.INFO, null, null, null, (Object) null); 2032 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2033 assertTrue(CallVerificationStack.getInstance().empty()); 2034 assertSame(r.getLoggerName(), child.getName()); 2035 assertNull(r.getMessage()); 2036 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 2037 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 2038 assertSame(r.getSourceClassName(), null); 2039 assertSame(r.getSourceMethodName(), null); 2040 assertSame(r.getLevel(), Level.INFO); 2041 assertEquals(1, r.getParameters().length); 2042 assertNull(r.getParameters()[0]); 2043 assertSame(r.getThrown(), null); 2044 } 2045 2046 /* 2047 * Test logp(Level, String, String, String, Object) with null level. 2048 */ 2049 public void testLogp_LevelStringStringStringObject_NullLevel() { 2050 // this.sharedLogger.setLevel(Level.OFF); 2051 try { 2052 this.sharedLogger.logp(null, "sourceClass", "sourceMethod", 2053 "logp(Level, String, String, String, Object) msg", 2054 new Object()); 2055 fail("Should throw NullPointerException!"); 2056 } catch (NullPointerException e) { 2057 } 2058 } 2059 2060 /* 2061 * Test logp(Level, String, String, String, Object[]) with normal values. 2062 */ 2063 public void testLogp_LevelStringStringStringObjects_Normal() { 2064 Object[] params = new Object[2]; 2065 params[0] = new Object(); 2066 params[1] = new Object(); 2067 this.sharedLogger.setLevel(Level.INFO); 2068 this.sharedLogger.logp(Level.INFO, "sourceClass", "sourceMethod", 2069 "logp(Level, String, String, String, Object[]) msg", params); 2070 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2071 assertTrue(CallVerificationStack.getInstance().empty()); 2072 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2073 assertEquals(r.getMessage(), 2074 "logp(Level, String, String, String, Object[]) msg"); 2075 assertSame(r.getResourceBundleName(), this.sharedLogger 2076 .getResourceBundleName()); 2077 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 2078 assertSame(r.getSourceClassName(), "sourceClass"); 2079 assertSame(r.getSourceMethodName(), "sourceMethod"); 2080 assertSame(r.getLevel(), Level.INFO); 2081 assertEquals(2, r.getParameters().length); 2082 assertSame(params[0], r.getParameters()[0]); 2083 assertSame(params[1], r.getParameters()[1]); 2084 assertSame(r.getThrown(), null); 2085 2086 this.sharedLogger.logp(Level.CONFIG, "sourceClass", "sourceMethod", 2087 "logp(Level, String, String, String, Object[]) msg", params); 2088 assertTrue(CallVerificationStack.getInstance().empty()); 2089 this.sharedLogger.setLevel(Level.OFF); 2090 this.sharedLogger.logp(Level.OFF, "sourceClass", "sourceMethod", 2091 "logp(Level, String, String, String, Object[]) msg", params); 2092 assertTrue(CallVerificationStack.getInstance().empty()); 2093 } 2094 2095 /* 2096 * Test logp(Level, String, String, String, Object[]) with null message and 2097 * object. 2098 */ 2099 public void testLogp_LevelStringStringStringObjects_NullMsgObj() { 2100 Logger child = new MockLogger("childLogger", null); 2101 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 2102 child.addHandler(new MockHandler()); 2103 child.setParent(parent); 2104 2105 child.setLevel(Level.INFO); 2106 child.logp(Level.INFO, null, null, null, (Object[]) null); 2107 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2108 assertTrue(CallVerificationStack.getInstance().empty()); 2109 assertSame(r.getLoggerName(), child.getName()); 2110 assertNull(r.getMessage()); 2111 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 2112 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 2113 assertSame(r.getSourceClassName(), null); 2114 assertSame(r.getSourceMethodName(), null); 2115 assertSame(r.getLevel(), Level.INFO); 2116 assertNull(r.getParameters()); 2117 assertSame(r.getThrown(), null); 2118 } 2119 2120 /* 2121 * Test logp(Level, String, String, String, Object[]) with null level. 2122 */ 2123 public void testLogp_LevelStringStringStringObjects_NullLevel() { 2124 // this.sharedLogger.setLevel(Level.OFF); 2125 try { 2126 this.sharedLogger.logp(null, "sourceClass", "sourceMethod", 2127 "logp(Level, String, String, String, Object[]) msg", 2128 new Object[0]); 2129 fail("Should throw NullPointerException!"); 2130 } catch (NullPointerException e) { 2131 } 2132 } 2133 2134 /* 2135 * Test logp(Level, String, String, String, Throwable) with normal values. 2136 */ 2137 public void testLogp_LevelStringStringStringThrowable_Normal() { 2138 Throwable t = new Throwable(); 2139 this.sharedLogger.setLevel(Level.INFO); 2140 this.sharedLogger.logp(Level.INFO, "sourceClass", "sourceMethod", 2141 "logp(Level, String, String, String, Throwable) msg", t); 2142 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2143 assertTrue(CallVerificationStack.getInstance().empty()); 2144 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2145 assertEquals(r.getMessage(), 2146 "logp(Level, String, String, String, Throwable) msg"); 2147 assertSame(r.getResourceBundleName(), this.sharedLogger 2148 .getResourceBundleName()); 2149 assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle()); 2150 assertSame(r.getSourceClassName(), "sourceClass"); 2151 assertSame(r.getSourceMethodName(), "sourceMethod"); 2152 assertSame(r.getLevel(), Level.INFO); 2153 assertNull(r.getParameters()); 2154 assertSame(r.getThrown(), t); 2155 2156 this.sharedLogger.logp(Level.CONFIG, "sourceClass", "sourceMethod", 2157 "logp(Level, String, String, String, Throwable) msg", t); 2158 assertTrue(CallVerificationStack.getInstance().empty()); 2159 this.sharedLogger.setLevel(Level.OFF); 2160 this.sharedLogger.logp(Level.OFF, "sourceClass", "sourceMethod", 2161 "logp(Level, String, String, String, Throwable) msg", t); 2162 assertTrue(CallVerificationStack.getInstance().empty()); 2163 } 2164 2165 /* 2166 * Test logp(Level, String, String, String, Throwable) with null message and 2167 * throwable. 2168 */ 2169 public void testLogp_LevelStringTStringStringhrowable_Null() { 2170 Logger child = new MockLogger("childLogger", null); 2171 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 2172 child.addHandler(new MockHandler()); 2173 child.setParent(parent); 2174 2175 child.setLevel(Level.INFO); 2176 child.logp(Level.INFO, null, null, null, (Throwable) null); 2177 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2178 assertTrue(CallVerificationStack.getInstance().empty()); 2179 assertSame(r.getLoggerName(), child.getName()); 2180 assertNull(r.getMessage()); 2181 assertSame(r.getResourceBundleName(), parent.getResourceBundleName()); 2182 assertSame(r.getResourceBundle(), parent.getResourceBundle()); 2183 assertSame(r.getSourceClassName(), null); 2184 assertSame(r.getSourceMethodName(), null); 2185 assertSame(r.getLevel(), Level.INFO); 2186 assertNull(r.getParameters()); 2187 assertSame(r.getThrown(), null); 2188 } 2189 2190 /* 2191 * Test logp(Level, String, String, String, Throwable) with null level. 2192 */ 2193 public void testLogp_LevelStringStringStringThrowable_NullLevel() { 2194 // this.sharedLogger.setLevel(Level.OFF); 2195 try { 2196 this.sharedLogger.logp(null, "sourceClass", "sourceMethod", 2197 "log(Level, String, String, String, Throwable) msg", 2198 new Throwable()); 2199 fail("Should throw NullPointerException!"); 2200 } catch (NullPointerException e) { 2201 } 2202 } 2203 2204 /* 2205 * Test logrb(Level, String, String, String, String) with normal values. 2206 */ 2207 public void testLogrb_LevelStringStringString_Normal() { 2208 this.sharedLogger.setLevel(Level.INFO); 2209 this.sharedLogger.logrb(Level.INFO, "sourceClass", "sourceMethod", 2210 VALID_RESOURCE_BUNDLE2, 2211 "logrb(Level, String, String, String, String) msg"); 2212 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2213 assertTrue(CallVerificationStack.getInstance().empty()); 2214 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2215 assertEquals(r.getMessage(), 2216 "logrb(Level, String, String, String, String) msg"); 2217 assertSame(r.getResourceBundleName(), VALID_RESOURCE_BUNDLE2); 2218 assertEquals(VALID_VALUE2, r.getResourceBundle().getString(VALID_KEY)); 2219 assertSame(r.getSourceClassName(), "sourceClass"); 2220 assertSame(r.getSourceMethodName(), "sourceMethod"); 2221 assertSame(r.getLevel(), Level.INFO); 2222 assertNull(r.getParameters()); 2223 assertSame(r.getThrown(), null); 2224 2225 this.sharedLogger.logrb(Level.CONFIG, "sourceClass", "sourceMethod", 2226 VALID_RESOURCE_BUNDLE2, 2227 "logrb(Level, String, String, String, String) msg"); 2228 assertTrue(CallVerificationStack.getInstance().empty()); 2229 this.sharedLogger.setLevel(Level.OFF); 2230 this.sharedLogger.logrb(Level.OFF, "sourceClass", "sourceMethod", 2231 VALID_RESOURCE_BUNDLE2, 2232 "logrb(Level, String, String, String, String) msg"); 2233 assertTrue(CallVerificationStack.getInstance().empty()); 2234 } 2235 2236 /* 2237 * Test logrb(Level, String, String, String, String) with null message. 2238 */ 2239 public void testLogrb_LevelStringStringString_NullMsg() { 2240 this.sharedLogger.setLevel(Level.INFO); 2241 this.sharedLogger.logrb(Level.INFO, null, null, null, null); 2242 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2243 assertTrue(CallVerificationStack.getInstance().empty()); 2244 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2245 assertNull(r.getMessage()); 2246 assertSame(r.getResourceBundleName(), null); 2247 assertSame(r.getSourceClassName(), null); 2248 assertSame(r.getSourceMethodName(), null); 2249 assertSame(r.getLevel(), Level.INFO); 2250 assertNull(r.getParameters()); 2251 assertSame(r.getThrown(), null); 2252 } 2253 2254 /* 2255 * Test logrb(Level, String, String, String) with null level. 2256 */ 2257 public void testLogrb_LevelStringStringString_NullLevel() { 2258 // this.sharedLogger.setLevel(Level.OFF); 2259 try { 2260 this.sharedLogger.logrb(null, "sourceClass", "sourceMethod", 2261 VALID_RESOURCE_BUNDLE2, 2262 "logrb(Level, String, String, String, String) msg"); 2263 fail("Should throw NullPointerException!"); 2264 } catch (NullPointerException e) { 2265 } 2266 } 2267 2268 /* 2269 * Test logrb(Level, String, String, String, String) with invalid resource 2270 * bundle. 2271 */ 2272 public void testLogrb_LevelStringStringString_InvalidRes() { 2273 this.sharedLogger.setLevel(Level.ALL); 2274 this.sharedLogger.logrb(Level.ALL, "sourceClass", "sourceMethod", 2275 INVALID_RESOURCE_BUNDLE, 2276 "logrb(Level, String, String, String, String) msg"); 2277 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2278 assertTrue(CallVerificationStack.getInstance().empty()); 2279 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2280 assertEquals(r.getMessage(), 2281 "logrb(Level, String, String, String, String) msg"); 2282 assertSame(r.getResourceBundleName(), INVALID_RESOURCE_BUNDLE); 2283 assertSame(r.getResourceBundle(), null); 2284 assertSame(r.getSourceClassName(), "sourceClass"); 2285 assertSame(r.getSourceMethodName(), "sourceMethod"); 2286 assertSame(r.getLevel(), Level.ALL); 2287 assertNull(r.getParameters()); 2288 assertSame(r.getThrown(), null); 2289 } 2290 2291 /* 2292 * Test logrb(Level, String, String, String, String, Object) with normal 2293 * values. 2294 */ 2295 public void testLogrb_LevelStringStringStringObject_Normal() { 2296 Object param = new Object(); 2297 this.sharedLogger.setLevel(Level.INFO); 2298 this.sharedLogger.logrb(Level.INFO, "sourceClass", "sourceMethod", 2299 VALID_RESOURCE_BUNDLE2, 2300 "logrb(Level, String, String, String, String, Object) msg", 2301 param); 2302 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2303 assertTrue(CallVerificationStack.getInstance().empty()); 2304 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2305 assertEquals(r.getMessage(), 2306 "logrb(Level, String, String, String, String, Object) msg"); 2307 assertSame(r.getResourceBundleName(), VALID_RESOURCE_BUNDLE2); 2308 assertSame(r.getSourceClassName(), "sourceClass"); 2309 assertSame(r.getSourceMethodName(), "sourceMethod"); 2310 assertSame(r.getLevel(), Level.INFO); 2311 assertEquals(1, r.getParameters().length); 2312 assertSame(param, r.getParameters()[0]); 2313 assertSame(r.getThrown(), null); 2314 2315 this.sharedLogger.logrb(Level.CONFIG, "sourceClass", "sourceMethod", 2316 VALID_RESOURCE_BUNDLE2, 2317 "logrb(Level, String, String, String, String, Object) msg", 2318 param); 2319 assertTrue(CallVerificationStack.getInstance().empty()); 2320 this.sharedLogger.setLevel(Level.OFF); 2321 this.sharedLogger.logrb(Level.OFF, "sourceClass", "sourceMethod", 2322 VALID_RESOURCE_BUNDLE2, 2323 "logrb(Level, String, String, String, String, Object) msg", 2324 param); 2325 assertTrue(CallVerificationStack.getInstance().empty()); 2326 } 2327 2328 /* 2329 * Test logrb(Level, String, String, String, String, Object) with null 2330 * message and object. 2331 */ 2332 public void testLogrb_LevelStringStringStringObject_NullMsgObj() { 2333 this.sharedLogger.setLevel(Level.INFO); 2334 this.sharedLogger.logrb(Level.INFO, null, null, null, null, 2335 (Object) null); 2336 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2337 assertTrue(CallVerificationStack.getInstance().empty()); 2338 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2339 assertNull(r.getMessage()); 2340 assertSame(r.getResourceBundleName(), null); 2341 assertSame(r.getSourceClassName(), null); 2342 assertSame(r.getSourceMethodName(), null); 2343 assertSame(r.getLevel(), Level.INFO); 2344 assertEquals(1, r.getParameters().length); 2345 assertNull(r.getParameters()[0]); 2346 assertSame(r.getThrown(), null); 2347 } 2348 2349 /* 2350 * Test logrb(Level, String, String, String, String, Object) with null 2351 * level. 2352 */ 2353 public void testLogrb_LevelStringStringStringObject_NullLevel() { 2354 // this.sharedLogger.setLevel(Level.OFF); 2355 try { 2356 this.sharedLogger.logrb(null, "sourceClass", "sourceMethod", 2357 VALID_RESOURCE_BUNDLE2, 2358 "logrb(Level, String, String, String, String, Object) msg", 2359 new Object()); 2360 fail("Should throw NullPointerException!"); 2361 } catch (NullPointerException e) { 2362 } 2363 } 2364 2365 /* 2366 * Test logrb(Level, String, String, String, String, Object) with invalid 2367 * resource bundle. 2368 */ 2369 public void testLogrb_LevelStringStringStringObject_InvalidRes() { 2370 Object param = new Object(); 2371 this.sharedLogger.setLevel(Level.ALL); 2372 this.sharedLogger.logrb(Level.ALL, "sourceClass", "sourceMethod", 2373 INVALID_RESOURCE_BUNDLE, 2374 "logrb(Level, String, String, String, String) msg", param); 2375 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2376 assertTrue(CallVerificationStack.getInstance().empty()); 2377 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2378 assertEquals(r.getMessage(), 2379 "logrb(Level, String, String, String, String) msg"); 2380 assertSame(r.getResourceBundleName(), INVALID_RESOURCE_BUNDLE); 2381 assertSame(r.getResourceBundle(), null); 2382 assertSame(r.getSourceClassName(), "sourceClass"); 2383 assertSame(r.getSourceMethodName(), "sourceMethod"); 2384 assertSame(r.getLevel(), Level.ALL); 2385 assertEquals(1, r.getParameters().length); 2386 assertSame(param, r.getParameters()[0]); 2387 assertSame(r.getThrown(), null); 2388 } 2389 2390 /* 2391 * Test logrb(Level, String, String, String, String, Object[]) with normal 2392 * values. 2393 */ 2394 public void testLogrb_LevelStringStringStringObjects_Normal() { 2395 Object[] params = new Object[2]; 2396 params[0] = new Object(); 2397 params[1] = new Object(); 2398 this.sharedLogger.setLevel(Level.INFO); 2399 this.sharedLogger.logrb(Level.INFO, "sourceClass", "sourceMethod", 2400 VALID_RESOURCE_BUNDLE2, 2401 "logrb(Level, String, String, String, String, Object[]) msg", 2402 params); 2403 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2404 assertTrue(CallVerificationStack.getInstance().empty()); 2405 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2406 assertEquals(r.getMessage(), 2407 "logrb(Level, String, String, String, String, Object[]) msg"); 2408 assertSame(r.getResourceBundleName(), VALID_RESOURCE_BUNDLE2); 2409 assertSame(r.getSourceClassName(), "sourceClass"); 2410 assertSame(r.getSourceMethodName(), "sourceMethod"); 2411 assertSame(r.getLevel(), Level.INFO); 2412 assertEquals(2, r.getParameters().length); 2413 assertSame(params[0], r.getParameters()[0]); 2414 assertSame(params[1], r.getParameters()[1]); 2415 assertSame(r.getThrown(), null); 2416 2417 this.sharedLogger.logrb(Level.CONFIG, "sourceClass", "sourceMethod", 2418 VALID_RESOURCE_BUNDLE2, 2419 "logrb(Level, String, String, String, String, Object[]) msg", 2420 params); 2421 assertTrue(CallVerificationStack.getInstance().empty()); 2422 this.sharedLogger.setLevel(Level.OFF); 2423 this.sharedLogger.logrb(Level.OFF, "sourceClass", "sourceMethod", 2424 VALID_RESOURCE_BUNDLE2, 2425 "logrb(Level, String, String, String, String, Object[]) msg", 2426 params); 2427 assertTrue(CallVerificationStack.getInstance().empty()); 2428 } 2429 2430 /* 2431 * Test logrb(Level, String, String, String, String, Object[]) with null 2432 * message and object. 2433 */ 2434 public void testLogrb_LevelStringStringStringObjects_NullMsgObj() { 2435 this.sharedLogger.setLevel(Level.INFO); 2436 this.sharedLogger.logrb(Level.INFO, null, null, null, null, 2437 (Object[]) null); 2438 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2439 assertTrue(CallVerificationStack.getInstance().empty()); 2440 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2441 assertNull(r.getMessage()); 2442 assertSame(r.getResourceBundleName(), null); 2443 assertSame(r.getSourceClassName(), null); 2444 assertSame(r.getSourceMethodName(), null); 2445 assertSame(r.getLevel(), Level.INFO); 2446 assertNull(r.getParameters()); 2447 assertSame(r.getThrown(), null); 2448 } 2449 2450 /* 2451 * Test logrb(Level, String, String, String, String, Object[]) with null 2452 * level. 2453 */ 2454 public void testLogrb_LevelStringStringStringObjects_NullLevel() { 2455 // this.sharedLogger.setLevel(Level.OFF); 2456 try { 2457 this.sharedLogger 2458 .logrb( 2459 null, 2460 "sourceClass", 2461 "sourceMethod", 2462 VALID_RESOURCE_BUNDLE2, 2463 "logrb(Level, String, String, String, String, Object[]) msg", 2464 new Object[0]); 2465 fail("Should throw NullPointerException!"); 2466 } catch (NullPointerException e) { 2467 } 2468 } 2469 2470 /* 2471 * Test logrb(Level, String, String, String, String, Object[]) with invalid 2472 * resource bundle. 2473 */ 2474 public void testLogrb_LevelStringStringStringObjects_InvalidRes() { 2475 Object[] params = new Object[2]; 2476 params[0] = new Object(); 2477 params[1] = new Object(); 2478 this.sharedLogger.setLevel(Level.ALL); 2479 this.sharedLogger.logrb(Level.ALL, "sourceClass", "sourceMethod", 2480 INVALID_RESOURCE_BUNDLE, 2481 "logrb(Level, String, String, String, String) msg", params); 2482 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2483 assertTrue(CallVerificationStack.getInstance().empty()); 2484 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2485 assertEquals(r.getMessage(), 2486 "logrb(Level, String, String, String, String) msg"); 2487 assertSame(r.getResourceBundleName(), INVALID_RESOURCE_BUNDLE); 2488 assertSame(r.getResourceBundle(), null); 2489 assertSame(r.getSourceClassName(), "sourceClass"); 2490 assertSame(r.getSourceMethodName(), "sourceMethod"); 2491 assertSame(r.getLevel(), Level.ALL); 2492 assertEquals(2, r.getParameters().length); 2493 assertSame(params[0], r.getParameters()[0]); 2494 assertSame(params[1], r.getParameters()[1]); 2495 assertSame(r.getThrown(), null); 2496 } 2497 2498 /* 2499 * Test logrb(Level, String, String, String, String, Throwable) with normal 2500 * values. 2501 */ 2502 public void testLogrb_LevelStringStringStringThrowable_Normal() { 2503 Throwable t = new Throwable(); 2504 this.sharedLogger.setLevel(Level.INFO); 2505 this.sharedLogger.logrb(Level.parse("1611"), "sourceClass", 2506 "sourceMethod", VALID_RESOURCE_BUNDLE2, 2507 "logrb(Level, String, String, String, String, Throwable) msg", 2508 t); 2509 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2510 assertTrue(CallVerificationStack.getInstance().empty()); 2511 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2512 assertEquals(r.getMessage(), 2513 "logrb(Level, String, String, String, String, Throwable) msg"); 2514 assertSame(r.getResourceBundleName(), VALID_RESOURCE_BUNDLE2); 2515 assertSame(r.getSourceClassName(), "sourceClass"); 2516 assertSame(r.getSourceMethodName(), "sourceMethod"); 2517 assertSame(r.getLevel(), Level.parse("1611")); 2518 assertNull(r.getParameters()); 2519 assertSame(r.getThrown(), t); 2520 assertNull(Level.parse("1611").getResourceBundleName()); 2521 2522 this.sharedLogger.logrb(Level.CONFIG, "sourceClass", "sourceMethod", 2523 VALID_RESOURCE_BUNDLE2, 2524 "logrb(Level, String, String, String, String, Throwable) msg", 2525 t); 2526 assertTrue(CallVerificationStack.getInstance().empty()); 2527 this.sharedLogger.setLevel(Level.OFF); 2528 this.sharedLogger.logrb(Level.OFF, "sourceClass", "sourceMethod", 2529 VALID_RESOURCE_BUNDLE2, 2530 "logrb(Level, String, String, String, String, Throwable) msg", 2531 t); 2532 assertTrue(CallVerificationStack.getInstance().empty()); 2533 } 2534 2535 /* 2536 * Test logrb(Level, String, String, String, String, Throwable) with null 2537 * message and throwable. 2538 */ 2539 public void testLogrb_LevelStringTStringStringhrowable_NullMsgObj() { 2540 this.sharedLogger.setLevel(Level.INFO); 2541 this.sharedLogger.logrb(Level.INFO, null, null, null, null, 2542 (Throwable) null); 2543 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2544 assertTrue(CallVerificationStack.getInstance().empty()); 2545 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2546 assertNull(r.getMessage()); 2547 assertSame(r.getResourceBundleName(), null); 2548 assertSame(r.getSourceClassName(), null); 2549 assertSame(r.getSourceMethodName(), null); 2550 assertSame(r.getLevel(), Level.INFO); 2551 assertNull(r.getParameters()); 2552 assertSame(r.getThrown(), null); 2553 } 2554 2555 /* 2556 * Test logrb(Level, String, String, String, String, Throwable) with null 2557 * level. 2558 */ 2559 public void testLogrb_LevelStringStringStringThrowable_NullLevel() { 2560 // this.sharedLogger.setLevel(Level.OFF); 2561 try { 2562 this.sharedLogger 2563 .logrb( 2564 null, 2565 "sourceClass", 2566 "sourceMethod", 2567 VALID_RESOURCE_BUNDLE2, 2568 "log(Level, String, String, String, String, Throwable) msg", 2569 new Throwable()); 2570 fail("Should throw NullPointerException!"); 2571 } catch (NullPointerException e) { 2572 } 2573 } 2574 2575 /* 2576 * Test logrb(Level, String, String, String, String, Throwable) with invalid 2577 * resource bundle. 2578 */ 2579 public void testLogrb_LevelStringStringStringThrowable_InvalidRes() { 2580 Throwable t = new Throwable(); 2581 this.sharedLogger.setLevel(Level.ALL); 2582 this.sharedLogger.logrb(Level.ALL, "sourceClass", "sourceMethod", 2583 INVALID_RESOURCE_BUNDLE, 2584 "logrb(Level, String, String, String, String) msg", t); 2585 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2586 assertTrue(CallVerificationStack.getInstance().empty()); 2587 assertSame(r.getLoggerName(), this.sharedLogger.getName()); 2588 assertEquals(r.getMessage(), 2589 "logrb(Level, String, String, String, String) msg"); 2590 assertSame(r.getResourceBundleName(), INVALID_RESOURCE_BUNDLE); 2591 assertSame(r.getResourceBundle(), null); 2592 assertSame(r.getSourceClassName(), "sourceClass"); 2593 assertSame(r.getSourceMethodName(), "sourceMethod"); 2594 assertSame(r.getLevel(), Level.ALL); 2595 assertNull(r.getParameters()); 2596 assertSame(r.getThrown(), t); 2597 } 2598 2599 /* 2600 * Test log(LogRecord) for a normal log record. Meanwhile the logger has an 2601 * appropriate level, no filter, no parent. 2602 */ 2603 public void testLog_LogRecord_AppropriateLevelNoFilterNoParent() { 2604 LogRecord r = new LogRecord(Level.INFO, 2605 "testLog_LogRecord_AppropriateLevelNoFilterNoParent"); 2606 2607 this.sharedLogger.setLevel(Level.INFO); 2608 this.sharedLogger.log(r); 2609 2610 assertSame(r, CallVerificationStack.getInstance().pop()); 2611 assertTrue(CallVerificationStack.getInstance().empty()); 2612 assertSame(r.getLoggerName(), null); 2613 assertEquals(r.getMessage(), 2614 "testLog_LogRecord_AppropriateLevelNoFilterNoParent"); 2615 assertSame(r.getResourceBundleName(), null); 2616 assertSame(r.getSourceClassName(), null); 2617 assertSame(r.getSourceMethodName(), null); 2618 assertSame(r.getLevel(), Level.INFO); 2619 assertNull(r.getParameters()); 2620 assertSame(r.getThrown(), null); 2621 } 2622 2623 /* 2624 * Test log(LogRecord) with null log record. 2625 */ 2626 public void testLog_LogRecord_Null() { 2627 this.sharedLogger.setLevel(Level.INFO); 2628 try { 2629 this.sharedLogger.log(null); 2630 fail("Should throw NullPointerException!"); 2631 } catch (NullPointerException e) { 2632 } 2633 } 2634 2635 /* 2636 * Test log(LogRecord) for a normal log record. Meanwhile the logger has an 2637 * inappropriate level, no filter, no parent. 2638 */ 2639 public void testLog_LogRecord_InppropriateLevelNoFilterNoParent() { 2640 LogRecord r = new LogRecord(Level.INFO, 2641 "testLog_LogRecord_InppropriateLevelNoFilterNoParent"); 2642 2643 this.sharedLogger.setLevel(Level.WARNING); 2644 this.sharedLogger.log(r); 2645 assertTrue(CallVerificationStack.getInstance().empty()); 2646 2647 r.setLevel(Level.OFF); 2648 this.sharedLogger.setLevel(Level.OFF); 2649 this.sharedLogger.log(r); 2650 assertTrue(CallVerificationStack.getInstance().empty()); 2651 } 2652 2653 /* 2654 * Test log(LogRecord) for a normal log record. Meanwhile the logger has an 2655 * appropriate level, a filter that accepts the fed log record, no parent. 2656 */ 2657 public void testLog_LogRecord_AppropriateLevelTrueFilterNoParent() { 2658 LogRecord r = new LogRecord(Level.INFO, 2659 "testLog_LogRecord_AppropriateLevelTrueFilterNoParent"); 2660 2661 this.sharedLogger.setLevel(Level.INFO); 2662 this.sharedLogger.setFilter(new MockTrueFilter()); 2663 this.sharedLogger.log(r); 2664 2665 // pop twice, one pushed by mock handler, one by true mock filter 2666 assertSame(r, CallVerificationStack.getInstance().pop()); 2667 assertSame(r, CallVerificationStack.getInstance().pop()); 2668 assertTrue(CallVerificationStack.getInstance().empty()); 2669 2670 assertSame(r.getLoggerName(), null); 2671 assertEquals(r.getMessage(), 2672 "testLog_LogRecord_AppropriateLevelTrueFilterNoParent"); 2673 assertSame(r.getResourceBundleName(), null); 2674 assertSame(r.getSourceClassName(), null); 2675 assertSame(r.getSourceMethodName(), null); 2676 assertSame(r.getLevel(), Level.INFO); 2677 assertNull(r.getParameters()); 2678 assertSame(r.getThrown(), null); 2679 } 2680 2681 /* 2682 * Test log(LogRecord) for a normal log record. Meanwhile the logger has an 2683 * appropriate level, a filter that rejects the fed log record, no parent. 2684 */ 2685 public void testLog_LogRecord_AppropriateLevelFalseFilterNoParent() { 2686 LogRecord r = new LogRecord(Level.INFO, 2687 "testLog_LogRecord_AppropriateLevelFalseFilterNoParent"); 2688 2689 this.sharedLogger.setLevel(Level.INFO); 2690 this.sharedLogger.setFilter(new MockFilter()); 2691 this.sharedLogger.log(r); 2692 2693 // pop only once, pushed by mock filter 2694 assertSame(r, CallVerificationStack.getInstance().pop()); 2695 assertTrue(CallVerificationStack.getInstance().empty()); 2696 2697 assertSame(r.getLoggerName(), null); 2698 assertEquals(r.getMessage(), 2699 "testLog_LogRecord_AppropriateLevelFalseFilterNoParent"); 2700 assertSame(r.getResourceBundleName(), null); 2701 assertSame(r.getSourceClassName(), null); 2702 assertSame(r.getSourceMethodName(), null); 2703 assertSame(r.getLevel(), Level.INFO); 2704 assertNull(r.getParameters()); 2705 assertSame(r.getThrown(), null); 2706 } 2707 2708 /* 2709 * Test that the parent's handler is notified for a new log record when 2710 * getUseParentHandlers() is true. 2711 */ 2712 public void testLog_ParentInformed() { 2713 Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE); 2714 Logger parent = new MockParentLogger("parentLogger", 2715 VALID_RESOURCE_BUNDLE2); 2716 2717 child.setParent(parent); 2718 child.setLevel(Level.INFO); 2719 parent.setLevel(Level.INFO); 2720 parent.addHandler(new MockHandler()); 2721 LogRecord r = new LogRecord(Level.INFO, "testLog_ParentInformed"); 2722 child.log(r); 2723 assertTrue(child.getUseParentHandlers()); 2724 // pop only once, pushed by the parent logger's handler, not by the 2725 // parent itself! 2726 assertSame(r, CallVerificationStack.getInstance().pop()); 2727 assertTrue(CallVerificationStack.getInstance().empty()); 2728 assertSame(r.getLoggerName(), null); 2729 assertEquals(r.getMessage(), "testLog_ParentInformed"); 2730 assertSame(r.getResourceBundleName(), null); 2731 assertSame(r.getSourceClassName(), null); 2732 assertSame(r.getSourceMethodName(), null); 2733 assertSame(r.getLevel(), Level.INFO); 2734 assertNull(r.getParameters()); 2735 assertSame(r.getThrown(), null); 2736 2737 // set the child logger to disabling level 2738 child.setLevel(Level.SEVERE); 2739 child.log(r); 2740 assertTrue(CallVerificationStack.getInstance().empty()); 2741 2742 // set the parent logger to disabling level 2743 child.setLevel(Level.INFO); 2744 parent.setLevel(Level.SEVERE); 2745 child.log(r); 2746 assertSame(r, CallVerificationStack.getInstance().pop()); 2747 assertTrue(CallVerificationStack.getInstance().empty()); 2748 2749 // set the child logger off 2750 child.setLevel(Level.OFF); 2751 child.log(r); 2752 assertTrue(CallVerificationStack.getInstance().empty()); 2753 2754 // set the record off 2755 r.setLevel(Level.OFF); 2756 child.log(r); 2757 assertTrue(CallVerificationStack.getInstance().empty()); 2758 } 2759 2760 /* 2761 * Test that the ancestor's handler is notified for a new log record when 2762 * getUseParentHandlers() is true. 2763 */ 2764 public void testLog_AncestorInformed() { 2765 Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE); 2766 Logger parent = new MockParentLogger("parentLogger", 2767 VALID_RESOURCE_BUNDLE2); 2768 Logger ancestor = new MockParentLogger("ancestorLogger", 2769 VALID_RESOURCE_BUNDLE3); 2770 2771 child.setParent(parent); 2772 parent.setParent(ancestor); 2773 child.setLevel(Level.INFO); 2774 parent.setLevel(Level.INFO); 2775 ancestor.setLevel(Level.OFF); 2776 ancestor.addHandler(new MockHandler()); 2777 LogRecord r = new LogRecord(Level.INFO, "testLog_AncestorInformed"); 2778 child.log(r); 2779 assertTrue(child.getUseParentHandlers()); 2780 assertTrue(parent.getUseParentHandlers()); 2781 // pop only once, pushed by the ancestor's logger's handler, not by the 2782 // parent itself! 2783 assertSame(r, CallVerificationStack.getInstance().pop()); 2784 assertTrue(CallVerificationStack.getInstance().empty()); 2785 2786 // set parent's level to a disabling one 2787 parent.setLevel(Level.WARNING); 2788 child.log(r); 2789 assertSame(r, CallVerificationStack.getInstance().pop()); 2790 assertTrue(CallVerificationStack.getInstance().empty()); 2791 2792 // set child's level to a disabling one 2793 parent.setLevel(Level.INFO); 2794 child.setLevel(Level.WARNING); 2795 child.log(r); 2796 assertTrue(CallVerificationStack.getInstance().empty()); 2797 2798 // set parent's useParentHandlers to false 2799 parent.setLevel(Level.INFO); 2800 child.setLevel(Level.INFO); 2801 parent.setUseParentHandlers(false); 2802 child.log(r); 2803 assertTrue(CallVerificationStack.getInstance().empty()); 2804 } 2805 2806 /* 2807 * Test that the parent's handler is notified for a new log record when 2808 * getUseParentHandlers() is false. 2809 */ 2810 public void testLog_ParentNotInformed() { 2811 Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE); 2812 Logger parent = new MockParentLogger("parentLogger", 2813 VALID_RESOURCE_BUNDLE2); 2814 2815 child.setParent(parent); 2816 child.setLevel(Level.INFO); 2817 parent.setLevel(Level.INFO); 2818 parent.addHandler(new MockHandler()); 2819 LogRecord r = new LogRecord(Level.INFO, "testLog_ParentInformed"); 2820 child.setUseParentHandlers(false); 2821 child.log(r); 2822 assertFalse(child.getUseParentHandlers()); 2823 assertTrue(CallVerificationStack.getInstance().empty()); 2824 } 2825 2826 /* 2827 * Test that a logger with null level and no parent. Defaulted to 2828 * Level.INFO. 2829 */ 2830 public void testLog_NullLevelNoParent() { 2831 LogRecord r = new LogRecord(Level.INFO, "testLog_NullLevelNoParent"); 2832 assertNull(this.sharedLogger.getLevel()); 2833 assertNull(this.sharedLogger.getParent()); 2834 assertTrue(this.sharedLogger.isLoggable(r.getLevel())); 2835 this.sharedLogger.log(r); 2836 assertSame(r, CallVerificationStack.getInstance().pop()); 2837 assertTrue(CallVerificationStack.getInstance().empty()); 2838 assertNull(this.sharedLogger.getLevel()); 2839 2840 r.setLevel(Level.WARNING); 2841 assertTrue(this.sharedLogger.isLoggable(r.getLevel())); 2842 this.sharedLogger.log(r); 2843 assertSame(r, CallVerificationStack.getInstance().pop()); 2844 assertTrue(CallVerificationStack.getInstance().empty()); 2845 2846 r.setLevel(Level.CONFIG); 2847 this.sharedLogger.log(r); 2848 assertFalse(this.sharedLogger.isLoggable(r.getLevel())); 2849 assertTrue(CallVerificationStack.getInstance().empty()); 2850 } 2851 2852 /* 2853 * Test that a logger inherits its parent level when its level is null. 2854 */ 2855 public void testLog_NullLevelHasParent() { 2856 Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE); 2857 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 2858 child.addHandler(new MockHandler()); 2859 child.setParent(parent); 2860 parent.setLevel(Level.FINER); 2861 2862 assertNull(child.getLevel()); 2863 2864 LogRecord r = new LogRecord(Level.FINE, "testLog_NullLevelHasParent"); 2865 child.log(r); 2866 assertTrue(child.isLoggable(r.getLevel())); 2867 // pop only once, pushed by the child logger's handler 2868 assertSame(r, CallVerificationStack.getInstance().pop()); 2869 assertTrue(CallVerificationStack.getInstance().empty()); 2870 2871 assertSame(r.getLoggerName(), null); 2872 assertEquals(r.getMessage(), "testLog_NullLevelHasParent"); 2873 assertSame(r.getResourceBundleName(), null); 2874 assertSame(r.getSourceClassName(), null); 2875 assertSame(r.getSourceMethodName(), null); 2876 assertSame(r.getLevel(), Level.FINE); 2877 assertNull(r.getParameters()); 2878 assertSame(r.getThrown(), null); 2879 assertNull(child.getLevel()); 2880 2881 // set the parent logger to disabling level 2882 parent.setLevel(Level.CONFIG); 2883 assertFalse(child.isLoggable(r.getLevel())); 2884 child.log(r); 2885 assertTrue(CallVerificationStack.getInstance().empty()); 2886 assertNull(child.getLevel()); 2887 2888 // test ancestor 2889 Logger ancestor = new MockLogger("ancestorLogger", 2890 VALID_RESOURCE_BUNDLE3); 2891 parent.setParent(ancestor); 2892 parent.setLevel(null); 2893 parent.setUseParentHandlers(false); 2894 ancestor.setLevel(Level.ALL); 2895 child.log(r); 2896 assertTrue(child.isLoggable(r.getLevel())); 2897 assertSame(r, CallVerificationStack.getInstance().pop()); 2898 assertTrue(CallVerificationStack.getInstance().empty()); 2899 assertNull(child.getLevel()); 2900 assertNull(parent.getLevel()); 2901 } 2902 2903 /* 2904 * Test that a logger with null resource bundle and no parent. Defaulted to 2905 * null. 2906 */ 2907 public void testLog_NullResNoParent() { 2908 Logger log = new MockLogger("Logger", null); 2909 log.addHandler(new MockHandler()); 2910 log.setLevel(Level.FINE); 2911 2912 assertNull(log.getResourceBundle()); 2913 assertNull(log.getResourceBundleName()); 2914 assertNull(log.getParent()); 2915 log.log(Level.INFO, "testLog_NullResNoParent"); 2916 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2917 assertTrue(CallVerificationStack.getInstance().empty()); 2918 assertNull(log.getResourceBundle()); 2919 assertNull(log.getResourceBundleName()); 2920 assertNull(r.getResourceBundle()); 2921 assertNull(r.getResourceBundleName()); 2922 } 2923 2924 /* 2925 * Test that a logger inherits its parent resource bundle when its resource 2926 * bundle is null. 2927 */ 2928 public void testLog_NullResHasParent() { 2929 Logger child = new MockLogger("childLogger", null); 2930 Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); 2931 child.addHandler(new MockHandler()); 2932 child.setParent(parent); 2933 parent.setLevel(Level.FINER); 2934 assertNull(child.getResourceBundle()); 2935 assertNull(child.getResourceBundleName()); 2936 2937 child.log(Level.FINE, "testLog_NullResHasParent"); 2938 // pop only once, pushed by the child logger's handler 2939 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2940 assertTrue(CallVerificationStack.getInstance().empty()); 2941 2942 assertSame(r.getLoggerName(), "childLogger"); 2943 assertEquals(r.getMessage(), "testLog_NullResHasParent"); 2944 assertSame(r.getResourceBundleName(), VALID_RESOURCE_BUNDLE2); 2945 assertSame(r.getSourceClassName(), null); 2946 assertSame(r.getSourceMethodName(), null); 2947 assertSame(r.getLevel(), Level.FINE); 2948 assertNull(r.getParameters()); 2949 assertSame(r.getThrown(), null); 2950 assertNull(child.getResourceBundle()); 2951 assertNull(child.getResourceBundleName()); 2952 } 2953 2954 /* 2955 * Test that a logger inherits its ancestor's resource bundle when its 2956 * resource bundle and its parent's resource bundle are both null. 2957 */ 2958 public void testLog_NullResHasAncestor() { 2959 Logger child = new MockLogger("childLogger", null); 2960 Logger parent = new MockLogger("parentLogger", null); 2961 Logger ancestor = new MockLogger("ancestorLogger", 2962 VALID_RESOURCE_BUNDLE3); 2963 child.addHandler(new MockHandler()); 2964 child.setParent(parent); 2965 parent.setParent(ancestor); 2966 parent.setLevel(Level.FINER); 2967 assertNull(child.getResourceBundle()); 2968 assertNull(child.getResourceBundleName()); 2969 2970 child.log(Level.FINE, "testLog_NullResHasAncestor"); 2971 // pop only once, pushed by the child logger's handler 2972 LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop(); 2973 assertTrue(CallVerificationStack.getInstance().empty()); 2974 2975 assertSame(r.getLoggerName(), "childLogger"); 2976 assertEquals(r.getMessage(), "testLog_NullResHasAncestor"); 2977 assertSame(r.getResourceBundleName(), VALID_RESOURCE_BUNDLE3); 2978 assertSame(r.getSourceClassName(), null); 2979 assertSame(r.getSourceMethodName(), null); 2980 assertSame(r.getLevel(), Level.FINE); 2981 assertNull(r.getParameters()); 2982 assertSame(r.getThrown(), null); 2983 assertNull(child.getResourceBundle()); 2984 assertNull(child.getResourceBundleName()); 2985 } 2986 2987 /* 2988 * Test when one handler throws an exception. 2989 */ 2990 public void testLog_ExceptionalHandler() { 2991 MockLogger l = new MockLogger("testLog_ExceptionalHandler", null); 2992 l.addHandler(new MockExceptionalHandler()); 2993 l.addHandler(new MockHandler()); 2994 try { 2995 l.severe("testLog_ExceptionalHandler"); 2996 fail("Should throw RuntimeException!"); 2997 } catch (RuntimeException e) { 2998 } 2999 assertTrue(CallVerificationStack.getInstance().empty()); 3000 } 3001 3002 /* Logger.loadResourceBundle is not publicly accessible in Android 3003 public void testLoadResourceBundleNonExistent() { 3004 try { 3005 // Try a load a non-existent resource bundle. 3006 LoggerExtension.loadResourceBundle("missinglogger.properties"); 3007 fail("Expected an exception."); 3008 } catch (MissingResourceException ex) { 3009 // Expected exception is precisely a MissingResourceException 3010 assertTrue(ex.getClass() == MissingResourceException.class); 3011 } 3012 } 3013 */ 3014 3015 /* 3016 * test initHandler 3017 */ 3018 public void test_initHandler() throws Exception { 3019 File logProps = new File(LOGGING_CONFIG_FILE); 3020 LogManager lm = LogManager.getLogManager(); 3021 lm.readConfiguration(new FileInputStream(logProps)); 3022 3023 Logger log = Logger.getLogger(""); 3024 // can log properly 3025 Handler[] handlers = log.getHandlers(); 3026 assertEquals(2, handlers.length); 3027 } 3028 3029 /* 3030 * A mock logger, used to test the protected constructors and fields. 3031 */ 3032 public static class MockLogger extends Logger { 3033 3034 public MockLogger(String name, String resourceBundleName) { 3035 super(name, resourceBundleName); 3036 } 3037 } 3038 3039 /* 3040 * A mock logger, used to test inheritance. 3041 */ 3042 public static class MockParentLogger extends Logger { 3043 3044 public MockParentLogger(String name, String resourceBundleName) { 3045 super(name, resourceBundleName); 3046 } 3047 3048 public void log(LogRecord record) { 3049 CallVerificationStack.getInstance().push(record); 3050 super.log(record); 3051 } 3052 3053 } 3054 3055 /* 3056 * A mock handler, used to validate the expected method is called with the 3057 * expected parameters. 3058 */ 3059 public static class MockHandler extends Handler { 3060 3061 public void close() { 3062 // System.out.println("close!"); 3063 } 3064 3065 public void flush() { 3066 // System.out.println("flushed!"); 3067 } 3068 3069 public void publish(LogRecord record) { 3070 // System.out.println("publish!"); 3071 CallVerificationStack.getInstance().push(record); 3072 } 3073 } 3074 3075 /* 3076 * A mock handler that throws an exception when publishing a log record. 3077 */ 3078 public static class MockExceptionalHandler extends Handler { 3079 3080 public void close() { 3081 // System.out.println("close!"); 3082 } 3083 3084 public void flush() { 3085 // System.out.println("flushed!"); 3086 } 3087 3088 public void publish(LogRecord record) { 3089 // System.out.println("publish!"); 3090 throw new RuntimeException(); 3091 } 3092 } 3093 3094 /* 3095 * A mock filter, always return false. 3096 */ 3097 public static class MockFilter implements Filter { 3098 3099 public boolean isLoggable(LogRecord record) { 3100 CallVerificationStack.getInstance().push(record); 3101 return false; 3102 } 3103 } 3104 3105 /* 3106 * A mock filter, always return true. 3107 */ 3108 public static class MockTrueFilter implements Filter { 3109 3110 public boolean isLoggable(LogRecord record) { 3111 CallVerificationStack.getInstance().push(record); 3112 return true; 3113 } 3114 } 3115 } 3116