01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
18: /**
19: * @author Elena Semukhina
20: * @version $Revision$
21: */package java.lang;
22:
23: import junit.framework.TestCase;
24:
25: public class ThrowableRTest extends TestCase {
26:
27: private class initCauseExc extends RuntimeException {
28:
29: private static final long serialVersionUID = 0L;
30:
31: initCauseExc(Throwable cause) {
32: super (cause);
33: }
34:
35: public Throwable initCause(Throwable cause) {
36: return cause;
37: }
38: }
39:
40: /**
41: * Tests the Throwable(Throwable) constructor when the initCause() method
42: * is overloaded
43: */
44: public void testThrowableThrowableInitCause() {
45: NullPointerException nPE = new NullPointerException();
46: initCauseExc iC = new initCauseExc(nPE);
47: assertTrue("Assert 0: The cause has not been set", iC
48: .getCause() != null);
49: assertTrue("Assert 1: The invalid cause has been set", iC
50: .getCause() == nPE);
51: }
52:
53: /**
54: * A regression test for HARMONY-1431 I-3 issue.
55: * Tests that getStackTrace() contains info about sources
56: * and does not contain empty parentheses
57: */
58: public void testStackTraceFileName() {
59: try {
60: Class<?> a = Class.forName("SomeClass");
61: fail("ClassNotFoundException should be thrown");
62: } catch (ClassNotFoundException e) {
63: StackTraceElement ste[] = e.getStackTrace();
64: for (int i = 0; i < ste.length; i++) {
65: String element = ste[i].toString();
66: if (element.indexOf("()") != -1) {
67: fail("Empty parentheses are published in stack trace: "
68: + element);
69: break;
70: }
71: }
72: }
73: }
74:
75: /**
76: * A regression test for HARMONY-1431 I-3 issue.
77: * Tests that getStackTrace() contains info about the "main" method
78: */
79: public void testStackTraceMathodMain() {
80: try {
81: Class<?> a = Class.forName("SomeClass");
82: fail("ClassNotFoundException should be thrown");
83: } catch (ClassNotFoundException e) {
84: StackTraceElement ste[] = e.getStackTrace();
85: String mainFrame = ste[ste.length - 1].toString();
86: if (mainFrame.indexOf("TestRunner.main") == -1) {
87: fail("Method \"main\" is not published in stack trace");
88: }
89: }
90: }
91: }
|