Changeset 11324 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2016-11-27T05:16:30+01:00 (8 years ago)
Author:
Don-vip
Message:

findbugs

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
1 added
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r11104 r11324  
    1010import java.io.InputStream;
    1111import java.lang.reflect.Field;
     12import java.security.AccessController;
     13import java.security.PrivilegedAction;
    1214import java.util.Arrays;
    1315import java.util.Collection;
     
    7981     */
    8082    public static InputStream getRegressionDataStream(int ticketid, String filename) throws IOException {
    81         return Compression.getUncompressedFileInputStream(new File(getRegressionDataDir(ticketid) + '/' + filename));
     83        return Compression.getUncompressedFileInputStream(new File(getRegressionDataDir(ticketid), filename));
    8284    }
    8385
     
    173175    public static Object getPrivateField(Object obj, String fieldName) throws ReflectiveOperationException {
    174176        Field f = obj.getClass().getDeclaredField(fieldName);
    175         f.setAccessible(true);
     177        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
     178            f.setAccessible(true);
     179            return null;
     180        });
    176181        return f.get(obj);
    177182    }
  • trunk/test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java

    r10443 r11324  
    2020import org.openstreetmap.josm.testutils.JOSMTestRules;
    2121
     22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     23
    2224/**
    2325 * Unit tests for class {@link SelectByInternalPointAction}.
     
    2931     */
    3032    @Rule
     33    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3134    public JOSMTestRules rules = new JOSMTestRules().preferences().projection();
    3235
  • trunk/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java

    r11192 r11324  
    2727import org.openstreetmap.josm.tools.date.DateUtils;
    2828
     29import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     30
    2931/**
    3032 * Unit tests for class {@link SearchCompiler}.
     
    3638     */
    3739    @Rule
     40    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3841    public JOSMTestRules test = new JOSMTestRules().preferences();
    3942
  • trunk/test/unit/org/openstreetmap/josm/data/AutosaveTaskTest.java

    r11035 r11324  
    88import static org.junit.Assert.assertTrue;
    99
     10import java.io.BufferedWriter;
    1011import java.io.File;
    11 import java.io.FileWriter;
    12 import java.io.FilenameFilter;
    1312import java.io.IOException;
     13import java.nio.charset.StandardCharsets;
    1414import java.nio.file.Files;
    1515import java.nio.file.Paths;
     
    143143
    144144    private int countFiles() {
    145         return task.getAutosaveDir().toFile().list(new FilenameFilter() {
    146             @Override
    147             public boolean accept(File dir, String name) {
    148                 return name.endsWith(".osm");
    149             }
    150         }).length;
     145        String[] files = task.getAutosaveDir().toFile().list((dir, name) -> name.endsWith(".osm"));
     146        return files != null ? files.length : 0;
    151147    }
    152148
     
    194190    public void testDiscardUnsavedLayersIgnoresCurrentInstance() throws IOException {
    195191        runAutosaveTaskSeveralTimes(1);
    196         try (FileWriter file = new FileWriter(new File(task.getAutosaveDir().toFile(), "any_other_file.osm"))) {
     192        try (BufferedWriter file = Files.newBufferedWriter(
     193                new File(task.getAutosaveDir().toFile(), "any_other_file.osm").toPath(), StandardCharsets.UTF_8)) {
    197194            file.append("");
    198195        }
     
    237234    public void testRecoverLayers() throws Exception {
    238235        runAutosaveTaskSeveralTimes(1);
    239         try (FileWriter file = new FileWriter(new File(task.getAutosaveDir().toFile(), "any_other_file.osm"))) {
     236        try (BufferedWriter file = Files.newBufferedWriter(
     237                new File(task.getAutosaveDir().toFile(), "any_other_file.osm").toPath(), StandardCharsets.UTF_8)) {
    240238            file.append("<?xml version=\"1.0\"?><osm version=\"0.6\"><node id=\"1\" lat=\"1\" lon=\"2\" version=\"1\"/></osm>");
    241239        }
  • trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java

    r10962 r11324  
    4545            File cacheFile = new File("foobar/testUseBigDiskFile_BLOCK_v2.data");
    4646            if (!cacheFile.exists()) {
    47                 cacheFile.createNewFile();
     47                if (!cacheFile.createNewFile()) {
     48                    System.err.println("Unable to create " + cacheFile.getAbsolutePath());
     49                }
    4850            }
    4951            try (FileOutputStream fileOutputStream = new FileOutputStream(cacheFile, false)) {
  • trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetTest.java

    r11121 r11324  
    3131     */
    3232    @Test
     33    @SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS")
    3334    public void testSetKeys() {
    3435        final Changeset cs = new Changeset();
  • trunk/test/unit/org/openstreetmap/josm/data/osm/NodeDataTest.java

    r10946 r11324  
    1515import org.openstreetmap.josm.data.coor.LatLon;
    1616
     17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     18
    1719public class NodeDataTest {
    1820
     21    @SuppressFBWarnings(value = "OBJECT_DESERIALIZATION")
    1922    private static NodeData serializeUnserialize(NodeData data) throws IOException, ClassNotFoundException {
    2023        try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  • trunk/test/unit/org/openstreetmap/josm/data/osm/QuadBucketsTest.java

    r11269 r11324  
    44import java.io.FileInputStream;
    55import java.io.InputStream;
     6import java.security.SecureRandom;
    67import java.util.ArrayList;
    78import java.util.Arrays;
     
    193194
    194195        // force splits in quad buckets
    195         Random random = new Random(31);
     196        Random random = new SecureRandom();
    196197        for (int i = 0; i < NUM_COMPLETE_WAYS; i++) {
    197198            Way w = new Way(wayId++);
     
    213214
    214215        // add some incomplete nodes
    215         List<Node> incompleteNodes = new ArrayList<>();
    216216        for (int i = 0; i < NUM_INCOMPLETE_NODES; i++) {
    217217            Node n = new Node(nodeId++);
    218             incompleteNodes.add(n);
    219218            n.setIncomplete(true);
    220219            ds.addPrimitive(n);
  • trunk/test/unit/org/openstreetmap/josm/data/osm/WayDataTest.java

    r10733 r11324  
    1111import org.junit.Test;
    1212
     13import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     14
    1315public class WayDataTest {
     16
    1417    @Test
     18    @SuppressFBWarnings(value = "OBJECT_DESERIALIZATION")
    1519    public void testSerializationForDragAndDrop() throws Exception {
    1620        final WayData data = new WayData();
  • trunk/test/unit/org/openstreetmap/josm/data/projection/EllipsoidTest.java

    r10758 r11324  
    22package org.openstreetmap.josm.data.projection;
    33
     4import java.security.SecureRandom;
    45import java.util.Random;
    56
     
    2021    @Test
    2122    public void testLatLon2Cart2LatLon() {
    22         Random r = new Random(System.currentTimeMillis());
     23        Random r = new SecureRandom();
    2324        double maxErrLat = 0, maxErrLon = 0;
    2425        Ellipsoid ellips = Ellipsoid.WGS84;
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java

    r10758 r11324  
    66import java.io.File;
    77import java.io.FileInputStream;
    8 import java.io.FileNotFoundException;
    98import java.io.FileOutputStream;
    109import java.io.IOException;
     
    1413import java.io.OutputStreamWriter;
    1514import java.nio.charset.StandardCharsets;
     15import java.security.SecureRandom;
    1616import java.util.ArrayList;
    1717import java.util.Arrays;
     
    3838import org.openstreetmap.josm.tools.Pair;
    3939import org.openstreetmap.josm.tools.Utils;
     40
     41import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    4042
    4143/**
     
    7274    }
    7375
    74     static Random rand = new Random();
    75 
    76     public static void main(String[] args) throws FileNotFoundException, IOException {
     76    static Random rand = new SecureRandom();
     77
     78    /**
     79     * Program entry point.
     80     * @param args no argument is expected
     81     * @throws IOException in case of I/O error
     82     */
     83    public static void main(String[] args) throws IOException {
    7784        Collection<RefEntry> refs = readData();
    7885        refs = updateData(refs);
     
    200207
    201208    /**
    202      * Run external cs2cs command from the PROJ.4 library to convert lat/lon to
    203      * east/north value.
     209     * Run external cs2cs command from the PROJ.4 library to convert lat/lon to east/north value.
    204210     * @param def the proj.4 projection definition string
    205211     * @param ll the LatLon
    206212     * @return projected EastNorth or null in case of error
    207213     */
     214    @SuppressFBWarnings(value = "COMMAND_INJECTION")
    208215    private static EastNorth latlon2eastNorthProj4(String def, LatLon ll) {
    209216        List<String> args = new ArrayList<>();
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java

    r10758 r11324  
    1212import java.io.OutputStreamWriter;
    1313import java.nio.charset.StandardCharsets;
     14import java.security.SecureRandom;
    1415import java.util.ArrayList;
    1516import java.util.HashMap;
     
    8687        }
    8788
    88         Random rand = new Random();
     89        Random rand = new SecureRandom();
    8990        try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
    9091                new FileOutputStream(PROJECTION_DATA_FILE), StandardCharsets.UTF_8))) {
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionTest.java

    r10758 r11324  
    22package org.openstreetmap.josm.data.projection;
    33
     4import java.security.SecureRandom;
    45import java.util.Arrays;
    56import java.util.Collection;
     
    1819public class ProjectionTest {
    1920
    20     private static Random rand = new Random(System.currentTimeMillis());
     21    private static Random rand = new SecureRandom();
    2122
    2223    boolean error;
  • trunk/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java

    r10983 r11324  
    99import java.io.IOException;
    1010import java.io.PrintStream;
     11import java.nio.charset.StandardCharsets;
    1112import java.util.Arrays;
    1213import java.util.Collection;
    13 
    14 import javax.swing.event.ChangeEvent;
    15 import javax.swing.event.ChangeListener;
    1614
    1715import org.junit.BeforeClass;
     
    2523import org.openstreetmap.josm.plugins.PluginListParseException;
    2624import org.openstreetmap.josm.plugins.PluginListParser;
     25
     26import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2727
    2828/**
     
    3939    }
    4040
     41    @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING")
    4142    private void testShow(final String arg, String expected) throws InterruptedException, IOException {
    4243        PrintStream old = System.out;
     
    4950                }
    5051            };
    51             t.run();
     52            t.start();
    5253            t.join();
    5354            System.out.flush();
    54             assertEquals(expected, baos.toString().trim());
     55            assertEquals(expected, baos.toString(StandardCharsets.UTF_8.name()).trim());
    5556        } finally {
    5657            System.setOut(old);
     
    8586        try {
    8687            System.setProperty("josm.plugins", "buildings_tools,plastic_laf");
    87             SplashProgressMonitor monitor = new SplashProgressMonitor("foo", new ChangeListener() {
    88                 @Override
    89                 public void stateChanged(ChangeEvent e) {
    90                     // Do nothing
    91                 }
     88            SplashProgressMonitor monitor = new SplashProgressMonitor("foo", e -> {
     89                // Do nothing
    9290            });
    9391            Collection<PluginInformation> plugins = MainApplication.updateAndLoadEarlyPlugins(null, monitor);
  • trunk/test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java

    r10405 r11324  
    3232public class NavigatableComponentTest {
    3333
    34     private final class NavigatableComponentMock extends NavigatableComponent {
     34    private static final class NavigatableComponentMock extends NavigatableComponent {
    3535        @Override
    3636        public Point getLocationOnScreen() {
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/MainLayerManagerTest.java

    r10744 r11324  
    4343    }
    4444
    45     protected class AbstractTestOsmLayer extends OsmDataLayer {
     45    protected static class AbstractTestOsmLayer extends OsmDataLayer {
    4646        public AbstractTestOsmLayer() {
    4747            super(new DataSet(), "OSM layer", null);
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r10937 r11324  
    2020import javax.net.ssl.HttpsURLConnection;
    2121import javax.net.ssl.SSLContext;
    22 import javax.net.ssl.SSLSession;
    2322import javax.net.ssl.TrustManager;
    2423import javax.net.ssl.X509TrustManager;
     
    2928import org.openstreetmap.josm.JOSMFixture;
    3029import org.openstreetmap.josm.Main;
     30
     31import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    3132
    3233/**
     
    7778            new X509TrustManager() {
    7879                @Override
     80                @SuppressFBWarnings(value = "WEAK_TRUST_MANAGER")
    7981                public X509Certificate[] getAcceptedIssuers() {
    8082                    return new X509Certificate[0];
     
    8284
    8385                @Override
     86                @SuppressFBWarnings(value = "WEAK_TRUST_MANAGER")
    8487                public void checkClientTrusted(X509Certificate[] certs, String authType) {
    8588                }
    8689
    8790                @Override
     91                @SuppressFBWarnings(value = "WEAK_TRUST_MANAGER")
    8892                public void checkServerTrusted(X509Certificate[] certs, String authType) {
    8993                }
     
    97101
    98102        // Create all-trusting host name verifier
    99         HostnameVerifier allHostsValid = new HostnameVerifier() {
    100             @Override
    101             public boolean verify(String hostname, SSLSession session) {
    102                 return true;
    103             }
    104         };
     103        HostnameVerifier allHostsValid = (hostname, session) -> true;
    105104
    106105        // Install the all-trusting host verifier
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionReaderTest.java

    r10571 r11324  
    4343    private List<Layer> testRead(String sessionFileName) throws IOException, IllegalDataException {
    4444        boolean zip = sessionFileName.endsWith(".joz");
    45         File file = new File(getSessionDataDir()+"/"+sessionFileName);
     45        File file = new File(getSessionDataDir(), sessionFileName);
    4646        SessionReader reader = new SessionReader();
    4747        reader.loadSession(file, zip, null);
  • trunk/test/unit/org/openstreetmap/josm/tools/LoggingTest.java

    r10899 r11324  
    55import static org.junit.Assert.assertEquals;
    66import static org.junit.Assert.assertFalse;
     7import static org.junit.Assert.assertNotNull;
    78import static org.junit.Assert.assertNull;
    89import static org.junit.Assert.assertTrue;
     
    1819import org.junit.Test;
    1920
     21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     22
    2023/**
    2124 * @author michael
     
    7376    }
    7477
     78    @SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION")
    7579    private void testLogCaptured(Level level, Consumer<String> expectedTester, Runnable printMessage) {
    7680        Logging.setLogLevel(level);
     
    7882        printMessage.run();
    7983
     84        assertNotNull(captured);
    8085        expectedTester.accept(captured.getMessage());
    8186        assertEquals(level, captured.getLevel());
  • trunk/test/unit/org/openstreetmap/josm/tools/RightAndLefthandTrafficTest.java

    r11267 r11324  
    99import org.openstreetmap.josm.testutils.JOSMTestRules;
    1010
     11import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     12
    1113/**
    1214 * Unit tests of {@link RightAndLefthandTraffic} class.
     
    1719     */
    1820    @Rule
     21    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    1922    public JOSMTestRules rules = new JOSMTestRules().platform().projection().commands();
    2023
  • trunk/test/unit/org/openstreetmap/josm/tools/TerritoriesTest.java

    r11247 r11324  
    1212import org.openstreetmap.josm.testutils.JOSMTestRules;
    1313
     14import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     15
    1416/**
    1517 * Unit tests of {@link Territories} class.
     
    2022     */
    2123    @Rule
     24    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    2225    public JOSMTestRules rules = new JOSMTestRules().platform().projection().commands();
    2326
  • trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java

    r11320 r11324  
    1616import org.openstreetmap.josm.testutils.JOSMTestRules;
    1717
     18import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     19
    1820/**
    1921 * Unit tests of {@link Utils} class.
     
    2426     */
    2527    @Rule
     28    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    2629    public JOSMTestRules rules = new JOSMTestRules();
    2730
Note: See TracChangeset for help on using the changeset viewer.