PageRenderTime 259ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/apache-log4j-1.2.17/tests/src/java/org/apache/log4j/CategoryTest.java

#
Java | 111 lines | 45 code | 12 blank | 54 comment | 1 complexity | 2fa77fc21da64c7957ed1e2a03db8c63 MD5 | raw file
Possible License(s): Apache-2.0
  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. package org.apache.log4j;
  18. import junit.framework.TestCase;
  19. import java.lang.reflect.Method;
  20. /**
  21. * Tests of Category.
  22. *
  23. * @author Curt Arnold
  24. * @since 1.2.14
  25. */
  26. public class CategoryTest extends TestCase {
  27. /**
  28. * Constructs new instance of test.
  29. * @param name test name.
  30. */
  31. public CategoryTest(final String name) {
  32. super(name);
  33. }
  34. /**
  35. * Tests Category.forcedLog.
  36. */
  37. public void testForcedLog() {
  38. MockCategory category = new MockCategory("org.example.foo");
  39. category.setAdditivity(false);
  40. category.addAppender(new VectorAppender());
  41. category.info("Hello, World");
  42. }
  43. /**
  44. * Tests that the return type of getChainedPriority is Priority.
  45. * @throws Exception thrown if Category.getChainedPriority can not be found.
  46. */
  47. public void testGetChainedPriorityReturnType() throws Exception {
  48. Method method = Category.class.getMethod("getChainedPriority", (Class[]) null);
  49. assertTrue(method.getReturnType() == Priority.class);
  50. }
  51. /**
  52. * Tests l7dlog(Priority, String, Throwable).
  53. */
  54. public void testL7dlog() {
  55. Logger logger = Logger.getLogger("org.example.foo");
  56. logger.setLevel(Level.ERROR);
  57. Priority debug = Level.DEBUG;
  58. logger.l7dlog(debug, "Hello, World", null);
  59. }
  60. /**
  61. * Tests l7dlog(Priority, String, Object[], Throwable).
  62. */
  63. public void testL7dlog4Param() {
  64. Logger logger = Logger.getLogger("org.example.foo");
  65. logger.setLevel(Level.ERROR);
  66. Priority debug = Level.DEBUG;
  67. logger.l7dlog(debug, "Hello, World", new Object[0], null);
  68. }
  69. /**
  70. * Tests setPriority(Priority).
  71. * @deprecated
  72. */
  73. public void testSetPriority() {
  74. Logger logger = Logger.getLogger("org.example.foo");
  75. Priority debug = Level.DEBUG;
  76. logger.setPriority(debug);
  77. }
  78. /**
  79. * Derived category to check method signature of forcedLog.
  80. */
  81. private static class MockCategory extends Logger {
  82. /**
  83. * Create new instance of MockCategory.
  84. * @param name category name
  85. */
  86. public MockCategory(final String name) {
  87. super(name);
  88. repository = new Hierarchy(this);
  89. }
  90. /**
  91. * Request an info level message.
  92. * @param msg message
  93. */
  94. public void info(final String msg) {
  95. Priority info = Level.INFO;
  96. forcedLog(MockCategory.class.toString(), info, msg, null);
  97. }
  98. }
  99. }