source: josm/trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportTest.java@ 12770

Last change on this file since 12770 was 12770, checked in by bastiK, 7 years ago

see #15229 - remove GUI references from BugReport and BugReportQueue

signature of BugReport#getReportText changed without deprecation
(probably not used by any external plugin)

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools.bugreport;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertSame;
6import static org.junit.Assert.assertTrue;
7
8import java.io.IOException;
9import java.io.PrintWriter;
10import java.io.StringWriter;
11
12import org.junit.Rule;
13import org.junit.Test;
14import org.openstreetmap.josm.testutils.JOSMTestRules;
15
16import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17import org.openstreetmap.josm.actions.ShowStatusReportAction;
18
19/**
20 * Tests the bug report class.
21 * @author Michael Zangl
22 */
23public class BugReportTest {
24 /**
25 * Preferences for the report text
26 */
27 @Rule
28 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
29 public JOSMTestRules test = new JOSMTestRules().preferences();
30
31 /**
32 * Test {@link BugReport#getReportText()}
33 */
34 @Test
35 public void testReportText() {
36 ReportedException e = interceptInChildMethod(new IOException("test-exception-message"));
37 e.put("test-key", "test-value");
38 String text = new BugReport(e).getReportText(ShowStatusReportAction.getReportHeader());
39
40 assertTrue(text.contains("test-exception-message"));
41 assertTrue(text.contains("interceptInChildMethod"));
42 assertTrue(text.contains("testReportText")); // stack trace
43 assertTrue(text.contains("test-key: test-value"));
44 }
45
46 /**
47 * Test {@link BugReport#intercept(Throwable)}
48 */
49 @Test
50 public void testIntercept() {
51 IOException base = new IOException("test");
52 ReportedException intercepted = interceptInChildMethod(base);
53 assertEquals(intercepted.getCause(), base);
54
55 StringWriter out = new StringWriter();
56 intercepted.printReportDataTo(new PrintWriter(out));
57
58 assertTrue(out.toString().contains("interceptInChildMethod")); // calling method.
59
60 assertSame(intercepted, BugReport.intercept(intercepted));
61 }
62
63 private ReportedException interceptInChildMethod(IOException base) {
64 return BugReport.intercept(base);
65 }
66
67 /**
68 * Test {@link BugReport#getCallingMethod(int)}
69 */
70 @Test
71 public void testGetCallingMethod() {
72 assertEquals("BugReportTest#testGetCallingMethod", BugReport.getCallingMethod(1));
73 assertEquals("BugReportTest#testGetCallingMethod", testGetCallingMethod2());
74 assertEquals("?", BugReport.getCallingMethod(100));
75 }
76
77 private String testGetCallingMethod2() {
78 return BugReport.getCallingMethod(2);
79 }
80}
Note: See TracBrowser for help on using the repository browser.