You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractTraceTest.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*******************************************************************************
  2. * Copyright (c) 2006 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Matthew Webster - initial implementation
  10. *******************************************************************************/
  11. package org.aspectj.weaver;
  12. import java.util.ArrayList;
  13. import org.aspectj.weaver.tools.AbstractTrace;
  14. import org.aspectj.weaver.tools.DefaultTrace;
  15. import org.aspectj.weaver.tools.Traceable;
  16. import junit.framework.TestCase;
  17. public abstract class AbstractTraceTest extends TestCase {
  18. protected AbstractTrace trace;
  19. public void testIsTraceEnabled() {
  20. DefaultTrace trace = new DefaultTrace(getClass());
  21. assertFalse(trace.isTraceEnabled());
  22. }
  23. public void testEnterWithThisAndArgs() {
  24. trace.enter("testEnterWithThisAndArgs",this,new Object[] { "arg1", "arg2" });
  25. }
  26. public void testEnterWithThisAndArray() {
  27. Object arg1 = new String[] { "s1", "s2" };
  28. Object arg2 = new char[] { 'a', 'b', 'c' };
  29. trace.enter(getName(),this,new Object[] { arg1, arg2 });
  30. }
  31. public void testEnterWithThisAndCollection() {
  32. Object arg1 = new ArrayList();
  33. trace.enter(getName(),this,new Object[] { arg1 });
  34. }
  35. public void testEnterWithThisAndTraceable () {
  36. Object arg1 = new Traceable() {
  37. public String toTraceString() {
  38. return getClass().getName() + "[Traceable]";
  39. }
  40. };
  41. trace.enter(getName(),this,new Object[] { arg1 });
  42. }
  43. public void testEnterWithThisAndToStringException () {
  44. Object arg1 = new Object() {
  45. public String toString() {
  46. throw new RuntimeException("toString() can throw an Exception");
  47. }
  48. };
  49. trace.enter(getName(),this,new Object[] { arg1 });
  50. }
  51. public void testEnterWithThisAndHashCodeException () {
  52. Object arg1 = new Object() {
  53. public int hashCode() {
  54. throw new RuntimeException("hashCode can throw an Exception");
  55. }
  56. };
  57. trace.enter(getName(),this,new Object[] { arg1 });
  58. }
  59. public void testEnterWithThisAndClassLoader () {
  60. Object arg1 = new ClassLoader() {
  61. public String toString() {
  62. throw new Error("Don't call ClassLoader.toString()");
  63. }
  64. };
  65. trace.enter(getName(),this,new Object[] { arg1 });
  66. }
  67. public void testEnterWithThis() {
  68. trace.enter("testEnterWithThis",this);
  69. }
  70. public void testEnter() {
  71. trace.enter("testEnter");
  72. }
  73. public void testExitWithReturn() {
  74. trace.exit("testExitWithReturn","ret");
  75. }
  76. public void testExitWithThrowable() {
  77. trace.exit("testExitWithThrowable",new RuntimeException());
  78. }
  79. public void testExit() {
  80. trace.exit("testExit");
  81. }
  82. public void testEvent() {
  83. trace.event("testEvent");
  84. }
  85. public void testEventWithThisAndArgs() {
  86. trace.event("testEventWithThisAndArgs",this,new Object[] { "arg1", "arg2" });
  87. }
  88. public void testEventWithThisAndArg() {
  89. trace.event("testEventWithThisAndArg",this,"arg1");
  90. }
  91. public void testDebug() {
  92. trace.debug("debug");
  93. }
  94. public void testInfo() {
  95. trace.info("information");
  96. }
  97. public void testWarn() {
  98. trace.warn("warning");
  99. }
  100. public void testWarnWithException() {
  101. trace.warn("warning",new RuntimeException("warning"));
  102. }
  103. public void testError() {
  104. trace.error("error");
  105. }
  106. public void testErrorWithException() {
  107. trace.error("error",new RuntimeException("error"));
  108. }
  109. public void testFatal() {
  110. trace.fatal("fatal");
  111. }
  112. public void testFatalWithException() {
  113. trace.fatal("fatal",new RuntimeException("fatal"));
  114. }
  115. }