blob: 61bc7a86950ee13a5f10ad94505de6782350127f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/* *******************************************************************
* 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
import java.io.*;
import org.aspectj.lang.*;
import org.aspectj.runtime.reflect.JoinPointImplTest;
import org.aspectj.runtime.reflect.SignatureTest;
import junit.framework.*;
public class RuntimeModuleTests extends TestCase {
public static TestSuite suite() {
TestSuite suite = new TestSuite(RuntimeModuleTests.class.getName());
suite.addTestSuite(RuntimeModuleTests.class); // minimum 1 test (testNothing)
suite.addTestSuite(SignatureTest.class);
suite.addTestSuite(JoinPointImplTest.class);
return suite;
}
public RuntimeModuleTests(String name) { super(name); }
public void testNoAspectBoundException() {
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);
}
}
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"));
}
}
|