1 | package org.openstreetmap.josm.gui.annotation;
|
---|
2 |
|
---|
3 | import java.io.ByteArrayInputStream;
|
---|
4 | import java.io.InputStream;
|
---|
5 | import java.lang.reflect.Field;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import javax.swing.Action;
|
---|
9 | import javax.swing.Icon;
|
---|
10 |
|
---|
11 | import junit.framework.TestCase;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Check;
|
---|
14 | import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Combo;
|
---|
15 | import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Key;
|
---|
16 | import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Label;
|
---|
17 | import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Text;
|
---|
18 |
|
---|
19 | public class AnnotationPresetTest extends TestCase {
|
---|
20 |
|
---|
21 | public void testAnnotationPresetLoads() throws Exception {
|
---|
22 | InputStream in = getClass().getResourceAsStream("annotation-test.xml");
|
---|
23 | List<AnnotationPreset> all = AnnotationPreset.readAll(in);
|
---|
24 |
|
---|
25 | assertEquals(1, all.size());
|
---|
26 | AnnotationPreset a = all.get(0);
|
---|
27 | assertEquals("Highway", a.getValue(Action.NAME));
|
---|
28 | Field dataField = a.getClass().getDeclaredField("data");
|
---|
29 | dataField.setAccessible(true);
|
---|
30 | List<?> data = (List<?>)dataField.get(a);
|
---|
31 | assertEquals(5, data.size());
|
---|
32 |
|
---|
33 | Label label = (Label)data.get(0);
|
---|
34 | assertEquals("Inserting a highway in UK", label.text);
|
---|
35 |
|
---|
36 | Text text = (Text)data.get(1);
|
---|
37 | assertEquals("name", text.key);
|
---|
38 | assertEquals("Highway (e.g. M3)", text.text);
|
---|
39 | assertFalse(text.delete_if_empty);
|
---|
40 | assertNull(text.default_);
|
---|
41 |
|
---|
42 | Combo combo = (Combo)data.get(2);
|
---|
43 | assertEquals("highway", combo.key);
|
---|
44 | assertEquals("Type", combo.text);
|
---|
45 | assertEquals("major,minor", combo.values);
|
---|
46 | assertTrue(combo.delete_if_empty);
|
---|
47 | assertTrue(combo.editable);
|
---|
48 | assertNull(combo.default_);
|
---|
49 |
|
---|
50 | Check check = (Check)data.get(3);
|
---|
51 | assertEquals("oneway", check.key);
|
---|
52 | assertEquals("Oneway", check.text);
|
---|
53 | assertTrue(check.default_);
|
---|
54 |
|
---|
55 | Key key = (Key)data.get(4);
|
---|
56 | assertEquals("class", key.key);
|
---|
57 | assertEquals("highway", key.value);
|
---|
58 | }
|
---|
59 |
|
---|
60 | public void testIconLoadsFromClasspath() throws Exception {
|
---|
61 | String xml = "<annotations><item icon='logo'></item></annotations>";
|
---|
62 | List<AnnotationPreset> all = AnnotationPreset.readAll(new ByteArrayInputStream(xml.getBytes()));
|
---|
63 |
|
---|
64 | assertEquals(1, all.size());
|
---|
65 |
|
---|
66 | Icon icon = (Icon)all.get(0).getValue(Action.SMALL_ICON);
|
---|
67 | assertNotNull(icon);
|
---|
68 | assertEquals("Icon loaded and of correct size",
|
---|
69 | 24, Math.max(icon.getIconHeight(), icon.getIconWidth()));
|
---|
70 | }
|
---|
71 | }
|
---|