1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.layer;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertTrue;
|
---|
7 |
|
---|
8 | import org.junit.BeforeClass;
|
---|
9 | import org.junit.Test;
|
---|
10 | import org.openstreetmap.josm.JOSMFixture;
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
|
---|
13 | import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel;
|
---|
14 | import org.openstreetmap.josm.gui.layer.TMSLayer;
|
---|
15 | import org.openstreetmap.josm.gui.layer.TMSLayerTest;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Unit tests of {@link LayerVisibilityAction} class.
|
---|
19 | */
|
---|
20 | public class LayerVisibilityActionTest {
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Setup tests
|
---|
24 | */
|
---|
25 | @BeforeClass
|
---|
26 | public static void setUpBeforeClass() {
|
---|
27 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Unit test of {@link LayerVisibilityAction} class.
|
---|
32 | */
|
---|
33 | @Test
|
---|
34 | public void testLayerVisibilityAction() {
|
---|
35 | TMSLayer layer = TMSLayerTest.createTmsLayer();
|
---|
36 | try {
|
---|
37 | LayerListModel model = LayerListDialog.getInstance().getModel();
|
---|
38 | LayerVisibilityAction action = new LayerVisibilityAction(model);
|
---|
39 | action.updateEnabledState();
|
---|
40 | assertFalse(action.isEnabled());
|
---|
41 |
|
---|
42 | Main.getLayerManager().addLayer(layer);
|
---|
43 | action.updateEnabledState();
|
---|
44 | assertTrue(action.isEnabled());
|
---|
45 | assertTrue(action.supportLayers(model.getSelectedLayers()));
|
---|
46 |
|
---|
47 | // now check values
|
---|
48 | action.updateValues();
|
---|
49 | assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
|
---|
50 | assertEquals("OpacitySlider [getRealValue()=1.0]", action.opacitySlider.toString());
|
---|
51 |
|
---|
52 | action.opacitySlider.setRealValue(.5);
|
---|
53 | action.updateValues();
|
---|
54 |
|
---|
55 | assertEquals(0.5, action.opacitySlider.getRealValue(), 1e-15);
|
---|
56 | assertEquals("OpacitySlider [getRealValue()=0.5]", action.opacitySlider.toString());
|
---|
57 |
|
---|
58 | action.setVisibleFlag(false);
|
---|
59 | action.updateValues();
|
---|
60 | assertFalse(layer.isVisible());
|
---|
61 |
|
---|
62 | action.setVisibleFlag(true);
|
---|
63 | action.updateValues();
|
---|
64 | assertTrue(layer.isVisible());
|
---|
65 |
|
---|
66 | // layer stays visible during adjust
|
---|
67 | action.opacitySlider.setValueIsAdjusting(true);
|
---|
68 | action.opacitySlider.setRealValue(0);
|
---|
69 | assertEquals(0, layer.getOpacity(), 1e-15);
|
---|
70 | layer.setOpacity(.1); // to make layer.isVisible work
|
---|
71 | assertTrue(layer.isVisible());
|
---|
72 | layer.setOpacity(0);
|
---|
73 |
|
---|
74 | action.opacitySlider.setValueIsAdjusting(false);
|
---|
75 | action.opacitySlider.setRealValue(0);
|
---|
76 | assertEquals(0, layer.getOpacity(), 1e-15);
|
---|
77 | layer.setOpacity(.1); // to make layer.isVisible work
|
---|
78 | assertFalse(layer.isVisible());
|
---|
79 | layer.setOpacity(0);
|
---|
80 | action.updateValues();
|
---|
81 |
|
---|
82 | // Opacity reset when it was 0 and user set layer to visible.
|
---|
83 | action.setVisibleFlag(true);
|
---|
84 | action.updateValues();
|
---|
85 | assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
|
---|
86 | assertEquals(1.0, layer.getOpacity(), 1e-15);
|
---|
87 |
|
---|
88 | } finally {
|
---|
89 | Main.getLayerManager().removeLayer(layer);
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|