2002-12-16 18:09:36 +01:00
|
|
|
/* *******************************************************************
|
|
|
|
* Copyright (c) 1999-2001 Xerox Corporation,
|
|
|
|
* 2002 Palo Alto Research Center, Incorporated (PARC).
|
|
|
|
* All rights reserved.
|
|
|
|
* This program and the accompanying materials are made available
|
|
|
|
* under the terms of the Common Public License v1.0
|
|
|
|
* which accompanies this distribution and is available at
|
|
|
|
* http://www.eclipse.org/legal/cpl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* Xerox/PARC initial implementation
|
|
|
|
* ******************************************************************/
|
|
|
|
|
|
|
|
// default package
|
|
|
|
|
2004-01-15 06:21:33 +01:00
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
import org.aspectj.lang.*;
|
2004-03-19 21:48:01 +01:00
|
|
|
import org.aspectj.runtime.reflect.SignatureTest;
|
2004-01-14 16:24:06 +01:00
|
|
|
|
2002-12-16 18:09:36 +01:00
|
|
|
import junit.framework.*;
|
|
|
|
|
|
|
|
public class RuntimeModuleTests extends TestCase {
|
|
|
|
|
2003-10-31 20:27:44 +01:00
|
|
|
public static TestSuite suite() {
|
2002-12-16 18:09:36 +01:00
|
|
|
TestSuite suite = new TestSuite(RuntimeModuleTests.class.getName());
|
|
|
|
suite.addTestSuite(RuntimeModuleTests.class); // minimum 1 test (testNothing)
|
2004-03-19 21:48:01 +01:00
|
|
|
suite.addTestSuite(SignatureTest.class);
|
2002-12-16 18:09:36 +01:00
|
|
|
return suite;
|
|
|
|
}
|
|
|
|
|
|
|
|
public RuntimeModuleTests(String name) { super(name); }
|
2004-01-14 16:24:06 +01:00
|
|
|
|
|
|
|
public void testNoAspectBoundException() {
|
2004-01-15 06:21:33 +01:00
|
|
|
RuntimeException fun = new RuntimeException("fun");
|
|
|
|
NoAspectBoundException nab = new NoAspectBoundException("Foo", fun);
|
|
|
|
assertEquals(fun,nab.getCause());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testSoftExceptionPrintStackTrace() {
|
|
|
|
// let's see
|
|
|
|
// Throwable t = new Error("xyz");
|
|
|
|
// new SoftException(t).printStackTrace();
|
|
|
|
|
|
|
|
// save to specified PrintStream
|
|
|
|
ByteArrayOutputStream sink = new ByteArrayOutputStream();
|
|
|
|
PrintStream out = new PrintStream(sink);
|
|
|
|
new SoftException(new Error("xyz")).printStackTrace(out);
|
|
|
|
String s = new String(sink.toByteArray());
|
|
|
|
out.flush();
|
|
|
|
checkSoftExceptionString(s);
|
|
|
|
|
|
|
|
// save to specified PrintWriter
|
|
|
|
sink = new ByteArrayOutputStream();
|
|
|
|
PrintWriter pout = new PrintWriter(sink);
|
|
|
|
new SoftException(new Error("xyz")).printStackTrace(pout);
|
|
|
|
pout.flush();
|
|
|
|
s = new String(sink.toByteArray());
|
|
|
|
checkSoftExceptionString(s);
|
|
|
|
|
|
|
|
// check System.err redirect
|
|
|
|
PrintStream systemErr = System.err;
|
|
|
|
try {
|
|
|
|
sink = new ByteArrayOutputStream();
|
|
|
|
out = new PrintStream(sink);
|
|
|
|
System.setErr(out);
|
|
|
|
new SoftException(new Error("xyz")).printStackTrace();
|
|
|
|
out.flush();
|
|
|
|
s = new String(sink.toByteArray());
|
|
|
|
checkSoftExceptionString(s);
|
|
|
|
} finally {
|
|
|
|
System.setErr(systemErr);
|
|
|
|
}
|
|
|
|
}
|
2004-03-19 21:48:01 +01:00
|
|
|
|
|
|
|
|
2004-01-15 06:21:33 +01:00
|
|
|
static void checkSoftExceptionString(String s) {
|
|
|
|
assertTrue(-1 != s.indexOf("SoftException"));
|
|
|
|
assertTrue(-1 != s.indexOf("Caused by: java.lang.Error"));
|
|
|
|
assertTrue(-1 != s.indexOf("xyz"));
|
|
|
|
assertTrue(-1 != s.indexOf("testSoftExceptionPrintStackTrace"));
|
2004-01-14 16:24:06 +01:00
|
|
|
}
|
2002-12-16 18:09:36 +01:00
|
|
|
}
|