Changeset 11324 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2016-11-27T05:16:30+01:00 (8 years ago)
- 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 10 10 import java.io.InputStream; 11 11 import java.lang.reflect.Field; 12 import java.security.AccessController; 13 import java.security.PrivilegedAction; 12 14 import java.util.Arrays; 13 15 import java.util.Collection; … … 79 81 */ 80 82 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)); 82 84 } 83 85 … … 173 175 public static Object getPrivateField(Object obj, String fieldName) throws ReflectiveOperationException { 174 176 Field f = obj.getClass().getDeclaredField(fieldName); 175 f.setAccessible(true); 177 AccessController.doPrivileged((PrivilegedAction<Void>) () -> { 178 f.setAccessible(true); 179 return null; 180 }); 176 181 return f.get(obj); 177 182 } -
trunk/test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java
r10443 r11324 20 20 import org.openstreetmap.josm.testutils.JOSMTestRules; 21 21 22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 23 22 24 /** 23 25 * Unit tests for class {@link SelectByInternalPointAction}. … … 29 31 */ 30 32 @Rule 33 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 31 34 public JOSMTestRules rules = new JOSMTestRules().preferences().projection(); 32 35 -
trunk/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java
r11192 r11324 27 27 import org.openstreetmap.josm.tools.date.DateUtils; 28 28 29 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 30 29 31 /** 30 32 * Unit tests for class {@link SearchCompiler}. … … 36 38 */ 37 39 @Rule 40 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 38 41 public JOSMTestRules test = new JOSMTestRules().preferences(); 39 42 -
trunk/test/unit/org/openstreetmap/josm/data/AutosaveTaskTest.java
r11035 r11324 8 8 import static org.junit.Assert.assertTrue; 9 9 10 import java.io.BufferedWriter; 10 11 import java.io.File; 11 import java.io.FileWriter;12 import java.io.FilenameFilter;13 12 import java.io.IOException; 13 import java.nio.charset.StandardCharsets; 14 14 import java.nio.file.Files; 15 15 import java.nio.file.Paths; … … 143 143 144 144 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; 151 147 } 152 148 … … 194 190 public void testDiscardUnsavedLayersIgnoresCurrentInstance() throws IOException { 195 191 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)) { 197 194 file.append(""); 198 195 } … … 237 234 public void testRecoverLayers() throws Exception { 238 235 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)) { 240 238 file.append("<?xml version=\"1.0\"?><osm version=\"0.6\"><node id=\"1\" lat=\"1\" lon=\"2\" version=\"1\"/></osm>"); 241 239 } -
trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java
r10962 r11324 45 45 File cacheFile = new File("foobar/testUseBigDiskFile_BLOCK_v2.data"); 46 46 if (!cacheFile.exists()) { 47 cacheFile.createNewFile(); 47 if (!cacheFile.createNewFile()) { 48 System.err.println("Unable to create " + cacheFile.getAbsolutePath()); 49 } 48 50 } 49 51 try (FileOutputStream fileOutputStream = new FileOutputStream(cacheFile, false)) { -
trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetTest.java
r11121 r11324 31 31 */ 32 32 @Test 33 @SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS") 33 34 public void testSetKeys() { 34 35 final Changeset cs = new Changeset(); -
trunk/test/unit/org/openstreetmap/josm/data/osm/NodeDataTest.java
r10946 r11324 15 15 import org.openstreetmap.josm.data.coor.LatLon; 16 16 17 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 18 17 19 public class NodeDataTest { 18 20 21 @SuppressFBWarnings(value = "OBJECT_DESERIALIZATION") 19 22 private static NodeData serializeUnserialize(NodeData data) throws IOException, ClassNotFoundException { 20 23 try (ByteArrayOutputStream bytes = new ByteArrayOutputStream(); -
trunk/test/unit/org/openstreetmap/josm/data/osm/QuadBucketsTest.java
r11269 r11324 4 4 import java.io.FileInputStream; 5 5 import java.io.InputStream; 6 import java.security.SecureRandom; 6 7 import java.util.ArrayList; 7 8 import java.util.Arrays; … … 193 194 194 195 // force splits in quad buckets 195 Random random = new Random(31);196 Random random = new SecureRandom(); 196 197 for (int i = 0; i < NUM_COMPLETE_WAYS; i++) { 197 198 Way w = new Way(wayId++); … … 213 214 214 215 // add some incomplete nodes 215 List<Node> incompleteNodes = new ArrayList<>();216 216 for (int i = 0; i < NUM_INCOMPLETE_NODES; i++) { 217 217 Node n = new Node(nodeId++); 218 incompleteNodes.add(n);219 218 n.setIncomplete(true); 220 219 ds.addPrimitive(n); -
trunk/test/unit/org/openstreetmap/josm/data/osm/WayDataTest.java
r10733 r11324 11 11 import org.junit.Test; 12 12 13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 14 13 15 public class WayDataTest { 16 14 17 @Test 18 @SuppressFBWarnings(value = "OBJECT_DESERIALIZATION") 15 19 public void testSerializationForDragAndDrop() throws Exception { 16 20 final WayData data = new WayData(); -
trunk/test/unit/org/openstreetmap/josm/data/projection/EllipsoidTest.java
r10758 r11324 2 2 package org.openstreetmap.josm.data.projection; 3 3 4 import java.security.SecureRandom; 4 5 import java.util.Random; 5 6 … … 20 21 @Test 21 22 public void testLatLon2Cart2LatLon() { 22 Random r = new Random(System.currentTimeMillis());23 Random r = new SecureRandom(); 23 24 double maxErrLat = 0, maxErrLon = 0; 24 25 Ellipsoid ellips = Ellipsoid.WGS84; -
trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java
r10758 r11324 6 6 import java.io.File; 7 7 import java.io.FileInputStream; 8 import java.io.FileNotFoundException;9 8 import java.io.FileOutputStream; 10 9 import java.io.IOException; … … 14 13 import java.io.OutputStreamWriter; 15 14 import java.nio.charset.StandardCharsets; 15 import java.security.SecureRandom; 16 16 import java.util.ArrayList; 17 17 import java.util.Arrays; … … 38 38 import org.openstreetmap.josm.tools.Pair; 39 39 import org.openstreetmap.josm.tools.Utils; 40 41 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 40 42 41 43 /** … … 72 74 } 73 75 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 { 77 84 Collection<RefEntry> refs = readData(); 78 85 refs = updateData(refs); … … 200 207 201 208 /** 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. 204 210 * @param def the proj.4 projection definition string 205 211 * @param ll the LatLon 206 212 * @return projected EastNorth or null in case of error 207 213 */ 214 @SuppressFBWarnings(value = "COMMAND_INJECTION") 208 215 private static EastNorth latlon2eastNorthProj4(String def, LatLon ll) { 209 216 List<String> args = new ArrayList<>(); -
trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java
r10758 r11324 12 12 import java.io.OutputStreamWriter; 13 13 import java.nio.charset.StandardCharsets; 14 import java.security.SecureRandom; 14 15 import java.util.ArrayList; 15 16 import java.util.HashMap; … … 86 87 } 87 88 88 Random rand = new Random();89 Random rand = new SecureRandom(); 89 90 try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter( 90 91 new FileOutputStream(PROJECTION_DATA_FILE), StandardCharsets.UTF_8))) { -
trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionTest.java
r10758 r11324 2 2 package org.openstreetmap.josm.data.projection; 3 3 4 import java.security.SecureRandom; 4 5 import java.util.Arrays; 5 6 import java.util.Collection; … … 18 19 public class ProjectionTest { 19 20 20 private static Random rand = new Random(System.currentTimeMillis());21 private static Random rand = new SecureRandom(); 21 22 22 23 boolean error; -
trunk/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java
r10983 r11324 9 9 import java.io.IOException; 10 10 import java.io.PrintStream; 11 import java.nio.charset.StandardCharsets; 11 12 import java.util.Arrays; 12 13 import java.util.Collection; 13 14 import javax.swing.event.ChangeEvent;15 import javax.swing.event.ChangeListener;16 14 17 15 import org.junit.BeforeClass; … … 25 23 import org.openstreetmap.josm.plugins.PluginListParseException; 26 24 import org.openstreetmap.josm.plugins.PluginListParser; 25 26 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 27 27 28 28 /** … … 39 39 } 40 40 41 @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING") 41 42 private void testShow(final String arg, String expected) throws InterruptedException, IOException { 42 43 PrintStream old = System.out; … … 49 50 } 50 51 }; 51 t. run();52 t.start(); 52 53 t.join(); 53 54 System.out.flush(); 54 assertEquals(expected, baos.toString( ).trim());55 assertEquals(expected, baos.toString(StandardCharsets.UTF_8.name()).trim()); 55 56 } finally { 56 57 System.setOut(old); … … 85 86 try { 86 87 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 92 90 }); 93 91 Collection<PluginInformation> plugins = MainApplication.updateAndLoadEarlyPlugins(null, monitor); -
trunk/test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java
r10405 r11324 32 32 public class NavigatableComponentTest { 33 33 34 private final class NavigatableComponentMock extends NavigatableComponent {34 private static final class NavigatableComponentMock extends NavigatableComponent { 35 35 @Override 36 36 public Point getLocationOnScreen() { -
trunk/test/unit/org/openstreetmap/josm/gui/layer/MainLayerManagerTest.java
r10744 r11324 43 43 } 44 44 45 protected class AbstractTestOsmLayer extends OsmDataLayer {45 protected static class AbstractTestOsmLayer extends OsmDataLayer { 46 46 public AbstractTestOsmLayer() { 47 47 super(new DataSet(), "OSM layer", null); -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java
r10937 r11324 20 20 import javax.net.ssl.HttpsURLConnection; 21 21 import javax.net.ssl.SSLContext; 22 import javax.net.ssl.SSLSession;23 22 import javax.net.ssl.TrustManager; 24 23 import javax.net.ssl.X509TrustManager; … … 29 28 import org.openstreetmap.josm.JOSMFixture; 30 29 import org.openstreetmap.josm.Main; 30 31 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 31 32 32 33 /** … … 77 78 new X509TrustManager() { 78 79 @Override 80 @SuppressFBWarnings(value = "WEAK_TRUST_MANAGER") 79 81 public X509Certificate[] getAcceptedIssuers() { 80 82 return new X509Certificate[0]; … … 82 84 83 85 @Override 86 @SuppressFBWarnings(value = "WEAK_TRUST_MANAGER") 84 87 public void checkClientTrusted(X509Certificate[] certs, String authType) { 85 88 } 86 89 87 90 @Override 91 @SuppressFBWarnings(value = "WEAK_TRUST_MANAGER") 88 92 public void checkServerTrusted(X509Certificate[] certs, String authType) { 89 93 } … … 97 101 98 102 // 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; 105 104 106 105 // Install the all-trusting host verifier -
trunk/test/unit/org/openstreetmap/josm/io/session/SessionReaderTest.java
r10571 r11324 43 43 private List<Layer> testRead(String sessionFileName) throws IOException, IllegalDataException { 44 44 boolean zip = sessionFileName.endsWith(".joz"); 45 File file = new File(getSessionDataDir() +"/"+sessionFileName);45 File file = new File(getSessionDataDir(), sessionFileName); 46 46 SessionReader reader = new SessionReader(); 47 47 reader.loadSession(file, zip, null); -
trunk/test/unit/org/openstreetmap/josm/tools/LoggingTest.java
r10899 r11324 5 5 import static org.junit.Assert.assertEquals; 6 6 import static org.junit.Assert.assertFalse; 7 import static org.junit.Assert.assertNotNull; 7 8 import static org.junit.Assert.assertNull; 8 9 import static org.junit.Assert.assertTrue; … … 18 19 import org.junit.Test; 19 20 21 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 22 20 23 /** 21 24 * @author michael … … 73 76 } 74 77 78 @SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION") 75 79 private void testLogCaptured(Level level, Consumer<String> expectedTester, Runnable printMessage) { 76 80 Logging.setLogLevel(level); … … 78 82 printMessage.run(); 79 83 84 assertNotNull(captured); 80 85 expectedTester.accept(captured.getMessage()); 81 86 assertEquals(level, captured.getLevel()); -
trunk/test/unit/org/openstreetmap/josm/tools/RightAndLefthandTrafficTest.java
r11267 r11324 9 9 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 10 11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 11 13 /** 12 14 * Unit tests of {@link RightAndLefthandTraffic} class. … … 17 19 */ 18 20 @Rule 21 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 19 22 public JOSMTestRules rules = new JOSMTestRules().platform().projection().commands(); 20 23 -
trunk/test/unit/org/openstreetmap/josm/tools/TerritoriesTest.java
r11247 r11324 12 12 import org.openstreetmap.josm.testutils.JOSMTestRules; 13 13 14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 15 14 16 /** 15 17 * Unit tests of {@link Territories} class. … … 20 22 */ 21 23 @Rule 24 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 22 25 public JOSMTestRules rules = new JOSMTestRules().platform().projection().commands(); 23 26 -
trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
r11320 r11324 16 16 import org.openstreetmap.josm.testutils.JOSMTestRules; 17 17 18 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 19 18 20 /** 19 21 * Unit tests of {@link Utils} class. … … 24 26 */ 25 27 @Rule 28 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 26 29 public JOSMTestRules rules = new JOSMTestRules(); 27 30
Note:
See TracChangeset
for help on using the changeset viewer.