1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.testutils.annotations;
|
---|
3 |
|
---|
4 | import java.lang.annotation.Documented;
|
---|
5 | import java.lang.annotation.ElementType;
|
---|
6 | import java.lang.annotation.Retention;
|
---|
7 | import java.lang.annotation.RetentionPolicy;
|
---|
8 | import java.lang.annotation.Target;
|
---|
9 |
|
---|
10 | import org.junit.jupiter.api.extension.BeforeEachCallback;
|
---|
11 | import org.junit.jupiter.api.extension.ExtendWith;
|
---|
12 | import org.junit.jupiter.api.extension.ExtensionContext;
|
---|
13 | import org.openstreetmap.josm.gui.mappaint.ElemStyles;
|
---|
14 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Use map styles in tests.
|
---|
18 | *
|
---|
19 | * @author Taylor Smock
|
---|
20 | * @see JOSMTestRules#mapStyles()
|
---|
21 | */
|
---|
22 | @Documented
|
---|
23 | @Retention(RetentionPolicy.RUNTIME)
|
---|
24 | @Target({ ElementType.METHOD, ElementType.TYPE })
|
---|
25 | @BasicPreferences
|
---|
26 | @ExtendWith(MapPaintStyles.MapPaintStylesExtension.class)
|
---|
27 | public @interface MapPaintStyles {
|
---|
28 | /**
|
---|
29 | * Set up the default paintstyles
|
---|
30 | */
|
---|
31 | class MapPaintStylesExtension implements BeforeEachCallback {
|
---|
32 | private static int lastHashcode;
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public void beforeEach(ExtensionContext extensionContext) throws Exception {
|
---|
36 | setup();
|
---|
37 | }
|
---|
38 |
|
---|
39 | public static void setup() {
|
---|
40 | final ElemStyles styles = org.openstreetmap.josm.gui.mappaint.MapPaintStyles.getStyles();
|
---|
41 | if (styles.getStyleSources().hashCode() != lastHashcode || styles.getStyleSources().isEmpty()) {
|
---|
42 | org.openstreetmap.josm.gui.mappaint.MapPaintStyles.readFromPreferences();
|
---|
43 | lastHashcode = org.openstreetmap.josm.gui.mappaint.MapPaintStyles.getStyles().getStyleSources().hashCode();
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|