|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.mj.impl.utils; |
|
20 |
|
21 import com.nokia.mj.impl.utils.DebugUtils; |
|
22 |
|
23 import com.nokia.mj.impl.rt.test.UnitTestSuiteCreator; |
|
24 import j2meunit.framework.Test; |
|
25 import j2meunit.framework.TestCase; |
|
26 import j2meunit.framework.TestMethod; |
|
27 import j2meunit.framework.TestSuite; |
|
28 |
|
29 /** |
|
30 * DebugUtils unit tests. |
|
31 */ |
|
32 public class DebugUtilsTests extends TestCase implements UnitTestSuiteCreator |
|
33 { |
|
34 // Create the test suite. |
|
35 public TestSuite createTestSuite(String[] args) |
|
36 { |
|
37 TestSuite suite = new TestSuite(this.getClass().getName()); |
|
38 |
|
39 suite.addTest(new DebugUtilsTests("TestStackTrace", new TestMethod() |
|
40 { |
|
41 public void run(TestCase tc) |
|
42 { |
|
43 ((DebugUtilsTests)tc).testStackTrace(); |
|
44 } |
|
45 })); |
|
46 |
|
47 return suite; |
|
48 } |
|
49 |
|
50 public DebugUtilsTests() |
|
51 { |
|
52 } |
|
53 |
|
54 public DebugUtilsTests(String aTestName, TestMethod aTestMethod) |
|
55 { |
|
56 super(aTestName, aTestMethod); |
|
57 } |
|
58 |
|
59 // End j2meunit test framework setup |
|
60 |
|
61 protected void setUp() |
|
62 { |
|
63 } |
|
64 |
|
65 protected void tearDown() |
|
66 { |
|
67 } |
|
68 |
|
69 public void testStackTrace() |
|
70 { |
|
71 try |
|
72 { |
|
73 try |
|
74 { |
|
75 DebugUtils.getStackTrace(null); |
|
76 assertTrue("No exception.", false); |
|
77 } |
|
78 catch (NullPointerException ne) |
|
79 { |
|
80 } |
|
81 |
|
82 Exception e1 = new Exception("Test 42"); |
|
83 String res = DebugUtils.getStackTrace(e1); |
|
84 boolean ok = res.indexOf("at com.nokia.mj.impl.utils.DebugUtilsTests.testStackTrace") >= 0; |
|
85 assertTrue("Exception didn't contain: " + res, ok); |
|
86 |
|
87 } |
|
88 catch (Throwable t) |
|
89 { |
|
90 assertTrue(t.toString(), false); |
|
91 t.printStackTrace(); |
|
92 } |
|
93 } |
|
94 } |