1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertNotNull;
|
---|
7 | import static org.junit.Assert.assertNull;
|
---|
8 | import static org.junit.Assert.assertTrue;
|
---|
9 |
|
---|
10 | import java.awt.Color;
|
---|
11 | import java.io.File;
|
---|
12 |
|
---|
13 | import org.junit.Before;
|
---|
14 | import org.junit.Rule;
|
---|
15 | import org.junit.Test;
|
---|
16 | import org.openstreetmap.josm.Main;
|
---|
17 | import org.openstreetmap.josm.data.preferences.AbstractProperty;
|
---|
18 | import org.openstreetmap.josm.data.preferences.NamedColorProperty;
|
---|
19 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
20 |
|
---|
21 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Test of the base {@link Layer} class
|
---|
25 | * @author Michael Zangl
|
---|
26 | */
|
---|
27 | public class LayerTest {
|
---|
28 | /**
|
---|
29 | * We need projection
|
---|
30 | */
|
---|
31 | @Rule
|
---|
32 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
33 | public JOSMTestRules test = new JOSMTestRules().preferences().projection();
|
---|
34 |
|
---|
35 | private Layer testLayer;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Create test layer
|
---|
39 | */
|
---|
40 | @Before
|
---|
41 | public void setUp() {
|
---|
42 | testLayer = new LayerManagerTest.TestLayer();
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Test {@link Layer#getColorProperty()}
|
---|
47 | */
|
---|
48 | @Test
|
---|
49 | public void testGetColorProperty() {
|
---|
50 | assertEquals(null, testLayer.getColorProperty());
|
---|
51 |
|
---|
52 | AbstractProperty<Color> color = new LayerManagerTest.TestLayer() {
|
---|
53 | @Override
|
---|
54 | protected NamedColorProperty getBaseColorProperty() {
|
---|
55 | return new NamedColorProperty("x", Color.BLACK);
|
---|
56 | }
|
---|
57 | }.getColorProperty();
|
---|
58 |
|
---|
59 | assertEquals(Color.BLACK, color.get());
|
---|
60 | assertEquals(Color.BLACK, color.getDefaultValue());
|
---|
61 | assertEquals("color.layer.test.layer", color.getKey());
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Test of {@link Layer#isInfoResizable}
|
---|
66 | */
|
---|
67 | @Test
|
---|
68 | public void testIsInfoResizable() {
|
---|
69 | assertFalse(testLayer.isInfoResizable());
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Test of {@link Layer#getAssociatedFile()} and {@link Layer#setAssociatedFile(java.io.File)}
|
---|
74 | */
|
---|
75 | @Test
|
---|
76 | public void testAssociatedFile() {
|
---|
77 | assertNull(testLayer.getAssociatedFile());
|
---|
78 |
|
---|
79 | File file = new File("test");
|
---|
80 | testLayer.setAssociatedFile(file);
|
---|
81 | assertEquals(file, testLayer.getAssociatedFile());
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Test {@link Layer#getName()}
|
---|
86 | */
|
---|
87 | @Test
|
---|
88 | public void testGetName() {
|
---|
89 | assertEquals("Test Layer", testLayer.getName());
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Test {@link Layer#setName(String)}
|
---|
94 | */
|
---|
95 | @Test
|
---|
96 | public void testSetName() {
|
---|
97 | testLayer.setName("Test Layer2");
|
---|
98 | assertEquals("Test Layer2", testLayer.getName());
|
---|
99 |
|
---|
100 | testLayer = new LayerManagerTest.TestLayer() {
|
---|
101 | @Override
|
---|
102 | public AbstractProperty<Color> getColorProperty() {
|
---|
103 | return new NamedColorProperty("test", Color.RED);
|
---|
104 | }
|
---|
105 | };
|
---|
106 |
|
---|
107 | testLayer.setName("Test Layer2");
|
---|
108 | testLayer.setName(null);
|
---|
109 | assertEquals("", testLayer.getName());
|
---|
110 | testLayer.setName("Test Layer3");
|
---|
111 | assertEquals("Test Layer3", testLayer.getName());
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Test {@link Layer#rename(String)} and {@link Layer#isRenamed()}
|
---|
116 | */
|
---|
117 | @Test
|
---|
118 | public void testRename() {
|
---|
119 | assertFalse(testLayer.isRenamed());
|
---|
120 | testLayer.rename("Test Layer2");
|
---|
121 | assertEquals("Test Layer2", testLayer.getName());
|
---|
122 | assertTrue(testLayer.isRenamed());
|
---|
123 | }
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Test {@link Layer#isBackgroundLayer()} and {@link Layer#setBackgroundLayer(boolean)}
|
---|
127 | */
|
---|
128 | @Test
|
---|
129 | public void testBackgroundLayer() {
|
---|
130 | assertFalse(testLayer.isBackgroundLayer());
|
---|
131 | testLayer.setBackgroundLayer(true);
|
---|
132 | assertTrue(testLayer.isBackgroundLayer());
|
---|
133 | }
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Test {@link Layer#isVisible()} and {@link Layer#setVisible(boolean)}
|
---|
137 | */
|
---|
138 | @Test
|
---|
139 | public void testVisible() {
|
---|
140 | assertTrue(testLayer.isVisible());
|
---|
141 | testLayer.setVisible(false);
|
---|
142 | assertFalse(testLayer.isVisible());
|
---|
143 | testLayer.setVisible(true);
|
---|
144 | assertTrue(testLayer.isVisible());
|
---|
145 | }
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * Test {@link Layer#toggleVisible()}
|
---|
149 | */
|
---|
150 | @Test
|
---|
151 | public void testToggleVisible() {
|
---|
152 | assertTrue(testLayer.isVisible());
|
---|
153 | testLayer.toggleVisible();
|
---|
154 | assertFalse(testLayer.isVisible());
|
---|
155 | testLayer.toggleVisible();
|
---|
156 | assertTrue(testLayer.isVisible());
|
---|
157 | }
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Test {@link Layer#setOpacity(double)} and {@link Layer#getOpacity()}
|
---|
161 | */
|
---|
162 | @Test
|
---|
163 | public void testOpacity() {
|
---|
164 | assertEquals(1, testLayer.getOpacity(), 1e-3);
|
---|
165 |
|
---|
166 | testLayer.setOpacity(0.5);
|
---|
167 | assertEquals(0.5, testLayer.getOpacity(), 1e-3);
|
---|
168 |
|
---|
169 | testLayer.setOpacity(0);
|
---|
170 | assertFalse(testLayer.isVisible());
|
---|
171 |
|
---|
172 | testLayer.setVisible(true);
|
---|
173 | assertTrue(testLayer.isVisible());
|
---|
174 | assertEquals(1, testLayer.getOpacity(), 1e-3);
|
---|
175 | }
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Test {@link Layer#isProjectionSupported(org.openstreetmap.josm.data.projection.Projection)}
|
---|
179 | */
|
---|
180 | @Test
|
---|
181 | public void testIsProjectionSupported() {
|
---|
182 | assertFalse(testLayer.isProjectionSupported(null));
|
---|
183 | assertTrue(testLayer.isProjectionSupported(Main.getProjection()));
|
---|
184 | }
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Test {@link Layer#nameSupportedProjections()}
|
---|
188 | */
|
---|
189 | @Test
|
---|
190 | public void testNameSupportedProjections() {
|
---|
191 | assertNotNull(testLayer.nameSupportedProjections());
|
---|
192 | }
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Test {@link Layer#isSavable()}
|
---|
196 | */
|
---|
197 | @Test
|
---|
198 | public void testIsSavable() {
|
---|
199 | assertFalse(testLayer.isSavable());
|
---|
200 | }
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Test {@link Layer#checkSaveConditions()}
|
---|
204 | */
|
---|
205 | @Test
|
---|
206 | public void testCheckSaveConditions() {
|
---|
207 | assertTrue(testLayer.checkSaveConditions());
|
---|
208 | }
|
---|
209 | }
|
---|