Changeset 9490 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2016-01-16T18:27:55+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MultipolygonTestTest.java
r8510 r9490 5 5 import static org.junit.Assert.assertFalse; 6 6 import static org.junit.Assert.assertTrue; 7 import static org.junit.Assert.fail; 7 8 9 import java.io.FileInputStream; 10 import java.io.InputStream; 8 11 import java.util.ArrayList; 12 import java.util.Arrays; 9 13 import java.util.List; 14 import java.util.Set; 15 import java.util.TreeSet; 10 16 11 import org.junit.Before ;17 import org.junit.BeforeClass; 12 18 import org.junit.Test; 13 19 import org.openstreetmap.josm.JOSMFixture; … … 15 21 import org.openstreetmap.josm.data.osm.Node; 16 22 import org.openstreetmap.josm.data.osm.OsmUtils; 23 import org.openstreetmap.josm.data.osm.Relation; 17 24 import org.openstreetmap.josm.data.osm.Way; 25 import org.openstreetmap.josm.data.validation.TestError; 26 import org.openstreetmap.josm.gui.DefaultNameFormatter; 18 27 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 19 28 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 29 import org.openstreetmap.josm.io.OsmReader; 20 30 21 31 /** … … 25 35 26 36 private static final MultipolygonTest MULTIPOLYGON_TEST = new MultipolygonTest(); 37 private static final RelationChecker RELATION_TEST = new RelationChecker(); 27 38 28 39 /** … … 30 41 * @throws Exception if test cannot be initialized 31 42 */ 32 @Before 33 public void setUp() throws Exception {34 JOSMFixture.createUnitTestFixture().init( );43 @BeforeClass 44 public static void setUp() throws Exception { 45 JOSMFixture.createUnitTestFixture().init(true); 35 46 MapPaintStyles.readFromPreferences(); 36 MULTIPOLYGON_TEST.initialize();37 47 } 38 48 … … 52 62 @Test 53 63 public void testTicket10469() { 64 MULTIPOLYGON_TEST.initialize(); 54 65 MULTIPOLYGON_TEST.startTest(null); 55 66 … … 78 89 MULTIPOLYGON_TEST.endTest(); 79 90 } 91 92 /** 93 * Test all error cases manually created in multipolygon.osm. 94 * @throws Exception in case of error 95 */ 96 @Test 97 public void testMultipolygonFile() throws Exception { 98 try (InputStream is = new FileInputStream("data_nodist/multipolygon.osm")) { 99 for (Relation r : OsmReader.parseDataSet(is, null).getRelations()) { 100 if (r.isMultipolygon()) { 101 String name = DefaultNameFormatter.getInstance().format(r); 102 String codes = r.get("josm_error_codes"); 103 if (codes != null) { 104 List<TestError> errors = new ArrayList<>(); 105 for (org.openstreetmap.josm.data.validation.Test test : Arrays.asList(MULTIPOLYGON_TEST, RELATION_TEST)) { 106 test.initialize(); 107 test.startTest(null); 108 test.visit(r); 109 test.endTest(); 110 errors.addAll(test.getErrors()); 111 } 112 Set<Integer> expectedCodes = new TreeSet<>(); 113 for (String code : codes.split(",")) { 114 expectedCodes.add(Integer.parseInt(code)); 115 } 116 Set<Integer> actualCodes = new TreeSet<>(); 117 for (TestError error : errors) { 118 Integer code = error.getCode(); 119 assertTrue(name + " does not expect JOSM error code " + code + ": " + error.getDescription(), 120 expectedCodes.contains(code)); 121 actualCodes.add(code); 122 } 123 assertEquals(name + " " + expectedCodes + " => " + actualCodes, 124 expectedCodes.size(), actualCodes.size()); 125 } else if (r.hasKey("name") && (r.getName().startsWith("06") || r.getName().startsWith("07"))) { 126 fail(name + " lacks josm_error_codes tag"); 127 } 128 } 129 } 130 } 131 } 80 132 }
Note:
See TracChangeset
for help on using the changeset viewer.