source: josm/trunk/test/unit/org/openstreetmap/josm/testutils/annotations/AssertionsInEDT.java@ 18972

Last change on this file since 18972 was 18972, checked in by taylor.smock, 4 months ago

See #23465: Add additional javadoc comments

This also fixes some sonarlint issues

File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.testutils.annotations;
3
4import java.lang.annotation.ElementType;
5import java.lang.annotation.Retention;
6import java.lang.annotation.RetentionPolicy;
7import java.lang.annotation.Target;
8
9import org.junit.jupiter.api.extension.BeforeEachCallback;
10import org.junit.jupiter.api.extension.ExtendWith;
11import org.junit.jupiter.api.extension.ExtensionContext;
12import org.openstreetmap.josm.testutils.mockers.EDTAssertionMocker;
13
14/**
15 * Ensure that assertions in the edt are caught.
16 * The default mocker is {@link EDTAssertionMocker}. If you want to use a different one,
17 * you must use {@link org.junit.jupiter.api.extension.RegisterExtension} with
18 * {@link AssertionsExtension#setMocker(Runnable)}.
19 */
20@Target({ElementType.TYPE, ElementType.METHOD})
21@Retention(RetentionPolicy.RUNTIME)
22@ExtendWith(AssertionsInEDT.AssertionsExtension.class)
23public @interface AssertionsInEDT {
24 /**
25 * Check for assertions in the EDT
26 */
27 class AssertionsExtension implements BeforeEachCallback {
28 private Runnable edtAssertionMockingRunnable = EDTAssertionMocker::new;
29 @Override
30 public void beforeEach(ExtensionContext context) throws Exception {
31 this.edtAssertionMockingRunnable.run();
32 }
33
34 /**
35 * Re-raise AssertionErrors thrown in the EDT where they would have normally been swallowed.
36 * @param edtAssertionMockingRunnable Runnable for initializing this functionality
37 *
38 * @return this instance, for easy chaining
39 */
40 public AssertionsExtension setMocker(Runnable edtAssertionMockingRunnable) {
41 this.edtAssertionMockingRunnable = edtAssertionMockingRunnable;
42 return this;
43 }
44 }
45}
Note: See TracBrowser for help on using the repository browser.