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

Last change on this file since 17442 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools.bugreport;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertSame;
6import static org.junit.jupiter.api.Assertions.assertTrue;
7
8import java.io.IOException;
9import java.io.PrintWriter;
10import java.io.StringWriter;
11
12import org.junit.jupiter.api.extension.RegisterExtension;
13import org.junit.jupiter.api.Test;
14import org.openstreetmap.josm.actions.ShowStatusReportAction;
15import org.openstreetmap.josm.testutils.JOSMTestRules;
16
17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
18
19/**
20 * Tests the bug report class.
21 * @author Michael Zangl
22 */
23class BugReportTest {
24 /**
25 * Preferences for the report text
26 */
27 @RegisterExtension
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 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 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 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.