1 | package org.openstreetmap.josm.gui.annotation;
|
---|
2 |
|
---|
3 | import java.io.InputStream;
|
---|
4 | import java.lang.reflect.Field;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import javax.swing.Action;
|
---|
8 |
|
---|
9 | import junit.framework.TestCase;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Check;
|
---|
12 | import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Combo;
|
---|
13 | import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Key;
|
---|
14 | import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Label;
|
---|
15 | import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Text;
|
---|
16 |
|
---|
17 | public 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 | }
|
---|