Changeset 10222 in josm


Ignore:
Timestamp:
2016-05-15T21:14:06+02:00 (9 years ago)
Author:
Don-vip
Message:

findbugs - fix/suppress most of warnings reported in unit tests + enable low confidence warnings for core

Location:
trunk
Files:
44 edited

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r10171 r10222  
    676676                excludeFilter="tools/findbugs/josm-filter.xml"
    677677                effort="max"
     678                    reportLevel="low"
    678679                >
    679680            <sourcePath path="${base.dir}/src" />
  • trunk/scripts/SyncEditorImageryIndex.groovy

    r10077 r10222  
    2424import org.openstreetmap.josm.data.imagery.ImageryInfo
    2525import org.openstreetmap.josm.io.imagery.ImageryReader
     26
     27import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
    2628
    2729class SyncEditorImageryIndex {
     
    177179    }
    178180
     181    @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
    179182    void myprintln(String s) {
    180183        if(skipEntries.containsKey(s)) {
  • trunk/test/functional/org/openstreetmap/josm/io/MultiFetchServerObjectReaderTest.java

    r9655 r10222  
    1818import java.text.MessageFormat;
    1919import java.util.ArrayList;
     20import java.util.Locale;
    2021import java.util.logging.Logger;
    2122
     
    151152
    152153        String p = System.getProperties().getProperty("useCachedDataset");
    153         if (p != null && Boolean.parseBoolean(p.trim().toLowerCase())) {
     154        if (p != null && Boolean.parseBoolean(p.trim().toLowerCase(Locale.ENGLISH))) {
    154155            logger.info(MessageFormat.format("property ''{0}'' set, using cached dataset", "useCachedDataset"));
    155156            return;
  • trunk/test/functional/org/openstreetmap/josm/io/OsmServerBackreferenceReaderTest.java

    r9374 r10222  
    1818import java.text.MessageFormat;
    1919import java.util.HashSet;
     20import java.util.Locale;
    2021import java.util.Set;
    2122import java.util.logging.Logger;
     
    169170
    170171        String p = System.getProperty("useCachedDataset");
    171         if (p != null && Boolean.parseBoolean(p.trim().toLowerCase())) {
     172        if (p != null && Boolean.parseBoolean(p.trim().toLowerCase(Locale.ENGLISH))) {
    172173            logger.info(MessageFormat.format("property ''{0}'' set, using cached dataset", "useCachedDataset"));
    173174            return;
     
    516517        DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
    517518
    518         Set<Long> referringRelationsIds = new HashSet<>();
    519519        r = lookupRelation(referers, 6);
    520520        assertNotNull(r);
    521521        assertFalse(r.isIncomplete());
    522         referringRelationsIds.add(r.getId());
    523522        r = lookupRelation(referers, 7);
    524523        assertNotNull(r);
    525524        assertFalse(r.isIncomplete());
    526         referringRelationsIds.add(r.getId());
    527525        r = lookupRelation(referers, 8);
    528526        assertNotNull(r);
    529527        assertFalse(r.isIncomplete());
    530         referringRelationsIds.add(r.getId());
    531528        r = lookupRelation(referers, 9);
    532529        assertNotNull(r);
    533530        assertFalse(r.isIncomplete());
    534         referringRelationsIds.add(r.getId());
    535531
    536532        // all relations are fully loaded
  • trunk/test/functional/org/openstreetmap/josm/io/UploadStrategySelectionPanelTest.java

    r8514 r10222  
    2020public class UploadStrategySelectionPanelTest extends JFrame {
    2121
    22     private UploadStrategySelectionPanel uploadStrategySelectionPanel;
     22    protected UploadStrategySelectionPanel uploadStrategySelectionPanel;
    2323
    2424    protected void build()  {
     
    3737        tf.addActionListener(
    3838                new ActionListener() {
    39                     public void actionPerformed(ActionEvent arg0) {
     39                    @Override
     40                    public void actionPerformed(ActionEvent ae) {
    4041                        int n = 0;
    4142                        try {
  • trunk/test/performance/org/openstreetmap/josm/data/osm/KeyValuePerformanceTest.java

    r10002 r10222  
    2020import org.openstreetmap.josm.PerformanceTestUtils.PerformanceTestTimer;
    2121import org.openstreetmap.josm.data.osm.OsmDataGenerator.KeyValueDataGenerator;
     22
     23import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2224
    2325/**
     
    3840     */
    3941    @Rule
     42    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    4043    public Timeout globalTimeout = Timeout.seconds(15*60);
    4144
     
    5255     */
    5356    @Test
    54     public void meassureStringEqualsIntern() {
     57    @SuppressFBWarnings(value = "DM_STRING_CTOR", justification = "test Strings that are interned and those that are not")
     58    public void measureStringEqualsIntern() {
    5559        String str1Interned = "string1";
    5660        String str1InternedB = "string1";
     
    196200     */
    197201    @Test
     202    @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
    198203    public void testKeyValueGetKeysGet() {
    199204        for (double tagNodeRatio : TAG_NODE_RATIOS) {
  • trunk/test/performance/org/openstreetmap/josm/data/osm/RoundingPerformanceTest.java

    r7937 r10222  
    77import org.openstreetmap.josm.data.coor.LatLon;
    88import org.openstreetmap.josm.data.coor.LatLonTest;
     9
     10import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    911
    1012/**
     
    2224     */
    2325    @Test
     26    @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
    2427    public void test() {
    2528        final int n = 1000000;
  • trunk/test/performance/org/openstreetmap/josm/data/osm/visitor/paint/AbstractMapRendererPerformanceTestParent.java

    r10197 r10222  
    2424import org.openstreetmap.josm.io.OsmReader;
    2525
     26import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     27
    2628/**
    2729 * Abstract superclass of {@code StyledMapRendererPerformanceTest} and {@code WireframeMapRendererPerformanceTest}.
     
    3234    private static final int IMG_HEIGHT = 1050;
    3335
     36    @SuppressFBWarnings(value = "MS_PKGPROTECT")
    3437    protected static Graphics2D g;
     38    @SuppressFBWarnings(value = "MS_PKGPROTECT")
    3539    protected static BufferedImage img;
     40    @SuppressFBWarnings(value = "MS_PKGPROTECT")
    3641    protected static NavigatableComponent nc;
    3742    private static DataSet dsRestriction;
     
    4348     */
    4449    @Rule
     50    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    4551    public Timeout globalTimeout = Timeout.seconds(15*60);
    4652
     
    121127    }
    122128
    123     /** run this manually to verify that the rendering is set up properly */
     129    /**
     130     * run this manually to verify that the rendering is set up properly
     131     * @throws IOException if any I/O error occurs
     132     */
     133    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD")
    124134    private void dumpRenderedImage() throws IOException {
    125         File outputfile = new File("test-neubrandenburg.png");
    126         ImageIO.write(img, "png", outputfile);
     135        ImageIO.write(img, "png", new File("test-neubrandenburg.png"));
    127136    }
    128137}
  • trunk/test/performance/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRendererPerformanceTest.java

    r10197 r10222  
    99import org.junit.BeforeClass;
    1010import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
     11
     12import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1113
    1214/**
     
    2729    }
    2830
    29     /** run this manually to verify that the rendering is set up properly */
     31    /**
     32     * run this manually to verify that the rendering is set up properly
     33     * @throws IOException if any I/O error occurs
     34     */
     35    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD")
    3036    private void dumpRenderedImage() throws IOException {
    31         File outputfile = new File("test-neubrandenburg.png");
    32         ImageIO.write(img, "png", outputfile);
     37        ImageIO.write(img, "png", new File("test-neubrandenburg.png"));
    3338    }
    3439}
  • trunk/test/performance/org/openstreetmap/josm/gui/mappaint/MapRendererPerformanceTest.java

    r9793 r10222  
    1212import java.util.EnumMap;
    1313import java.util.List;
     14import java.util.Locale;
    1415import java.util.Map;
    1516
     
    4142import org.openstreetmap.josm.io.OsmReader;
    4243
     44import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     45
    4346public class MapRendererPerformanceTest {
    4447
     
    6568        ICON, SYMBOL, NODE_TEXT, LINE, LINE_TEXT, AREA;
    6669        public String label() {
    67             return name().toLowerCase();
     70            return name().toLowerCase(Locale.ENGLISH);
    6871        }
    6972    }
     
    7578     */
    7679    @Rule
     80    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    7781    public Timeout globalTimeout = Timeout.seconds(15*60);
    7882
     
    171175        private final List<Long> totalTimes = new ArrayList<>();
    172176
     177        @SuppressFBWarnings(value = "DM_GC")
    173178        public void run() throws IOException {
    174179            boolean checkScale = false;
     
    314319
    315320    public static void dumpTimes(StyledMapRenderer.BenchmarkData bd) {
    316         System.out.print(String.format("gen. %3d, sort %3d, draw %3d\n", bd.generateTime, bd.sortTime, bd.drawTime));
     321        System.out.print(String.format("gen. %3d, sort %3d, draw %3d%n", bd.generateTime, bd.sortTime, bd.drawTime));
    317322    }
    318323
  • trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSourceFilterTest.java

    r9771 r10222  
    1313import org.openstreetmap.josm.gui.mappaint.MultiCascade;
    1414
     15import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     16
    1517/**
    1618 * Tests how fast {@link MapCSSStyleSource} finds the right style candidates for one object.
     
    2123    private static final int TEST_RULE_COUNT = 10000;
    2224
    23     private class CssGenerator {
     25    private static class CssGenerator {
    2426        StringBuilder sb = new StringBuilder();
    2527        private KeyValueDataGenerator generator;
     
    8385     */
    8486    @Rule
     87    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    8588    public Timeout globalTimeout = Timeout.seconds(15*60);
    8689
  • trunk/test/performance/org/openstreetmap/josm/io/OsmReaderPerformanceTest.java

    r9491 r10222  
    2020import org.openstreetmap.josm.data.osm.DataSet;
    2121
     22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     23
    2224/**
    2325 * This test tests how fast we are at reading an OSM file.
     
    3537     */
    3638    @Rule
     39    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3740    public Timeout globalTimeout = Timeout.seconds(15*60);
    3841
  • trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java

    r10019 r10222  
    88import java.nio.file.Paths;
    99import java.text.MessageFormat;
     10import java.util.Locale;
    1011
    1112import org.openstreetmap.josm.data.projection.Projections;
     
    106107        // make sure we don't upload to or test against production
    107108        //
    108         String url = OsmApi.getOsmApi().getBaseUrl().toLowerCase().trim();
     109        String url = OsmApi.getOsmApi().getBaseUrl().toLowerCase(Locale.ENGLISH).trim();
    109110        if (url.startsWith("http://www.openstreetmap.org") || url.startsWith("http://api.openstreetmap.org")
    110111            || url.startsWith("https://www.openstreetmap.org") || url.startsWith("https://api.openstreetmap.org")) {
  • trunk/test/unit/org/openstreetmap/josm/MainTest.java

    r10200 r10222  
    1616import org.openstreetmap.josm.gui.MainApplication;
    1717import org.openstreetmap.josm.tools.WindowGeometry;
     18
     19import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1820
    1921/**
     
    5759     */
    5860    @Test
     61    @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
    5962    public void testLogs() {
    6063
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r9954 r10222  
    4747import org.openstreetmap.josm.io.Compression;
    4848
     49import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     50
    4951/**
    5052 * Various utils, useful for unit tests.
     
    105107     * @param array The array sorted for test purpose
    106108     */
     109    @SuppressFBWarnings(value = "RV_NEGATING_RESULT_OF_COMPARETO")
    107110    public static <T> void checkComparableContract(Comparator<T> comparator, T[] array) {
    108111        System.out.println("Validating Comparable contract on array of "+array.length+" elements");
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateCircleActionTest.java

    r9661 r10222  
    99import java.lang.reflect.Field;
    1010import java.lang.reflect.Method;
     11import java.security.AccessController;
     12import java.security.PrivilegedAction;
    1113import java.util.ArrayList;
    1214import java.util.Arrays;
     
    5658    public void addSelected(OsmPrimitive p, DataSet ds) {
    5759        try {
    58             Method method = ds.getClass()
     60            final Method method = ds.getClass()
    5961                .getDeclaredMethod("addSelected",
    6062                                   new Class<?>[] {Collection.class, boolean.class});
    61             method.setAccessible(true);
     63            AccessController.doPrivileged(new PrivilegedAction<Object>() {
     64                @Override
     65                public Object run() {
     66                    method.setAccessible(true);
     67                    return null;
     68                }
     69            });
    6270            method.invoke(ds, Collections.singleton(p), false);
    63         } catch (Exception e) {
     71        } catch (ReflectiveOperationException e) {
    6472            e.printStackTrace();
    6573            fail("Can't add OsmPrimitive to dataset: " + e.getMessage());
     
    162170            rlCache.setAccessible(true);
    163171            ConstantTrafficHand trafficHand = new ConstantTrafficHand(true);
    164             rlCache.set(null, new GeoPropertyIndex<Boolean>(trafficHand, 24));
    165         } catch (Exception e) {
     172            rlCache.set(null, new GeoPropertyIndex<>(trafficHand, 24));
     173        } catch (ReflectiveOperationException e) {
    166174            e.printStackTrace();
    167175            fail("Impossible to mock left/right hand database: " + e.getMessage());
  • trunk/test/unit/org/openstreetmap/josm/actions/UnJoinNodeWayActionTest.java

    r9661 r10222  
    2424     * Prepare the class for the test. The notification system must be disabled.
    2525     */
    26     public class UnJoinNodeWayActionTestClass extends UnJoinNodeWayAction {
     26    public static class UnJoinNodeWayActionTestClass extends UnJoinNodeWayAction {
    2727
    2828        /**
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/PostDownloadHandlerTest.java

    r9905 r10222  
    4747            @Override
    4848            public String[] getPatterns() {
    49                 return null;
     49                return new String[0];
    5050            }
    5151
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/MapViewMock.java

    r9669 r10222  
    1313
    1414class MapViewMock extends MapView {
    15     private final OsmDataLayer layer;
    16     private final DataSet currentDataSet;
     15    private final transient OsmDataLayer layer;
     16    private final transient DataSet currentDataSet;
    1717
    1818    MapViewMock(DataSet dataSet, OsmDataLayer layer) {
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java

    r9661 r10222  
    1010import java.awt.event.MouseEvent;
    1111import java.lang.reflect.Field;
     12import java.security.AccessController;
     13import java.security.PrivilegedAction;
    1214import java.util.Arrays;
    1315import java.util.Collection;
     
    2527import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2628
     29import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     30
    2731/**
    2832 * Unit tests for class {@link SelectAction}.
     
    3337     * Override some configuration variables without change in preferences.xml
    3438     */
    35     class PreferencesMock extends Preferences {
     39    static class PreferencesMock extends Preferences {
    3640        @Override
    3741        public synchronized int getInteger(String key, int def) {
     
    5054            super(mapFrame);
    5155            try {
    52                 Field mv = SelectAction.class.getDeclaredField("mv");
    53                 mv.setAccessible(true);
     56                final Field mv = SelectAction.class.getDeclaredField("mv");
     57                AccessController.doPrivileged(new PrivilegedAction<Object>() {
     58                    @Override
     59                    public Object run() {
     60                        mv.setAccessible(true);
     61                        return null;
     62                    }
     63                });
    5464                mv.set(this, new MapViewMock(dataSet, layer));
    55             } catch (Exception e) {
     65            } catch (ReflectiveOperationException e) {
    5666                e.printStackTrace();
    5767                fail("Can't setup testing environnement");
     
    8292     */
    8393    @Test
     94    @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
    8495    public void test10748() {
    8596        DataSet dataSet = new DataSet();
     
    137148            // As result of test, we must find a 2 nodes way, from EN(0, 0) to EN(100, 0)
    138149            assertTrue("Nodes are not merged", nodesMerged);
    139             assertSame(String.format("Expect exactly one way, found %d\n", dataSet.getWays().size()),
     150            assertSame(String.format("Expect exactly one way, found %d%n", dataSet.getWays().size()),
    140151                       dataSet.getWays().size(), 1);
    141152            Way rw = dataSet.getWays().iterator().next();
    142153            assertFalse("Way shouldn't be deleted\n", rw.isDeleted());
    143             assertSame(String.format("Way shouldn't have 2 nodes, %d found\n", w.getNodesCount()),
     154            assertSame(String.format("Way shouldn't have 2 nodes, %d found%n", w.getNodesCount()),
    144155                       rw.getNodesCount(), 2);
    145156            Node r1 = rw.firstNode();
     
    150161                r2 = tmp;
    151162            }
    152             assertSame(String.format("East should be 0, found %f\n", r1.getEastNorth().east()),
     163            assertSame(String.format("East should be 0, found %f%n", r1.getEastNorth().east()),
    153164                       Double.compare(r1.getEastNorth().east(), 0), 0);
    154             assertSame(String.format("East should be 100, found %f\n", r2.getEastNorth().east()),
     165            assertSame(String.format("East should be 100, found %f%n", r2.getEastNorth().east()),
    155166                       Double.compare(r2.getEastNorth().east(), 100), 0);
    156167        } finally {
  • trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java

    r10219 r10222  
    1313import org.junit.Test;
    1414import org.openstreetmap.josm.JOSMFixture;
     15
     16import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1517
    1618/**
     
    5961            this.attributes = attributes;
    6062            this.ready = true;
    61             this.notify();
     63            this.notifyAll();
    6264        }
    6365    }
     
    7173    }
    7274
     75    /**
     76     * Test status codes
     77     * @throws InterruptedException in case of thread interruption
     78     * @throws IOException in case of I/O error
     79     */
    7380    @Test
    74     public void testStatusCodes() throws Exception {
     81    public void testStatusCodes() throws IOException, InterruptedException {
    7582        doTestStatusCode(200);
    7683        // can't test for 3xx, as httpstat.us redirects finally to 200 page
     
    8592    }
    8693
     94    /**
     95     * Test unknown host
     96     * @throws InterruptedException in case of thread interruption
     97     * @throws IOException in case of I/O error
     98     */
    8799    @Test
    88     public void testUnknownHost() throws Exception {
     100    @SuppressFBWarnings(value = "WA_NOT_IN_LOOP")
     101    public void testUnknownHost() throws IOException, InterruptedException {
    89102        TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown");
    90103        Listener listener = new Listener();
     
    98111    }
    99112
    100     private void doTestStatusCode(int responseCode) throws Exception {
     113    @SuppressFBWarnings(value = "WA_NOT_IN_LOOP")
     114    private void doTestStatusCode(int responseCode) throws IOException, InterruptedException {
    101115        TestCachedTileLoaderJob job = getStatusLoaderJob(responseCode);
    102116        Listener listener = new Listener();
  • trunk/test/unit/org/openstreetmap/josm/data/coor/LatLonTest.java

    r9879 r10222  
    77import org.junit.Test;
    88import org.openstreetmap.josm.JOSMFixture;
     9
     10import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    911
    1012/**
     
    2628     * Lat/Lon sample values for unit tests
    2729     */
     30    @SuppressFBWarnings(value = "MS_PKGPROTECT")
    2831    public static final double[] SAMPLE_VALUES = new double[]{
    2932            -180.0, -179.9, -179.6, -179.5, -179.4, -179.1, -179.0, -100.0, -99.9, -10.0, -9.9, -1.0, -0.1,
  • trunk/test/unit/org/openstreetmap/josm/data/oauth/OAuthParametersTest.java

    r10201 r10222  
    1212import org.openstreetmap.josm.io.OsmApi;
    1313
     14import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1415import nl.jqno.equalsverifier.EqualsVerifier;
    1516
     
    3132     */
    3233    @Test
     34    @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
    3335    public void testCreateDefault() {
    3436        OAuthParameters def = OAuthParameters.createDefault();
  • trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetCacheTest.groovy

    r8510 r10222  
    99
    1010    @Test
    11     public void test_Constructor() {
     11    public void testConstructor() {
    1212        ChangesetCache cache = ChangesetCache.getInstance()
    1313        assert cache != null
     
    1515
    1616    @Test
    17     public void test_addAndRemoveListeners() {
     17    public void testAddAndRemoveListeners() {
    1818        ChangesetCache cache = ChangesetCache.getInstance()
    1919        cache.clear()
     
    3838
    3939    @Test
    40     public void update_get_remove_cycle() {
     40    public void updateGetRemoveCycle() {
    4141        ChangesetCache cache = ChangesetCache.getInstance()
    4242        cache.clear()
     
    9797
    9898    @Test
    99     public void fireingEvents_AddAChangeset() {
     99    public void fireingEventsAddAChangeset() {
    100100        ChangesetCache cache = ChangesetCache.getInstance()
    101101        cache.clear()
     
    118118
    119119    @Test
    120     public void fireingEvents_UpdateChangeset() {
     120    public void fireingEventsUpdateChangeset() {
    121121        ChangesetCache cache = ChangesetCache.getInstance()
    122122        cache.clear()
     
    141141
    142142    @Test
    143     public void fireingEvents_RemoveChangeset() {
     143    public void fireingEventsRemoveChangeset() {
    144144        ChangesetCache cache = ChangesetCache.getInstance()
    145145        cache.clear()
  • trunk/test/unit/org/openstreetmap/josm/data/osm/FilterTest.java

    r9214 r10222  
    161161                break;
    162162            }
     163            default: throw new AssertionError();
    163164            }
    164165
  • trunk/test/unit/org/openstreetmap/josm/data/osm/MultipolygonBuilderTest.java

    r9666 r10222  
    1414import org.openstreetmap.josm.io.OsmReader;
    1515
     16import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     17
    1618/**
    1719 * Unit tests of the {@code MultipolygonBuilder} class.
     
    2325     */
    2426    @Rule
     27    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    2528    public Timeout globalTimeout = Timeout.seconds(15);
    2629
  • trunk/test/unit/org/openstreetmap/josm/data/osm/OsmPrimitiveKeyHandlingTest.java

    r9459 r10222  
    1010import org.openstreetmap.josm.JOSMFixture;
    1111import org.openstreetmap.josm.data.coor.LatLon;
     12
     13import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1214
    1315/**
     
    7274     */
    7375    @Test
     76    @SuppressFBWarnings(value = "DM_STRING_CTOR", justification = "test that equals is used and not ==")
    7477    public void remove() {
    7578        Node n = new Node();
  • trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java

    r9716 r10222  
    3434
    3535    @Test
    36     public void testBBox() {
     36    public void testBbox() {
    3737        DataSet ds = new DataSet();
    3838
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java

    r10219 r10222  
    222222            Process process = pb.start();
    223223            OutputStream stdin = process.getOutputStream();
    224             final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin, StandardCharsets.UTF_8));
    225224            InputStream stdout = process.getInputStream();
    226             final BufferedReader reader = new BufferedReader(new InputStreamReader(stdout, StandardCharsets.UTF_8));
    227             String input = String.format("%.9f %.9f\n", ll.lon(), ll.lat());
    228             writer.write(input);
    229             writer.close();
    230             output = reader.readLine();
    231             reader.close();
     225            try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin, StandardCharsets.UTF_8))) {
     226                writer.write(String.format("%.9f %.9f%n", ll.lon(), ll.lat()));
     227            }
     228            try (BufferedReader reader = new BufferedReader(new InputStreamReader(stdout, StandardCharsets.UTF_8))) {
     229                output = reader.readLine();
     230            }
    232231        } catch (IOException e) {
    233232            System.err.println("Error: Running external command failed: " + e + "\nCommand was: "+Utils.join(" ", args));
  • trunk/test/unit/org/openstreetmap/josm/data/validation/routines/DomainValidatorTestIT.java

    r10219 r10222  
    4848import org.junit.Test;
    4949
     50import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     51
    5052/**
    5153 * Integration tests for the DomainValidator.
     
    8284        download(htmlFile, "http://www.iana.org/domains/root/db", timestamp);
    8385
    84         BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(txtFile), StandardCharsets.UTF_8));
    85         String line;
    86         final String header;
    87         line = br.readLine(); // header
    88         if (line != null && line.startsWith("# Version ")) {
    89             header = line.substring(2);
    90         } else {
    91             br.close();
    92             throw new IOException("File does not have expected Version header");
    93         }
    94         final boolean generateUnicodeTlds = false; // Change this to generate Unicode TLDs as well
    95 
    96         // Parse html page to get entries
    97         Map<String, String[]> htmlInfo = getHtmlInfo(htmlFile);
    98         Map<String, String> missingTLD = new TreeMap<>(); // stores entry and comments as String[]
    99         Map<String, String> missingCC = new TreeMap<>();
    100         while ((line = br.readLine()) != null) {
    101             if (!line.startsWith("#")) {
    102                 final String unicodeTld; // only different from asciiTld if that was punycode
    103                 final String asciiTld = line.toLowerCase(Locale.ENGLISH);
    104                 if (line.startsWith("XN--")) {
    105                     unicodeTld = IDN.toUnicode(line);
    106                 } else {
    107                     unicodeTld = asciiTld;
    108                 }
    109                 if (!dv.isValidTld(asciiTld)) {
    110                     String[] info = htmlInfo.get(asciiTld);
    111                     if (info != null) {
    112                         String type = info[0];
    113                         String comment = info[1];
    114                         if ("country-code".equals(type)) { // Which list to use?
    115                             missingCC.put(asciiTld, unicodeTld + " " + comment);
    116                             if (generateUnicodeTlds) {
    117                                 missingCC.put(unicodeTld, asciiTld + " " + comment);
     86        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(txtFile), StandardCharsets.UTF_8))) {
     87            String line;
     88            final String header;
     89            line = br.readLine(); // header
     90            if (line != null && line.startsWith("# Version ")) {
     91                header = line.substring(2);
     92            } else {
     93                throw new IOException("File does not have expected Version header");
     94            }
     95            final boolean generateUnicodeTlds = false; // Change this to generate Unicode TLDs as well
     96
     97            // Parse html page to get entries
     98            Map<String, String[]> htmlInfo = getHtmlInfo(htmlFile);
     99            Map<String, String> missingTLD = new TreeMap<>(); // stores entry and comments as String[]
     100            Map<String, String> missingCC = new TreeMap<>();
     101            while ((line = br.readLine()) != null) {
     102                if (!line.startsWith("#")) {
     103                    final String unicodeTld; // only different from asciiTld if that was punycode
     104                    final String asciiTld = line.toLowerCase(Locale.ENGLISH);
     105                    if (line.startsWith("XN--")) {
     106                        unicodeTld = IDN.toUnicode(line);
     107                    } else {
     108                        unicodeTld = asciiTld;
     109                    }
     110                    if (!dv.isValidTld(asciiTld)) {
     111                        String[] info = htmlInfo.get(asciiTld);
     112                        if (info != null) {
     113                            String type = info[0];
     114                            String comment = info[1];
     115                            if ("country-code".equals(type)) { // Which list to use?
     116                                missingCC.put(asciiTld, unicodeTld + " " + comment);
     117                                if (generateUnicodeTlds) {
     118                                    missingCC.put(unicodeTld, asciiTld + " " + comment);
     119                                }
     120                            } else {
     121                                missingTLD.put(asciiTld, unicodeTld + " " + comment);
     122                                if (generateUnicodeTlds) {
     123                                    missingTLD.put(unicodeTld, asciiTld + " " + comment);
     124                                }
    118125                            }
    119126                        } else {
    120                             missingTLD.put(asciiTld, unicodeTld + " " + comment);
    121                             if (generateUnicodeTlds) {
    122                                 missingTLD.put(unicodeTld, asciiTld + " " + comment);
    123                             }
    124                         }
     127                            System.err.println("Expected to find HTML info for "+ asciiTld);
     128                        }
     129                    }
     130                    ianaTlds.add(asciiTld);
     131                    // Don't merge these conditions; generateUnicodeTlds is final so needs to be separate to avoid a warning
     132                    if (generateUnicodeTlds) {
     133                        if (!unicodeTld.equals(asciiTld)) {
     134                            ianaTlds.add(unicodeTld);
     135                        }
     136                    }
     137                }
     138            }
     139            // List html entries not in TLD text list
     140            for (String key : (new TreeMap<>(htmlInfo)).keySet()) {
     141                if (!ianaTlds.contains(key)) {
     142                    if (isNotInRootZone(key)) {
     143                        System.out.println("INFO: HTML entry not yet in root zone: "+key);
    125144                    } else {
    126                         System.err.println("Expected to find HTML info for "+ asciiTld);
    127                     }
    128                 }
    129                 ianaTlds.add(asciiTld);
    130                 // Don't merge these conditions; generateUnicodeTlds is final so needs to be separate to avoid a warning
    131                 if (generateUnicodeTlds) {
    132                     if (!unicodeTld.equals(asciiTld)) {
    133                         ianaTlds.add(unicodeTld);
    134                     }
    135                 }
    136             }
    137         }
    138         br.close();
    139         // List html entries not in TLD text list
    140         for (String key : (new TreeMap<>(htmlInfo)).keySet()) {
    141             if (!ianaTlds.contains(key)) {
    142                 if (isNotInRootZone(key)) {
    143                     System.out.println("INFO: HTML entry not yet in root zone: "+key);
    144                 } else {
    145                     System.err.println("WARN: Expected to find text entry for html: "+key);
    146                 }
    147             }
    148         }
    149         if (!missingTLD.isEmpty()) {
    150             printMap(header, missingTLD, "TLD");
    151             fail("missing TLD");
    152         }
    153         if (!missingCC.isEmpty()) {
    154             printMap(header, missingCC, "CC");
    155             fail("missing CC");
     145                        System.err.println("WARN: Expected to find text entry for html: "+key);
     146                    }
     147                }
     148            }
     149            if (!missingTLD.isEmpty()) {
     150                printMap(header, missingTLD, "TLD");
     151                fail("missing TLD");
     152            }
     153            if (!missingCC.isEmpty()) {
     154                printMap(header, missingCC, "CC");
     155                fail("missing CC");
     156            }
    156157        }
    157158        // Check if internal tables contain any additional entries
     
    175176    }
    176177
     178    @SuppressFBWarnings(value = "PERFORMANCE")
    177179    private static Map<String, String[]> getHtmlInfo(final File f) throws IOException {
    178180        final Map<String, String[]> info = new HashMap<>();
     
    186188        final Pattern comment = Pattern.compile("\\s+<td>([^<]+)</td>");
    187189
    188         final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8));
    189         String line;
    190         while ((line = br.readLine()) != null) {
    191             Matcher m = domain.matcher(line);
    192             if (m.lookingAt()) {
    193                 String dom = m.group(1);
    194                 String typ = "??";
    195                 String com = "??";
    196                 line = br.readLine();
    197                 while (line != null && line.matches("^\\s*$")) { // extra blank lines introduced
     190        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8))) {
     191            String line;
     192            while ((line = br.readLine()) != null) {
     193                Matcher m = domain.matcher(line);
     194                if (m.lookingAt()) {
     195                    String dom = m.group(1);
     196                    String typ = "??";
     197                    String com = "??";
    198198                    line = br.readLine();
    199                 }
    200                 Matcher t = type.matcher(line);
    201                 if (t.lookingAt()) {
    202                     typ = t.group(1);
    203                     line = br.readLine();
    204                     if (line != null && line.matches("\\s+<!--.*")) {
    205                         while (line != null && !line.matches(".*-->.*")) {
     199                    while (line != null && line.matches("^\\s*$")) { // extra blank lines introduced
     200                        line = br.readLine();
     201                    }
     202                    Matcher t = type.matcher(line);
     203                    if (t.lookingAt()) {
     204                        typ = t.group(1);
     205                        line = br.readLine();
     206                        if (line != null && line.matches("\\s+<!--.*")) {
     207                            while (line != null && !line.matches(".*-->.*")) {
     208                                line = br.readLine();
     209                            }
    206210                            line = br.readLine();
    207211                        }
    208                         line = br.readLine();
    209                     }
    210                     // Should have comment; is it wrapped?
    211                     while (line != null && !line.matches(".*</td>.*")) {
    212                         line += " " +br.readLine();
    213                     }
    214                     Matcher n = comment.matcher(line);
    215                     if (n.lookingAt()) {
    216                         com = n.group(1);
    217                     }
    218                     // Don't save unused entries
    219                     if (com.contains("Not assigned") || com.contains("Retired") || typ.equals("test")) {
    220 //                        System.out.println("Ignored: " + typ + " " + dom + " " +com);
     212                        // Should have comment; is it wrapped?
     213                        while (line != null && !line.matches(".*</td>.*")) {
     214                            line += " " +br.readLine();
     215                        }
     216                        Matcher n = comment.matcher(line);
     217                        if (n.lookingAt()) {
     218                            com = n.group(1);
     219                        }
     220                        // Don't save unused entries
     221                        if (com.contains("Not assigned") || com.contains("Retired") || typ.equals("test")) {
     222    //                        System.out.println("Ignored: " + typ + " " + dom + " " +com);
     223                        } else {
     224                            info.put(dom.toLowerCase(Locale.ENGLISH), new String[]{typ, com});
     225    //                        System.out.println("Storing: " + typ + " " + dom + " " +com);
     226                        }
    221227                    } else {
    222                         info.put(dom.toLowerCase(Locale.ENGLISH), new String[]{typ, com});
    223 //                        System.out.println("Storing: " + typ + " " + dom + " " +com);
    224                     }
    225                 } else {
    226                     System.err.println("Unexpected type: " + line);
    227                 }
    228             }
    229         }
    230         br.close();
     228                        System.err.println("Unexpected type: " + line);
     229                    }
     230                }
     231            }
     232        }
    231233        return info;
    232234    }
     
    262264            System.out.println("Downloading " + tldurl);
    263265            byte[] buff = new byte[1024];
    264             InputStream is = hc.getInputStream();
    265 
    266             FileOutputStream fos = new FileOutputStream(f);
    267             int len;
    268             while ((len = is.read(buff)) != -1) {
    269                 fos.write(buff, 0, len);
    270             }
    271             fos.close();
    272             is.close();
     266            try (InputStream is = hc.getInputStream();
     267                 FileOutputStream fos = new FileOutputStream(f)) {
     268                int len;
     269                while ((len = is.read(buff)) != -1) {
     270                    fos.write(buff, 0, len);
     271                }
     272            }
    273273            System.out.println("Done");
    274274        }
  • trunk/test/unit/org/openstreetmap/josm/data/validation/routines/EmailValidatorTest.java

    r10202 r10222  
    3737     * rules from the xml file.
    3838     */
    39     protected static String FORM_KEY = "emailForm";
     39    protected static final String FORM_KEY = "emailForm";
    4040
    4141    /**
    4242     * The key used to retrieve the validator action.
    4343     */
    44     protected static String ACTION = "email";
     44    protected static final String ACTION = "email";
    4545
    4646    private EmailValidator validator;
  • trunk/test/unit/org/openstreetmap/josm/data/validation/routines/UrlValidatorTest.java

    r10133 r10222  
    3131public class UrlValidatorTest {
    3232
    33    private final boolean printStatus = false;
    34    private final boolean printIndex = false; //print index that indicates current scheme,host,port,path, query test were using.
     33   private static final boolean printStatus = false;
     34   private static final boolean printIndex = false; //print index that indicates current scheme,host,port,path, query test were using.
    3535
    3636   /**
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MultipolygonTestTest.java

    r9490 r10222  
    6565        MULTIPOLYGON_TEST.startTest(null);
    6666
    67         List<Node> nodes = new ArrayList<>();
    68         nodes.add(new Node(new LatLon(0, 1)));
    69         nodes.add(new Node(new LatLon(0, 2)));
    70 
    7167        // Erroneous tag
    7268        Way w = createUnclosedWay("amenity=parking");
  • trunk/test/unit/org/openstreetmap/josm/gui/DefaultNameFormatterTest.java

    r10218 r10222  
    2626import org.xml.sax.SAXException;
    2727
     28import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     29
    2830/**
    2931 * Unit tests of {@link DefaultNameFormatter} class.
     
    4648     */
    4749    @Test
     50    @SuppressFBWarnings(value = "ITA_INEFFICIENT_TO_ARRAY")
    4851    public void testTicket9632() throws IllegalDataException, IOException, SAXException {
    4952        String source = "http://josm.openstreetmap.de/josmfile?page=Presets/BicycleJunction&amp;preset";
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackActionTest.java

    r9958 r10222  
    4343     */
    4444    @Test
    45     public void testTmsLayer() throws Exception {
     45    public void testTMSLayer() throws Exception {
    4646        // Create new TMS layer and clear cache
    4747        TMSLayer layer = new TMSLayer(new ImageryInfo("OSM TMS", "https://a.tile.openstreetmap.org/{zoom}/{x}/{y}.png", "tms", null, null));
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTestIT.java

    r9868 r10222  
    2727import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
    2828
     29import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     30
    2931/**
    3032 * Integration tests of {@link MapPaintPreference} class.
     
    3638     */
    3739    @Rule
     40    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3841    public Timeout globalTimeout = Timeout.seconds(10*60);
    3942
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreferenceTestIT.java

    r9918 r10222  
    2222import org.xml.sax.SAXException;
    2323
     24import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     25
    2426/**
    2527 * Integration tests of {@link TaggingPresetPreference} class.
     
    3133     */
    3234    @Rule
     35    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3336    public Timeout globalTimeout = Timeout.seconds(10*60);
    3437
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java

    r8863 r10222  
    6262            @Override
    6363            public String apply(TaggingPresetItem x) {
    64                 return ((Key) x).key;
     64                return x instanceof Key ? ((Key) x).key : null;
    6565            }
    6666        });
  • trunk/test/unit/org/openstreetmap/josm/io/ChangesetQueryUrlParserTest.groovy

    r8510 r10222  
    1212
    1313    @Test
    14     public void test_constructor() {
    15         ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
    16     }
    17 
    18     @Test
    19     public void test_parse_basic() {
     14    public void testConstructor() {
     15        ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
     16    }
     17
     18    @Test
     19    public void testParseBasic() {
    2020        ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
    2121
     
    3333
    3434    @Test
    35     public void test_uid() {
     35    public void testUid() {
    3636        ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
    3737        def ChangesetQuery q
     
    5555
    5656    @Test
    57     public void test_display_name() {
     57    public void testDisplayName() {
    5858        ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
    5959        def ChangesetQuery q
     
    6565    }
    6666
    67 
    68     @Test
    69     public void test_open() {
     67    @Test
     68    public void testOpen() {
    7069        ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
    7170        def ChangesetQuery q
     
    8887
    8988    @Test
    90     public void test_closed() {
     89    public void testClosed() {
    9190        ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
    9291        def ChangesetQuery q
     
    108107    }
    109108
    110 
    111     @Test
    112     public void test_uid_and_display_name() {
     109    @Test
     110    public void testUidAndDisplayName() {
    113111        ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
    114112        def ChangesetQuery q
     
    121119
    122120    @Test
    123     public void test_time() {
     121    public void testTime() {
    124122        ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
    125123        def ChangesetQuery q
     
    151149
    152150    @Test
    153     public void test_bbox() {
     151    public void testBbox() {
    154152        ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
    155153        def ChangesetQuery q
     
    185183
    186184    @Test
    187     public void test_changeset_ids() {
     185    public void testChangesetIds() {
    188186        ChangesetQueryUrlParser parser = new ChangesetQueryUrlParser();
    189187        def ChangesetQuery q
  • trunk/test/unit/org/openstreetmap/josm/io/DiffResultProcessorTest.groovy

    r8510 r10222  
    2222        // these calls should not fail
    2323        //
    24         def DiffResultProcessor processor  = new DiffResultProcessor(null)
    25         processor  = new DiffResultProcessor([])
    26         processor  = new DiffResultProcessor([n])
     24        new DiffResultProcessor(null)
     25        new DiffResultProcessor([])
     26        new DiffResultProcessor([n])
    2727    }
    2828
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r10208 r10222  
    7070                @Override
    7171                public X509Certificate[] getAcceptedIssuers() {
    72                     return null;
     72                    return new X509Certificate[0];
    7373                }
    7474
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTestIT.java

    r10123 r10222  
    2020import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2121
     22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     23
    2224/**
    2325 * Integration tests of {@link PluginHandler} class.
     
    2931     */
    3032    @Rule
     33    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3134    public Timeout globalTimeout = Timeout.seconds(10*60);
    3235
  • trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java

    r9672 r10222  
    8686    @Test
    8787    public void testReadDirection() {
    88         Double direction = ExifReader.readDirection(directionSampleFile);
    89         assertEquals(new Double(46.5), direction);
     88        assertEquals(Double.valueOf(46.5), ExifReader.readDirection(directionSampleFile));
    9089    }
    9190
  • trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java

    r10133 r10222  
    1414import org.openstreetmap.josm.JOSMFixture;
    1515import org.openstreetmap.josm.tools.UncheckedParseException;
     16
     17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1618
    1719/**
     
    192194     */
    193195    @Test
     196    @SuppressFBWarnings(value = "ISC_INSTANTIATE_STATIC_CLASS")
    194197    public void testCoverage() {
    195198        assertNotNull(new DateUtils());
Note: See TracChangeset for help on using the changeset viewer.