Changeset 31795 in osm for applications/editors
- Timestamp:
- 2015-12-03T22:27:47+01:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java
r31787 r31795 37 37 "Bearer " + Main.pref.get("mapillary.access-token")); 38 38 39 BufferedReader in = new BufferedReader(new InputStreamReader( 40 con.getInputStream())); 41 return Json.createReader(in).readObject(); 39 try ( 40 BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())) 41 ) { 42 return Json.createReader(in).readObject(); 43 } 42 44 } 43 45 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoGlyph.java
r31793 r31795 10 10 import javax.json.JsonReader; 11 11 12 public class TrafficoGlyph {12 public final class TrafficoGlyph { 13 13 private TrafficoGlyph() { 14 14 // private constructor to avoid instantiation -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoSign.java
r31787 r31795 9 9 import java.util.Map; 10 10 import java.util.Set; 11 import java.util.TreeMap;12 11 13 12 import javax.json.Json; … … 15 14 import javax.json.JsonObject; 16 15 17 public class TrafficoSign { 18 private static final Map<String, String> isIn = new TreeMap<>(); 19 20 static { 21 isIn.put("be", "europe"); 22 isIn.put("de", "europe"); 23 isIn.put("dk", "europe"); 24 isIn.put("es", "europe"); 16 public final class TrafficoSign { 17 private TrafficoSign() { 18 // private constructor to avoid instantiation 25 19 } 26 20 … … 31 25 System.out.println("Read signs for " + country); 32 26 InputStream countryStream = TrafficoSign.class 33 .getResourceAsStream("/data/fonts/traffico/signs/" + country 34 + ".json"); 27 .getResourceAsStream("/data/fonts/traffico/signs/" + country + ".json"); 35 28 if (countryStream == null) { 36 29 return null; … … 89 82 return signs.get(country).get(signName); 90 83 } 91 if (isIn.containsKey(country)) {92 return TrafficoSign.getSign(isIn.get(country), signName);93 }94 84 return null; 95 85 } -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoGlyphTest.java
r31793 r31795 3 3 import static org.junit.Assert.assertEquals; 4 4 5 import java.lang.reflect.Constructor;6 7 5 import org.junit.Test; 6 import org.openstreetmap.josm.plugins.mapillary.utils.TestUtil; 8 7 9 8 public class TrafficoGlyphTest { … … 17 16 } 18 17 19 /**20 * The following test has the only purpose to provide code coverage for the private constructor.21 */22 18 @Test 23 public void testPrivateConstructor() throws Exception { 24 Constructor<?> c = TrafficoGlyph.class.getDeclaredConstructors()[0]; 25 c.setAccessible(true); 26 c.newInstance(); 19 public void testUtilityClass() { 20 TestUtil.testUtilityClass(TrafficoGlyph.class); 27 21 } 28 22 -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/TestUtil.java
r31460 r31795 1 1 package org.openstreetmap.josm.plugins.mapillary.utils; 2 2 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 5 6 import java.lang.reflect.Constructor; 7 import java.lang.reflect.Method; 8 import java.lang.reflect.Modifier; 3 9 4 10 import org.openstreetmap.josm.Main; … … 41 47 } 42 48 49 /** 50 * This method tests utility classes for common coding standards (exactly one constructor that's private, 51 * only static methods, …) and fails the current test if one of those standards is not met. 52 * This is inspired by http://stackoverflow.com/questions/4520216 . 53 * @param c the class under test 54 */ 55 public static void testUtilityClass(final Class<?> c) { 56 try { 57 // class must be final 58 assertTrue(Modifier.isFinal(c.getModifiers())); 59 // with exactly one constructor 60 assertEquals(1, c.getDeclaredConstructors().length); 61 final Constructor<?> constructor = c.getDeclaredConstructors()[0]; 62 // constructor has to be private 63 assertTrue(!constructor.isAccessible() && Modifier.isPrivate(constructor.getModifiers())); 64 constructor.setAccessible(true); 65 // Call private constructor for code coverage 66 constructor.newInstance(); 67 for (Method m : c.getMethods()) { 68 // Check if all methods are static 69 assertTrue(m.getDeclaringClass() != c || Modifier.isStatic(m.getModifiers())); 70 } 71 } catch (Exception e) { 72 assertTrue(e.getMessage(), false); 73 } 74 } 43 75 }
Note:
See TracChangeset
for help on using the changeset viewer.