source: josm/test/org/openstreetmap/josm/gui/annotation/AnnotationPresetTest.java@ 193

Last change on this file since 193 was 193, checked in by imi, 17 years ago
  • added new XmlObjectParser that should replace the direct use of MinML2 in the future
  • changed AnnotationPreset to use the new parser
File size: 1.9 KB
Line 
1package org.openstreetmap.josm.gui.annotation;
2
3import java.io.InputStream;
4import java.lang.reflect.Field;
5import java.util.List;
6
7import javax.swing.Action;
8
9import junit.framework.TestCase;
10
11import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Check;
12import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Combo;
13import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Key;
14import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Label;
15import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Text;
16
17public class AnnotationPresetTest extends TestCase {
18
19 public void testAnnotationPresetLoads() throws Exception {
20 InputStream in = getClass().getResourceAsStream("annotation-test.xml");
21 List<AnnotationPreset> all = AnnotationPreset.readAll(in);
22
23 assertEquals(1, all.size());
24 AnnotationPreset a = all.get(0);
25 assertEquals("Highway", a.getValue(Action.NAME));
26 Field dataField = a.getClass().getDeclaredField("data");
27 dataField.setAccessible(true);
28 List<?> data = (List<?>)dataField.get(a);
29 assertEquals(5, data.size());
30
31 Label label = (Label)data.get(0);
32 assertEquals("Inserting a highway in UK", label.text);
33
34 Text text = (Text)data.get(1);
35 assertEquals("name", text.key);
36 assertEquals("Highway (e.g. M3)", text.text);
37 assertFalse(text.delete_if_empty);
38 assertNull(text.default_);
39
40 Combo combo = (Combo)data.get(2);
41 assertEquals("highway", combo.key);
42 assertEquals("Type", combo.text);
43 assertEquals("major,minor", combo.values);
44 assertTrue(combo.delete_if_empty);
45 assertTrue(combo.editable);
46 assertNull(combo.default_);
47
48 Check check = (Check)data.get(3);
49 assertEquals("oneway", check.key);
50 assertEquals("Oneway", check.text);
51 assertTrue(check.default_);
52
53 Key key = (Key)data.get(4);
54 assertEquals("class", key.key);
55 assertEquals("highway", key.value);
56 }
57}
Note: See TracBrowser for help on using the repository browser.