Changeset 18799 in josm


Ignore:
Timestamp:
2023-08-08T21:24:36+02:00 (16 months ago)
Author:
taylor.smock
Message:

See r18798: Actually use the @Territories annotation

This also fixes some tests that fail with specific options, but were passing due
to run order.

Location:
trunk/test
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/performance/org/openstreetmap/josm/data/validation/ValidationTaskPerformanceTest.java

    r17617 r18799  
    22package org.openstreetmap.josm.data.validation;
    33
    4 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     4import static org.junit.jupiter.api.Assertions.assertTrue;
     5
     6import java.util.Collection;
     7import java.util.List;
     8import java.util.stream.Collectors;
     9
    510import org.junit.jupiter.api.BeforeEach;
    611import org.junit.jupiter.api.Test;
    7 import org.junit.jupiter.api.extension.RegisterExtension;
    812import org.openstreetmap.josm.PerformanceTestUtils;
    913import org.openstreetmap.josm.data.osm.DataSet;
     
    1317import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1418import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    15 import org.openstreetmap.josm.testutils.JOSMTestRules;
    16 
    17 import java.util.Collection;
    18 import java.util.List;
    19 import java.util.stream.Collectors;
    20 
    21 import static org.junit.jupiter.api.Assertions.assertTrue;
     19import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     20import org.openstreetmap.josm.testutils.annotations.Projection;
     21import org.openstreetmap.josm.testutils.annotations.Territories;
    2222
    2323/**
    2424 * Performance test of {@code ValidationTask}.
    2525 */
     26@BasicPreferences
     27@Projection
     28@Territories
    2629class ValidationTaskPerformanceTest {
    2730
    2831    private List<org.openstreetmap.josm.data.validation.Test> tests;
    29 
    30     /**
    31      * Setup test.
    32      */
    33     @RegisterExtension
    34     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    35     public JOSMTestRules test = new JOSMTestRules().projection().territories().preferences();
    3632
    3733    /**
  • trunk/test/performance/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerPerformanceTest.java

    r17617 r18799  
    22package org.openstreetmap.josm.data.validation.tests;
    33
    4 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    54import org.junit.jupiter.api.BeforeEach;
    65import org.junit.jupiter.api.Test;
    7 import org.junit.jupiter.api.extension.RegisterExtension;
    86import org.openstreetmap.josm.PerformanceTestUtils;
    97import org.openstreetmap.josm.data.osm.DataSet;
    10 import org.openstreetmap.josm.testutils.JOSMTestRules;
     8import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     9import org.openstreetmap.josm.testutils.annotations.Projection;
     10import org.openstreetmap.josm.testutils.annotations.Territories;
    1111
    1212/**
    1313 * Performance test of {@code MapCSSTagChecker}.
    1414 */
     15@BasicPreferences
     16@Projection
     17@Territories
    1518class MapCSSTagCheckerPerformanceTest {
    1619
    1720    private MapCSSTagChecker tagChecker;
    1821    private DataSet dsCity;
    19 
    20     /**
    21      * Setup test.
    22      */
    23     @RegisterExtension
    24     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    25     public JOSMTestRules test = new JOSMTestRules().projection().territories().preferences();
    2622
    2723    /**
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r18562 r18799  
    88import static org.junit.jupiter.api.Assertions.fail;
    99import static org.junit.jupiter.api.Assumptions.assumeFalse;
     10import static org.junit.jupiter.api.Assumptions.assumeTrue;
    1011
    1112import java.awt.Component;
     
    7576 */
    7677public final class TestUtils {
     78    private static Boolean workingJMockit;
    7779
    7880    private TestUtils() {
     
    515517    @SuppressWarnings("null")
    516518    public static void assumeWorkingJMockit() {
    517         try {
    518             // Workaround to https://github.com/jmockit/jmockit1/issues/534
    519             // Inspired by https://issues.apache.org/jira/browse/SOLR-11606
    520             new WindowMocker();
    521             new JOptionPaneSimpleMocker();
    522         } catch (UnsupportedOperationException e) {
    523             assumeFalse(e != null);
    524         } finally {
    525             TestRunnerDecorator.cleanUpAllMocks();
    526         }
     519        if (workingJMockit == null) {
     520            try {
     521                // Workaround to https://github.com/jmockit/jmockit1/issues/534
     522                // Inspired by https://issues.apache.org/jira/browse/SOLR-11606
     523                new WindowMocker();
     524                new JOptionPaneSimpleMocker();
     525                workingJMockit = true;
     526            } catch (UnsupportedOperationException e) {
     527                workingJMockit = false;
     528            } finally {
     529                TestRunnerDecorator.cleanUpAllMocks();
     530            }
     531        }
     532        assumeTrue(workingJMockit);
    527533    }
    528534
  • trunk/test/unit/org/openstreetmap/josm/actions/SessionSaveActionTest.java

    r18690 r18799  
    1212
    1313import org.junit.jupiter.api.Test;
    14 import org.junit.jupiter.api.extension.RegisterExtension;
    1514import org.openstreetmap.josm.TestUtils;
    1615import org.openstreetmap.josm.gui.MainApplication;
     
    1817import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1918import org.openstreetmap.josm.io.session.SessionWriterTest;
    20 import org.openstreetmap.josm.testutils.JOSMTestRules;
     19import org.openstreetmap.josm.testutils.annotations.Main;
     20import org.openstreetmap.josm.testutils.annotations.Projection;
    2121import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
    22 
    23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2422
    2523/**
    2624 * Unit tests for class {@link SessionSaveAsAction}.
    2725 */
     26@Main
     27@Projection
    2828class SessionSaveActionTest {
    29     /**
    30      * Setup test.
    31      */
    32     @RegisterExtension
    33     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    34     public JOSMTestRules test = new JOSMTestRules().main().projection();
    35 
    3629    /**
    3730     * Unit test of {@link SessionSaveAction}
  • trunk/test/unit/org/openstreetmap/josm/actions/UploadActionTest.java

    r18485 r18799  
    1010import java.util.concurrent.TimeUnit;
    1111
    12 import org.junit.jupiter.api.BeforeAll;
    1312import org.junit.jupiter.api.Test;
    1413import org.junit.jupiter.api.extension.RegisterExtension;
     
    2524import org.openstreetmap.josm.testutils.JOSMTestRules;
    2625import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     26import org.openstreetmap.josm.testutils.annotations.Main;
     27import org.openstreetmap.josm.testutils.annotations.Projection;
     28import org.openstreetmap.josm.testutils.annotations.Territories;
    2729import org.openstreetmap.josm.testutils.mockers.WindowMocker;
    2830import org.openstreetmap.josm.tools.Logging;
    29 import org.openstreetmap.josm.tools.Territories;
    3031
    3132import mockit.Invocation;
     
    3839 */
    3940@BasicPreferences
     41@Main
     42@Projection
     43// Territories is needed due to test pollution. One of the listeners
     44// that may get registered on SelectionEventManager requires
     45// Territories. Rather unfortunately, we also need the external data to
     46// avoid the NPE.
     47@Territories(Territories.Initialize.ALL)
    4048class UploadActionTest {
    4149    // Only needed for layer cleanup. And user identity cleanup. And ensuring that data isn't accidentally uploaded.
    4250    // Note that the setUp method can be replaced by the @Territories extension, when that is merged.
    4351    @RegisterExtension
    44     static JOSMTestRules josmTestRules = new JOSMTestRules().main().projection().fakeAPI();
    45 
    46     @BeforeAll
    47     static void setUp() {
    48         // Territories is needed due to test pollution. One of the listeners
    49         // that may get registered on SelectionEventManager requires
    50         // Territories. Rather unfortunately, we also need the external data to
    51         // avoid the NPE.
    52         Territories.initialize();
    53     }
     52    static JOSMTestRules josmTestRules = new JOSMTestRules().fakeAPI();
    5453
    5554    /**
  • trunk/test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java

    r18723 r18799  
    6767
    6868    TestHandler handler;
     69    private ValidatorCLI validatorCLI;
    6970
    7071    @BeforeEach
     
    7475        this.handler = new TestHandler();
    7576        Logging.getLogger().addHandler(this.handler);
     77        validatorCLI = new ValidatorCLI();
    7678    }
    7779
     
    8688    @ValueSource(strings = {"resources/styles/standard/elemstyles.mapcss", "resources/styles/standard/potlatch2.mapcss"})
    8789    void testInternalMapcss(final String resourceLocation) {
    88         new ValidatorCLI().processArguments(new String[]{"--input", resourceLocation});
     90        validatorCLI.processArguments(new String[]{"--input", resourceLocation});
    8991        assertEquals(2, this.handler.logRecordList.size());
    9092        assertEquals(resourceLocation + " had no errors", this.handler.logRecordList.get(0).getMessage());
     
    111113    void testInternalValidatorMapcss(final String resourceLocation) {
    112114        final String path = Paths.get(temporaryDirectory.getPath(), resourceLocation).toString();
    113         new ValidatorCLI().processArguments(new String[]{"--input", path});
     115        validatorCLI.processArguments(new String[]{"--input", path});
    114116        assertEquals(2, this.handler.logRecordList.size(), this.handler.logRecordList.stream().map(LogRecord::getMessage).collect(
    115117                Collectors.joining(",\n")));
     
    123125        final String dataPath = TestUtils.getRegressionDataFile(13165, "13165.osm");
    124126        final String outputPath = Paths.get(temporaryDirectory.getPath(), "testBadDataTicket13165.geojson").toString();
    125         new ValidatorCLI().processArguments(new String[]{"--input", dataPath, "--output", outputPath});
     127        validatorCLI.processArguments(new String[]{"--input", dataPath, "--output", outputPath});
    126128        final File outputFile = new File(outputPath);
    127129        assertTrue(outputFile.exists());
     
    134136    @Test
    135137    void testBadDataPlusChangeFile() throws IOException {
    136         final ValidatorCLI validatorCLI = new ValidatorCLI();
    137138        // Write test data out
    138139        final String osmPath = Paths.get(temporaryDirectory.getPath(), "testBadDataPlusChangeFile.osm").toString();
     
    172173    void testNonRegression22898(final @TempDir Path preferencesLocation) throws IOException, ReflectiveOperationException {
    173174        AnnotationUtils.resetStaticClass(Config.class);
    174         final ValidatorCLI validatorCLI = new ValidatorCLI();
    175175        final Path preferences = preferencesLocation.resolve("preferences.xml");
    176176        try (OutputStream fos = Files.newOutputStream(preferences)) {
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r18761 r18799  
    1919import org.junit.jupiter.api.BeforeEach;
    2020import org.junit.jupiter.api.Test;
    21 import org.junit.jupiter.api.extension.RegisterExtension;
    2221import org.openstreetmap.josm.TestUtils;
    2322import org.openstreetmap.josm.command.ChangePropertyCommand;
     
    4342import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
    4443import org.openstreetmap.josm.io.OsmReader;
    45 import org.openstreetmap.josm.testutils.JOSMTestRules;
    4644import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    4745import org.openstreetmap.josm.testutils.annotations.Projection;
     46import org.openstreetmap.josm.testutils.annotations.Territories;
    4847import org.openstreetmap.josm.tools.Logging;
    49 
    50 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    5148
    5249/**
     
    5552@BasicPreferences
    5653@Projection
     54@Territories
    5755class MapCSSTagCheckerTest {
    58 
    59     /**
    60      * Setup test.
    61      */
    62     @RegisterExtension
    63     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    64     public JOSMTestRules test = new JOSMTestRules().territories();
    65 
    6656    /**
    6757     * Setup test.
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/UntaggedNodeTest.java

    r17275 r18799  
    88import java.io.InputStream;
    99
    10 import org.junit.jupiter.api.extension.RegisterExtension;
    1110import org.junit.jupiter.api.Test;
    1211import org.openstreetmap.josm.TestUtils;
     
    1413import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1514import org.openstreetmap.josm.io.OsmReader;
    16 import org.openstreetmap.josm.testutils.JOSMTestRules;
    17 
    18 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     15import org.openstreetmap.josm.testutils.annotations.Projection;
    1916
    2017/**
    2118 * Unit tests of {@code UntaggedNode} class.
    2219 */
     20@Projection
    2321class UntaggedNodeTest {
    2422
    2523    private final UntaggedNode test = new UntaggedNode();
    26 
    27     /**
    28      * Setup test.
    29      */
    30     @RegisterExtension
    31     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    32     public JOSMTestRules rules = new JOSMTestRules();
    3324
    3425    /**
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelperTest.java

    r17275 r18799  
    2121import javax.swing.table.DefaultTableModel;
    2222
    23 import org.junit.jupiter.api.extension.RegisterExtension;
    2423import org.junit.jupiter.api.Test;
    2524import org.openstreetmap.josm.TestUtils;
     
    3635import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    3736import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    38 import org.openstreetmap.josm.testutils.JOSMTestRules;
     37import org.openstreetmap.josm.testutils.annotations.Projection;
     38import org.openstreetmap.josm.testutils.annotations.Territories;
    3939import org.openstreetmap.josm.testutils.mockers.WindowMocker;
    40 
    41 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    4240
    4341/**
    4442 * Unit tests of {@link TagEditHelper} class.
    4543 */
     44@Projection
     45@Territories
    4646class TagEditHelperTest {
    47 
    48     /**
    49      * Setup tests
    50      */
    51     @RegisterExtension
    52     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    53     public JOSMTestRules test = new JOSMTestRules().territories().projection();
    54 
    5547    private static TagEditHelper newTagEditHelper() {
    5648        DefaultTableModel propertyData = new DefaultTableModel();
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java

    r18793 r18799  
    3232import org.openstreetmap.josm.testutils.annotations.Main;
    3333import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
     34import org.openstreetmap.josm.testutils.mockers.WindowMocker;
    3435
    3536/**
     
    142143            }
    143144        };
     145        new WindowMocker();
    144146
    145147        DataSet ds = new DataSet();
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/RenderingCLIAreaTest.java

    r18494 r18799  
    1212import org.hamcrest.CoreMatchers;
    1313import org.hamcrest.Matcher;
    14 import org.junit.jupiter.api.extension.RegisterExtension;
    1514import org.junit.jupiter.params.ParameterizedTest;
    1615import org.junit.jupiter.params.provider.MethodSource;
     
    1817import org.openstreetmap.josm.data.coor.ILatLon;
    1918import org.openstreetmap.josm.data.coor.LatLon;
    20 import org.openstreetmap.josm.testutils.JOSMTestRules;
    21 
    22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     19import org.openstreetmap.josm.testutils.annotations.Projection;
     20import org.openstreetmap.josm.testutils.annotations.Territories;
    2321
    2422/**
    2523 * Tests the method {@link RenderingCLI#determineRenderingArea(org.openstreetmap.josm.data.osm.DataSet)}.
    2624 */
     25@Projection
     26@Territories
    2727class RenderingCLIAreaTest {
    28     /**
    29      * Setup rule
    30      */
    31     @RegisterExtension
    32     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    33     public JOSMTestRules test = new JOSMTestRules().projection().territories();
    34 
    3528    public static Collection<Object[]> runs() {
    3629        Collection<Object[]> runs = new ArrayList<>();
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTestIT.java

    r18637 r18799  
    2020import java.util.Objects;
    2121import java.util.Set;
     22import java.util.concurrent.TimeUnit;
    2223import java.util.function.Consumer;
    2324import java.util.logging.Handler;
     
    2728import org.junit.jupiter.api.BeforeAll;
    2829import org.junit.jupiter.api.Test;
     30import org.junit.jupiter.api.Timeout;
    2931import org.junit.jupiter.api.extension.RegisterExtension;
    3032import org.junit.platform.commons.util.ReflectionUtils;
     
    4042import org.openstreetmap.josm.spi.preferences.Config;
    4143import org.openstreetmap.josm.testutils.JOSMTestRules;
     44import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     45import org.openstreetmap.josm.testutils.annotations.Main;
     46import org.openstreetmap.josm.testutils.annotations.Projection;
     47import org.openstreetmap.josm.testutils.annotations.Territories;
    4248import org.openstreetmap.josm.tools.Destroyable;
    4349import org.openstreetmap.josm.tools.Logging;
     
    4955 * Integration tests of {@link PluginHandler} class.
    5056 */
     57@BasicPreferences
     58@Main
     59@Projection
     60@Territories
     61@Timeout(value = 10, unit = TimeUnit.MINUTES)
    5162public class PluginHandlerTestIT {
    5263
     
    5768    @RegisterExtension
    5869    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    59     public static JOSMTestRules test = new JOSMTestRules().main().projection().preferences().https()
    60             .territories().timeout(10 * 60 * 1000);
     70    public static JOSMTestRules test = new JOSMTestRules().https();
    6171
    6272    /**
  • trunk/test/unit/org/openstreetmap/josm/tools/JosmDecimalFormatSymbolsProviderTest.java

    r18051 r18799  
    1515import org.junit.jupiter.api.BeforeAll;
    1616import org.junit.jupiter.api.Test;
    17 import org.junit.jupiter.api.extension.RegisterExtension;
    18 import org.openstreetmap.josm.testutils.JOSMTestRules;
    19 
    20 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2117
    2218/**
    2319 * Unit tests of {@link JosmDecimalFormatSymbolsProvider}.
    2420 */
     21@org.openstreetmap.josm.testutils.annotations.I18n
    2522class JosmDecimalFormatSymbolsProviderTest {
    26 
    27     /**
    28      * Setup rule.
    29      */
    30     @RegisterExtension
    31     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    32     public JOSMTestRules test = new JOSMTestRules();
    33 
    3423    @BeforeAll
    3524    static void beforeAll() throws IOException {
  • trunk/test/unit/org/openstreetmap/josm/tools/RightAndLefthandTrafficTest.java

    r17275 r18799  
    44import static org.junit.jupiter.api.Assertions.fail;
    55
    6 import org.junit.jupiter.api.extension.RegisterExtension;
    76import org.junit.jupiter.api.Test;
    87import org.openstreetmap.josm.data.coor.LatLon;
    9 import org.openstreetmap.josm.testutils.JOSMTestRules;
     8import org.openstreetmap.josm.testutils.annotations.Projection;
     9import org.openstreetmap.josm.testutils.annotations.Territories;
    1010
    11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1211import net.trajano.commons.testing.UtilityClassTestUtil;
    1312
     
    1514 * Unit tests of {@link RightAndLefthandTraffic} class.
    1615 */
     16@Projection
     17@Territories
    1718class RightAndLefthandTrafficTest {
    18     /**
    19      * Test rules.
    20      */
    21     @RegisterExtension
    22     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    23     public JOSMTestRules rules = new JOSMTestRules().projection().territories();
    24 
    2519    /**
    2620     * Tests that {@code RightAndLefthandTraffic} satisfies utility class criteria.
  • trunk/test/unit/org/openstreetmap/josm/tools/TerritoriesTest.java

    r17275 r18799  
    1414
    1515import org.junit.jupiter.api.Test;
    16 import org.junit.jupiter.api.extension.RegisterExtension;
    1716import org.openstreetmap.josm.TestUtils;
    1817import org.openstreetmap.josm.data.coor.LatLon;
    19 import org.openstreetmap.josm.testutils.JOSMTestRules;
     18import org.openstreetmap.josm.testutils.annotations.Projection;
    2019
    21 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2220import net.trajano.commons.testing.UtilityClassTestUtil;
    2321
     
    2523 * Unit tests of {@link Territories} class.
    2624 */
     25@Projection
     26@org.openstreetmap.josm.testutils.annotations.Territories
    2727class TerritoriesTest {
    28     /**
    29      * Test rules.
    30      */
    31     @RegisterExtension
    32     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    33     public JOSMTestRules rules = new JOSMTestRules().projection().territories();
    34 
    3528    /**
    3629     * Tests that {@code Territories} satisfies utility class criteria.
Note: See TracChangeset for help on using the changeset viewer.