Changeset 10886 in josm
- Timestamp:
- 2016-08-24T00:18:37+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReport.java
r10745 r10886 123 123 PrintWriter out = new PrintWriter(stringWriter); 124 124 if (isIncludeStatusReport()) { 125 out.println(ShowStatusReportAction.getReportHeader()); 125 try { 126 out.println(ShowStatusReportAction.getReportHeader()); 127 } catch (RuntimeException e) { 128 out.println("Could not generate status report: " + e.getMessage()); 129 } 126 130 } 127 131 if (isIncludeData()) { -
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportQueue.java
r10819 r10886 5 5 import java.util.ArrayList; 6 6 import java.util.LinkedList; 7 import java.util.concurrent.CopyOnWriteArrayList; 7 8 import java.util.function.BiFunction; 9 import java.util.function.Predicate; 8 10 9 11 import org.openstreetmap.josm.Main; … … 23 25 private Thread displayThread; 24 26 private final BiFunction<ReportedException, Integer, SuppressionMode> bugReportHandler = getBestHandler(); 27 private final CopyOnWriteArrayList<Predicate<ReportedException>> handlers = new CopyOnWriteArrayList<>(); 25 28 private int displayedErrors; 26 29 … … 97 100 98 101 private SuppressionMode displayFor(ReportedException e) { 102 if (handlers.stream().anyMatch(p -> p.test(e))) { 103 Main.trace("Intercepted by handler."); 104 return SuppressionMode.NONE; 105 } 99 106 return bugReportHandler.apply(e, getDisplayedErrors()); 100 107 } … … 123 130 } 124 131 132 /** 133 * Allows you to peek or even intersect the bug reports. 134 * @param handler The handler. It can return false to stop all further handling of the exception. 135 * @since 10886 136 */ 137 public void addBugReportHandler(Predicate<ReportedException> handler) { 138 handlers.add(handler); 139 } 140 141 /** 142 * Gets the global bug report queue 143 * @return The queue 144 * @since 10886 145 */ 125 146 public static BugReportQueue getInstance() { 126 147 return INSTANCE; -
trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandlerTest.java
r10819 r10886 2 2 package org.openstreetmap.josm.tools.bugreport; 3 3 4 import static org.junit.Assert.assertFalse;4 import java.util.concurrent.CountDownLatch; 5 5 6 import org.junit. Before;6 import org.junit.Rule; 7 7 import org.junit.Test; 8 import org.openstreetmap.josm.JOSMFixture; 8 import org.openstreetmap.josm.testutils.JOSMTestRules; 9 10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 9 11 10 12 /** … … 12 14 */ 13 15 public class BugReportExceptionHandlerTest { 14 15 16 /** 16 * Setup tests.17 * No dependencies 17 18 */ 18 @Before 19 public void setUp() { 20 JOSMFixture.createUnitTestFixture().init(true); 21 } 19 @Rule 20 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 21 public JOSMTestRules test = new JOSMTestRules(); 22 22 23 23 /** 24 24 * Unit test for {@link BugReportExceptionHandler#handleException} method. 25 * @throws InterruptedException if the current thread is interrupted while waiting 25 26 */ 26 27 @Test 27 public void testHandleException() { 28 public void testHandleException() throws InterruptedException { 29 CountDownLatch latch = new CountDownLatch(1); 30 BugReportQueue.getInstance().addBugReportHandler(e -> {latch.countDown(); return false;}); 28 31 BugReportExceptionHandler.handleException(new Exception("testHandleException")); 29 assertFalse(BugReportExceptionHandler.exceptionHandlingInProgress());32 latch.await(); 30 33 } 31 34 } -
trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportTest.java
r10285 r10886 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertSame; 6 import static org.junit.Assert.assertTrue; 5 7 8 import java.io.IOException; 9 import java.io.PrintWriter; 10 import java.io.StringWriter; 11 12 import org.junit.Rule; 6 13 import org.junit.Test; 14 import org.openstreetmap.josm.testutils.JOSMTestRules; 15 16 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 7 17 8 18 /** 9 19 * Tests the bug report class. 10 20 * @author Michael Zangl 11 * @since 1028512 21 */ 13 22 public class BugReportTest { 23 /** 24 * Preferences for the report text 25 */ 26 @Rule 27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 28 public JOSMTestRules test = new JOSMTestRules().preferences(); 29 30 /** 31 * Test {@link BugReport#getReportText()} 32 */ 33 @Test 34 public void testReportText() { 35 ReportedException e = interceptInChildMethod(new IOException("test-exception-message")); 36 e.put("test-key", "test-value"); 37 String text = new BugReport(e).getReportText(); 38 39 assertTrue(text.contains("test-exception-message")); 40 assertTrue(text.contains("interceptInChildMethod")); 41 assertTrue(text.contains("testReportText")); // stack trace 42 assertTrue(text.contains("test-key: test-value")); 43 } 44 45 /** 46 * Test {@link BugReport#intercept(Throwable)} 47 */ 48 @Test 49 public void testIntercept() { 50 IOException base = new IOException("test"); 51 ReportedException intercepted = interceptInChildMethod(base); 52 assertEquals(intercepted.getCause(), base); 53 54 StringWriter out = new StringWriter(); 55 intercepted.printReportDataTo(new PrintWriter(out)); 56 57 assertTrue(out.toString().contains("interceptInChildMethod")); // calling method. 58 59 assertSame(intercepted, BugReport.intercept(intercepted)); 60 } 61 62 private ReportedException interceptInChildMethod(IOException base) { 63 return BugReport.intercept(base); 64 } 14 65 15 66 /** … … 20 71 assertEquals("BugReportTest#testGetCallingMethod", BugReport.getCallingMethod(1)); 21 72 assertEquals("BugReportTest#testGetCallingMethod", testGetCallingMethod2()); 73 assertEquals("?", BugReport.getCallingMethod(100)); 22 74 } 23 75
Note:
See TracChangeset
for help on using the changeset viewer.