aboutsummaryrefslogtreecommitdiffstats
path: root/weaver5
diff options
context:
space:
mode:
authormwebster <mwebster>2006-07-27 09:30:17 +0000
committermwebster <mwebster>2006-07-27 09:30:17 +0000
commitdb06666e1c5858bdc4e6fb0c43ec2d74efd649f2 (patch)
treea97ae037a3dfe55839848f1a8bc22a9dc9c4f0f7 /weaver5
parent79d9aff324adce6ef480155be0db3db85a89092a (diff)
downloadaspectj-db06666e1c5858bdc4e6fb0c43ec2d74efd649f2.tar.gz
aspectj-db06666e1c5858bdc4e6fb0c43ec2d74efd649f2.zip
Bug 150487 "Tracing and Logging Framework" (add JUnit tests)
Diffstat (limited to 'weaver5')
-rw-r--r--weaver5/java5-src/org/aspectj/weaver/tools/Jdk14Trace.java22
-rw-r--r--weaver5/java5-testsrc/AllWeaver5Tests.java8
-rw-r--r--weaver5/java5-testsrc/org/aspectj/weaver/AllTracing5Tests.java27
-rw-r--r--weaver5/java5-testsrc/org/aspectj/weaver/Jdk14TraceFactoryTest.java30
-rw-r--r--weaver5/java5-testsrc/org/aspectj/weaver/Jdk14TraceTest.java67
-rw-r--r--weaver5/testsrc/Weaver5ModuleTests.java1
6 files changed, 150 insertions, 5 deletions
diff --git a/weaver5/java5-src/org/aspectj/weaver/tools/Jdk14Trace.java b/weaver5/java5-src/org/aspectj/weaver/tools/Jdk14Trace.java
index 93d816d90..7847e6127 100644
--- a/weaver5/java5-src/org/aspectj/weaver/tools/Jdk14Trace.java
+++ b/weaver5/java5-src/org/aspectj/weaver/tools/Jdk14Trace.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.aspectj.weaver.tools;
+import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -55,9 +56,26 @@ public class Jdk14Trace extends AbstractTrace {
}
}
- @Override
public boolean isTraceEnabled() {
- return logger.isLoggable(Level.FINE);
+ return logger.isLoggable(Level.FINER);
+ }
+
+ public void setTraceEnabled (boolean b) {
+ if (b) {
+ logger.setLevel(Level.FINER);
+ Handler[] handlers = logger.getHandlers();
+ if (handlers.length == 0) {
+ Logger parent = logger.getParent();
+ if (parent != null) handlers = parent.getHandlers();
+ }
+ for (int i = 0; i < handlers.length; i++) {
+ Handler handler = handlers[i];
+ handler.setLevel(Level.FINER);
+ }
+ }
+ else {
+ logger.setLevel(Level.INFO);
+ }
}
}
diff --git a/weaver5/java5-testsrc/AllWeaver5Tests.java b/weaver5/java5-testsrc/AllWeaver5Tests.java
index f0ef453c6..f54997a4e 100644
--- a/weaver5/java5-testsrc/AllWeaver5Tests.java
+++ b/weaver5/java5-testsrc/AllWeaver5Tests.java
@@ -1,3 +1,7 @@
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.aspectj.weaver.AllTracing5Tests;
import org.aspectj.weaver.TestJava5ReflectionBasedReferenceTypeDelegate;
import org.aspectj.weaver.patterns.ArgsTestCase;
import org.aspectj.weaver.patterns.ThisOrTargetTestCase;
@@ -6,9 +10,6 @@ import org.aspectj.weaver.tools.PointcutExpressionTest;
import org.aspectj.weaver.tools.PointcutParserTest;
import org.aspectj.weaver.tools.TypePatternMatcherTest;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
public class AllWeaver5Tests {
public static Test suite() {
@@ -21,6 +22,7 @@ public class AllWeaver5Tests {
suite.addTestSuite(PointcutExpressionTest.class);
suite.addTestSuite(PointcutParserTest.class);
suite.addTestSuite(TypePatternMatcherTest.class);
+ suite.addTest(AllTracing5Tests.suite());
//$JUnit-END$
return suite;
}
diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/AllTracing5Tests.java b/weaver5/java5-testsrc/org/aspectj/weaver/AllTracing5Tests.java
new file mode 100644
index 000000000..bc6e594b7
--- /dev/null
+++ b/weaver5/java5-testsrc/org/aspectj/weaver/AllTracing5Tests.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Webster - initial implementation
+ *******************************************************************************/
+package org.aspectj.weaver;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTracing5Tests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for org.aspectj.weaver");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(Jdk14TraceFactoryTest.class);
+ suite.addTestSuite(Jdk14TraceTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/Jdk14TraceFactoryTest.java b/weaver5/java5-testsrc/org/aspectj/weaver/Jdk14TraceFactoryTest.java
new file mode 100644
index 000000000..39bdef23d
--- /dev/null
+++ b/weaver5/java5-testsrc/org/aspectj/weaver/Jdk14TraceFactoryTest.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Webster - initial implementation
+ *******************************************************************************/
+package org.aspectj.weaver;
+
+import junit.framework.TestCase;
+
+import org.aspectj.weaver.tools.Jdk14TraceFactory;
+import org.aspectj.weaver.tools.Trace;
+
+public class Jdk14TraceFactoryTest extends TestCase {
+
+ public void testJdk14TraceFactory() {
+ Jdk14TraceFactory factory = new Jdk14TraceFactory();
+ }
+
+ public void testGetTrace() {
+ Jdk14TraceFactory factory = new Jdk14TraceFactory();
+ Trace trace = factory.getTrace(getClass());
+ assertFalse("Tracing should be disbled by default",trace.isTraceEnabled());
+ }
+
+}
diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/Jdk14TraceTest.java b/weaver5/java5-testsrc/org/aspectj/weaver/Jdk14TraceTest.java
new file mode 100644
index 000000000..283aadb55
--- /dev/null
+++ b/weaver5/java5-testsrc/org/aspectj/weaver/Jdk14TraceTest.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Webster - initial implementation
+ *******************************************************************************/
+package org.aspectj.weaver;
+
+import org.aspectj.weaver.tools.DefaultTrace;
+import org.aspectj.weaver.tools.Jdk14Trace;
+
+import junit.framework.TestCase;
+
+public class Jdk14TraceTest extends TestCase {
+
+ private Jdk14Trace trace;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ trace = new Jdk14Trace(getClass());
+ trace.setTraceEnabled(true);
+ }
+
+ public void testJdk14Trace() {
+ Jdk14Trace trace = new Jdk14Trace(getClass());
+ }
+
+ public void testEnterWithThisAndArgs() {
+ trace.enter("testEnterWithThisAndArgs",this,new Object[] { "arg1", "arg2" });
+ }
+
+ public void testEnterWithThis() {
+ trace.enter("testEnterWithThis",this);
+ }
+
+ public void testEnter() {
+ trace.enter("testEnter");
+ }
+
+ public void testExitWithReturn() {
+ trace.exit("testExitWithReturn","ret");
+ }
+
+ public void testExitWithThrowable() {
+ trace.exit("testExitWithThrowable",new RuntimeException());
+ }
+
+ public void testExit() {
+ trace.exit("testExit");
+ }
+
+ public void testIsTraceEnabled() {
+ DefaultTrace trace = new DefaultTrace(getClass());
+ assertFalse(trace.isTraceEnabled());
+ }
+
+ public void testSetTraceEnabled() {
+ DefaultTrace trace = new DefaultTrace(getClass());
+ trace.setTraceEnabled(true);
+ assertTrue(trace.isTraceEnabled());
+ }
+
+}
diff --git a/weaver5/testsrc/Weaver5ModuleTests.java b/weaver5/testsrc/Weaver5ModuleTests.java
index b8bb1170b..8aa725b93 100644
--- a/weaver5/testsrc/Weaver5ModuleTests.java
+++ b/weaver5/testsrc/Weaver5ModuleTests.java
@@ -25,6 +25,7 @@ public class Weaver5ModuleTests extends TestCase {
TestSuite suite = new TestSuite(Weaver5ModuleTests.class.getName());
if (TestUtil.is15VMOrGreater()) {
TestUtil.loadTestsReflectively(suite, "org.aspectj.weaver.tools.Java15PointcutExpressionTest", false);
+ TestUtil.loadTestsReflectively(suite, "org.aspectj.weaver.AllTracing5Tests", false);
suite.addTestSuite(PointcutExpressionTest.class);
} else {
suite.addTest(TestUtil.testNamed("all tests require 1.5"));