Changeset 31795 in osm for applications/editors/josm/plugins/mapillary/test
- Timestamp:
- 2015-12-03T22:27:47+01:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 1 added
- 2 edited
-
traffico/TrafficoGlyphTest.java (modified) (2 diffs)
-
traffico/TrafficoSignTest.java (added)
-
utils/TestUtil.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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.
