View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.report;
20  
21  import junit.framework.TestCase;
22  
23  /**
24   *
25   */
26  public class PojoStackTraceWriterTest extends TestCase {
27  
28      public void testTrimmedThrowableReal() {
29          PojoStackTraceWriter w =
30                  new PojoStackTraceWriter(ATestClass.AnotherTestClass.class.getName(), "testQuote", getAThrowAble());
31          String out = w.writeTrimmedTraceToString();
32          String expected = "org.apache.maven.surefire.report.PojoStackTraceWriterTest$ATestClass$AnotherTestClass"
33                  + ".getAThrowable(PojoStackTraceWriterTest.java";
34          assertTrue(out.contains(expected));
35      }
36  
37      public void testMultiLineMessage() {
38          String msg = "assert \"foo\" == \"bar\"\n" + "             |\n" + "             false";
39          try {
40              throw new RuntimeException(msg);
41          } catch (Throwable t) {
42              PojoStackTraceWriter writer = new PojoStackTraceWriter(null, null, t);
43              String stackTrace = writer.writeTraceToString();
44              assertTrue(stackTrace.startsWith("java.lang.RuntimeException: \n" + msg));
45          }
46      }
47  
48      static class ATestClass {
49          static class AnotherTestClass {
50              public static Throwable getAThrowable() {
51                  try {
52                      throw new Exception("Hey ho, hey ho, a throwable we throw!");
53                  } catch (Exception e) {
54                      return e;
55                  }
56              }
57          }
58      }
59  
60      private Throwable getAThrowAble() {
61          return ATestClass.AnotherTestClass.getAThrowable();
62      }
63  }