Ignore:
Timestamp:
2023-10-03T16:25:42+02:00 (15 months ago)
Author:
taylor.smock
Message:

Fix #23212: Overpass query wizard should transform key: to ["key"] instead of [~"key"~""]

This is fixed by using ExactKeyValue instead of KeyValue for key: queries.
As a happy side effect, this significantly reduces the cost of key: queries.
In a test area ("Mesa County, Colorado"), this reduces the cpu time from 2600ms
to 200ms and reduces memory allocations from 425mb to effectively 0 for a name:
query.

In addition, this simplifies many equals methods by converting the following
pattern to Objects.equals(first, second):

if (first == null) {
    if (second != null) {
        return true;
    }
} else if (!first.equals(second))
    return false;
return true;

There are some additional changes, mostly related to documentation and lint
issues.

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java

    r18690 r18847  
    2222import org.junit.jupiter.api.Timeout;
    2323import org.junit.jupiter.params.ParameterizedTest;
     24import org.junit.jupiter.params.provider.MethodSource;
    2425import org.junit.jupiter.params.provider.ValueSource;
    2526import org.openstreetmap.josm.TestUtils;
     
    4546import org.openstreetmap.josm.gui.tagging.presets.items.Key;
    4647import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    47 import org.openstreetmap.josm.tools.Logging;
    4848
    4949import nl.jqno.equalsverifier.EqualsVerifier;
     
    745745    }
    746746
     747    static Set<Class<? extends Match>> testEqualsContract() {
     748        TestUtils.assumeWorkingEqualsVerifier();
     749        final Set<Class<? extends Match>> matchers = TestUtils.getJosmSubtypes(Match.class);
     750        assertTrue(matchers.size() >= 10, "There should be at least 10 matchers from JOSM core");
     751        return matchers;
     752    }
     753
    747754    /**
    748755     * Unit test of methods {@link Match#equals} and {@link Match#hashCode}, including all subclasses.
    749      */
    750     @Test
    751     void testEqualsContract() {
    752         TestUtils.assumeWorkingEqualsVerifier();
    753         Set<Class<? extends Match>> matchers = TestUtils.getJosmSubtypes(Match.class);
    754         assertTrue(matchers.size() >= 10); // if it finds less than 10 classes, something is broken
    755         for (Class<?> c : matchers) {
    756             Logging.debug(c.toString());
    757             EqualsVerifier.forClass(c).usingGetClass()
    758                 .suppress(Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT)
    759                 .withPrefabValues(TaggingPreset.class, newTaggingPreset("foo"), newTaggingPreset("bar"))
    760                 .verify();
    761         }
     756     * @param clazz The class to test
     757     */
     758    @ParameterizedTest
     759    @MethodSource
     760    void testEqualsContract(Class<? extends Match> clazz) {
     761        EqualsVerifier.forClass(clazz).usingGetClass()
     762            .suppress(Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT)
     763            .withPrefabValues(TaggingPreset.class, newTaggingPreset("foo"), newTaggingPreset("bar"))
     764            .verify();
    762765    }
    763766
  • trunk/test/unit/org/openstreetmap/josm/tools/SearchCompilerQueryWizardTest.java

    r17988 r18847  
    77import org.junit.jupiter.api.Disabled;
    88import org.junit.jupiter.api.Test;
    9 import org.junit.jupiter.api.extension.RegisterExtension;
    10 import org.openstreetmap.josm.testutils.JOSMTestRules;
    11 
    12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     9import org.openstreetmap.josm.testutils.annotations.I18n;
    1310
    1411/**
    1512 * Unit tests of {@link SearchCompilerQueryWizard} class.
    1613 */
     14@I18n("de")
    1715class SearchCompilerQueryWizardTest {
    18     /**
    19      * Base test environment is enough
    20      */
    21     @RegisterExtension
    22     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    23     public JOSMTestRules test = new JOSMTestRules().i18n("de");
    24 
    2516    private static String constructQuery(String s) {
    2617        return SearchCompilerQueryWizard.constructQuery(s);
     
    264255                "type:node AND (*=forward OR *=backward)");
    265256    }
     257
     258    /**
     259     * Test for ticket <a href="https://josm.openstreetmap.de/ticket/23212>#23212</a>.
     260     * {@code key:} search should become {@code nwr["key"]}
     261     */
     262    @Test
     263    void testTicket23212() {
     264        assertQueryEquals("  nwr[\"name\"];\n", "name:");
     265    }
    266266}
Note: See TracChangeset for help on using the changeset viewer.