Changeset 10222 in josm for trunk/test/unit/org/openstreetmap/josm/data
- Timestamp:
- 2016-05-15T21:14:06+02:00 (10 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/data
- Files:
-
- 13 edited
-
cache/JCSCachedTileLoaderJobTest.java (modified) (5 diffs)
-
coor/LatLonTest.java (modified) (2 diffs)
-
oauth/OAuthParametersTest.java (modified) (2 diffs)
-
osm/ChangesetCacheTest.groovy (modified) (6 diffs)
-
osm/FilterTest.java (modified) (1 diff)
-
osm/MultipolygonBuilderTest.java (modified) (2 diffs)
-
osm/OsmPrimitiveKeyHandlingTest.java (modified) (2 diffs)
-
osm/RelationTest.java (modified) (1 diff)
-
projection/ProjectionRefTest.java (modified) (1 diff)
-
validation/routines/DomainValidatorTestIT.java (modified) (5 diffs)
-
validation/routines/EmailValidatorTest.java (modified) (1 diff)
-
validation/routines/UrlValidatorTest.java (modified) (1 diff)
-
validation/tests/MultipolygonTestTest.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java
r10219 r10222 13 13 import org.junit.Test; 14 14 import org.openstreetmap.josm.JOSMFixture; 15 16 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 15 17 16 18 /** … … 59 61 this.attributes = attributes; 60 62 this.ready = true; 61 this.notify(); 63 this.notifyAll(); 62 64 } 63 65 } … … 71 73 } 72 74 75 /** 76 * Test status codes 77 * @throws InterruptedException in case of thread interruption 78 * @throws IOException in case of I/O error 79 */ 73 80 @Test 74 public void testStatusCodes() throws Exception { 81 public void testStatusCodes() throws IOException, InterruptedException { 75 82 doTestStatusCode(200); 76 83 // can't test for 3xx, as httpstat.us redirects finally to 200 page … … 85 92 } 86 93 94 /** 95 * Test unknown host 96 * @throws InterruptedException in case of thread interruption 97 * @throws IOException in case of I/O error 98 */ 87 99 @Test 88 public void testUnknownHost() throws Exception { 100 @SuppressFBWarnings(value = "WA_NOT_IN_LOOP") 101 public void testUnknownHost() throws IOException, InterruptedException { 89 102 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown"); 90 103 Listener listener = new Listener(); … … 98 111 } 99 112 100 private void doTestStatusCode(int responseCode) throws Exception { 113 @SuppressFBWarnings(value = "WA_NOT_IN_LOOP") 114 private void doTestStatusCode(int responseCode) throws IOException, InterruptedException { 101 115 TestCachedTileLoaderJob job = getStatusLoaderJob(responseCode); 102 116 Listener listener = new Listener(); -
trunk/test/unit/org/openstreetmap/josm/data/coor/LatLonTest.java
r9879 r10222 7 7 import org.junit.Test; 8 8 import org.openstreetmap.josm.JOSMFixture; 9 10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 9 11 10 12 /** … … 26 28 * Lat/Lon sample values for unit tests 27 29 */ 30 @SuppressFBWarnings(value = "MS_PKGPROTECT") 28 31 public static final double[] SAMPLE_VALUES = new double[]{ 29 32 -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 12 12 import org.openstreetmap.josm.io.OsmApi; 13 13 14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 14 15 import nl.jqno.equalsverifier.EqualsVerifier; 15 16 … … 31 32 */ 32 33 @Test 34 @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") 33 35 public void testCreateDefault() { 34 36 OAuthParameters def = OAuthParameters.createDefault(); -
trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetCacheTest.groovy
r8510 r10222 9 9 10 10 @Test 11 public void test _Constructor() {11 public void testConstructor() { 12 12 ChangesetCache cache = ChangesetCache.getInstance() 13 13 assert cache != null … … 15 15 16 16 @Test 17 public void test _addAndRemoveListeners() {17 public void testAddAndRemoveListeners() { 18 18 ChangesetCache cache = ChangesetCache.getInstance() 19 19 cache.clear() … … 38 38 39 39 @Test 40 public void update _get_remove_cycle() {40 public void updateGetRemoveCycle() { 41 41 ChangesetCache cache = ChangesetCache.getInstance() 42 42 cache.clear() … … 97 97 98 98 @Test 99 public void fireingEvents _AddAChangeset() {99 public void fireingEventsAddAChangeset() { 100 100 ChangesetCache cache = ChangesetCache.getInstance() 101 101 cache.clear() … … 118 118 119 119 @Test 120 public void fireingEvents _UpdateChangeset() {120 public void fireingEventsUpdateChangeset() { 121 121 ChangesetCache cache = ChangesetCache.getInstance() 122 122 cache.clear() … … 141 141 142 142 @Test 143 public void fireingEvents _RemoveChangeset() {143 public void fireingEventsRemoveChangeset() { 144 144 ChangesetCache cache = ChangesetCache.getInstance() 145 145 cache.clear() -
trunk/test/unit/org/openstreetmap/josm/data/osm/FilterTest.java
r9214 r10222 161 161 break; 162 162 } 163 default: throw new AssertionError(); 163 164 } 164 165 -
trunk/test/unit/org/openstreetmap/josm/data/osm/MultipolygonBuilderTest.java
r9666 r10222 14 14 import org.openstreetmap.josm.io.OsmReader; 15 15 16 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 17 16 18 /** 17 19 * Unit tests of the {@code MultipolygonBuilder} class. … … 23 25 */ 24 26 @Rule 27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 25 28 public Timeout globalTimeout = Timeout.seconds(15); 26 29 -
trunk/test/unit/org/openstreetmap/josm/data/osm/OsmPrimitiveKeyHandlingTest.java
r9459 r10222 10 10 import org.openstreetmap.josm.JOSMFixture; 11 11 import org.openstreetmap.josm.data.coor.LatLon; 12 13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 14 13 15 /** … … 72 74 */ 73 75 @Test 76 @SuppressFBWarnings(value = "DM_STRING_CTOR", justification = "test that equals is used and not ==") 74 77 public void remove() { 75 78 Node n = new Node(); -
trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java
r9716 r10222 34 34 35 35 @Test 36 public void testB Box() {36 public void testBbox() { 37 37 DataSet ds = new DataSet(); 38 38 -
trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java
r10219 r10222 222 222 Process process = pb.start(); 223 223 OutputStream stdin = process.getOutputStream(); 224 final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin, StandardCharsets.UTF_8));225 224 InputStream stdout = process.getInputStream(); 226 finalBufferedReader reader = new BufferedReader(newInputStreamReader(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 } 232 231 } catch (IOException e) { 233 232 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 48 48 import org.junit.Test; 49 49 50 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 51 50 52 /** 51 53 * Integration tests for the DomainValidator. … … 82 84 download(htmlFile, "http://www.iana.org/domains/root/db", timestamp); 83 85 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 } 118 125 } 119 126 } 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); 125 144 } 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 } 156 157 } 157 158 // Check if internal tables contain any additional entries … … 175 176 } 176 177 178 @SuppressFBWarnings(value = "PERFORMANCE") 177 179 private static Map<String, String[]> getHtmlInfo(final File f) throws IOException { 178 180 final Map<String, String[]> info = new HashMap<>(); … … 186 188 final Pattern comment = Pattern.compile("\\s+<td>([^<]+)</td>"); 187 189 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 = "??"; 198 198 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 } 206 210 line = br.readLine(); 207 211 } 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 } 221 227 } 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 } 231 233 return info; 232 234 } … … 262 264 System.out.println("Downloading " + tldurl); 263 265 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 } 273 273 System.out.println("Done"); 274 274 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/routines/EmailValidatorTest.java
r10202 r10222 37 37 * rules from the xml file. 38 38 */ 39 protected static String FORM_KEY = "emailForm"; 39 protected static final String FORM_KEY = "emailForm"; 40 40 41 41 /** 42 42 * The key used to retrieve the validator action. 43 43 */ 44 protected static String ACTION = "email"; 44 protected static final String ACTION = "email"; 45 45 46 46 private EmailValidator validator; -
trunk/test/unit/org/openstreetmap/josm/data/validation/routines/UrlValidatorTest.java
r10133 r10222 31 31 public class UrlValidatorTest { 32 32 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. 35 35 36 36 /** -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MultipolygonTestTest.java
r9490 r10222 65 65 MULTIPOLYGON_TEST.startTest(null); 66 66 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 71 67 // Erroneous tag 72 68 Way w = createUnclosedWay("amenity=parking");
Note:
See TracChangeset
for help on using the changeset viewer.
