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

Last change on this file since 290 was 266, checked in by imi, 17 years ago
  • added "Getting Started" welcome screen
  • added latest JOSM version in About dialog
  • set "draw boundaries" to on by default
File size: 2.4 KB
Line 
1package org.openstreetmap.josm.gui.annotation;
2
3import java.io.ByteArrayInputStream;
4import java.io.InputStream;
5import java.lang.reflect.Field;
6import java.util.List;
7
8import javax.swing.Action;
9import javax.swing.Icon;
10
11import junit.framework.TestCase;
12
13import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Check;
14import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Combo;
15import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Key;
16import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Label;
17import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Text;
18
19public 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}
Note: See TracBrowser for help on using the repository browser.