Changeset 14048 in josm for trunk/test/unit/org
- Timestamp:
- 2018-07-24T23:25:24+02:00 (6 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 1 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/AllMappaintTests.java
r14043 r14048 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.mappaint 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import junit.framework.TestCase 4 import org.junit.runner.RunWith; 5 import org.junit.runners.Suite; 6 import org.openstreetmap.josm.gui.mappaint.mapcss.AllMapCSSTests; 5 7 6 import org.junit.runner.RunWith 7 import org.junit.runners.Suite 8 import org.openstreetmap.josm.gui.mappaint.mapcss.AllMapCSSTests 8 import junit.framework.TestCase; 9 9 10 /** 11 * All mappaint tests. 12 */ 10 13 @RunWith(Suite.class) 11 @Suite.SuiteClasses( [14 @Suite.SuiteClasses({ 12 15 LabelCompositionStrategyTest.class, 13 16 MapCSSWithExtendedTextDirectivesTest.class, 14 17 AllMapCSSTests.class 18 }) 19 public class AllMappaintTests extends TestCase{ 15 20 16 ]) 17 public class AllMappaintTests extends TestCase{} 18 21 } -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/LabelCompositionStrategyTest.java
r14043 r14048 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.mappaint 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import org.junit.* 5 import org.openstreetmap.josm.JOSMFixture 6 import org.openstreetmap.josm.data.osm.Node 7 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy 8 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.StaticLabelCompositionStrategy 9 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertNull; 10 6 11 class LabelCompositionStrategyTest { 7 import java.util.Arrays; 8 import java.util.Collections; 12 9 13 @BeforeClass 14 public static void createJOSMFixture(){ 15 JOSMFixture.createUnitTestFixture().init() 10 import org.junit.Rule; 11 import org.junit.Test; 12 import org.openstreetmap.josm.data.osm.Node; 13 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy; 14 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy; 15 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.StaticLabelCompositionStrategy; 16 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy; 17 import org.openstreetmap.josm.testutils.JOSMTestRules; 18 19 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 20 21 /** 22 * Unit tests of {@link LabelCompositionStrategy}. 23 */ 24 public class LabelCompositionStrategyTest { 25 26 /** 27 * Setup rule 28 */ 29 @Rule 30 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 31 public JOSMTestRules test = new JOSMTestRules(); 32 33 /** 34 * Test {@link StaticLabelCompositionStrategy}. 35 */ 36 @Test 37 public void testCreateStaticLabelCompositionStrategy() { 38 Node n = new Node(); 39 40 LabelCompositionStrategy strat = new StaticLabelCompositionStrategy(null); 41 assertNull(strat.compose(n)); 42 43 strat = new StaticLabelCompositionStrategy("a label"); 44 assertEquals("a label", strat.compose(n)); 16 45 } 17 46 47 /** 48 * Test {@link TagLookupCompositionStrategy}. 49 */ 18 50 @Test 19 public void createStaticLabelCompositionStrategy() { 20 def n = new Node() 51 public void testCreateTagLookupCompositionStrategy() { 52 Node n = new Node(); 53 n.put("my-tag", "my-value"); 21 54 22 def strat = new StaticLabelCompositionStrategy(null)23 assert strat.compose(n) == null55 LabelCompositionStrategy strat = new TagLookupCompositionStrategy(null); 56 assertNull(strat.compose(n)); 24 57 25 strat = new StaticLabelCompositionStrategy("a label") 26 assert strat.compose(n) == "a label" 58 strat = new TagLookupCompositionStrategy("name"); 59 assertNull(strat.compose(n)); 60 61 strat = new TagLookupCompositionStrategy("my-tag"); 62 assertEquals("my-value", strat.compose(n)); 27 63 } 28 64 65 /** 66 * Test {@link DeriveLabelFromNameTagsCompositionStrategy}. 67 */ 29 68 @Test 30 public void createTagLookupCompositionStrategy() { 31 def n = new Node() 32 n.put("my-tag", "my-value") 69 public void testCreateDeriveLabelFromNameTagsCompositionStrategy() { 70 DeriveLabelFromNameTagsCompositionStrategy strat = new DeriveLabelFromNameTagsCompositionStrategy(); 71 strat.setNameTags(null); 72 assertEquals(Collections.emptyList(), strat.getNameTags()); 33 73 34 def strat = new TagLookupCompositionStrategy(null) 35 assert strat.compose(n) == null 74 strat = new DeriveLabelFromNameTagsCompositionStrategy(); 75 strat.setNameTags(Arrays.asList("name", "brand")); 76 assertEquals(Arrays.asList("name", "brand"), strat.getNameTags()); 36 77 37 strat = new TagLookupCompositionStrategy("name") 38 assert strat.compose(n) == null 78 Node n = new Node(); 79 n.put("brand", "my brand"); 80 assertEquals("my brand", strat.compose(n)); 39 81 40 strat = new TagLookupCompositionStrategy("my-tag") 41 assert strat.compose(n) == "my-value" 42 } 43 44 @Test 45 public void createDeriveLabelFromNameTagsCompositionStrategy() { 46 def n 47 def strat 48 49 strat = new DeriveLabelFromNameTagsCompositionStrategy() 50 strat.setNameTags(null) 51 assert strat.getNameTags() == [] 52 53 strat = new DeriveLabelFromNameTagsCompositionStrategy() 54 strat.setNameTags(["name", "brand"]) 55 assert strat.getNameTags() == ["name", "brand"] 56 57 n = new Node() 58 n.put("brand", "my brand") 59 assert strat.compose(n) == "my brand" 60 61 n = new Node() 62 n.put("name", "my name") 63 n.put("brand", "my brand") 64 assert strat.compose(n) == "my name" 82 n = new Node(); 83 n.put("name", "my name"); 84 n.put("brand", "my brand"); 85 assertEquals("my name", strat.compose(n)); 65 86 } 66 87 } 67 -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/MapCSSWithExtendedTextDirectivesTest.java
r14043 r14048 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.mappaint 3 import java.awt.Color 2 package org.openstreetmap.josm.gui.mappaint; 4 3 5 import org.junit.* 6 import org.openstreetmap.josm.JOSMFixture 7 import org.openstreetmap.josm.data.osm.Node 8 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.TagKeyReference 9 import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel 10 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy 11 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertNotNull; 6 import static org.junit.Assert.assertNull; 7 import static org.junit.Assert.assertTrue; 12 8 13 class MapCSSWithExtendedTextDirectivesTest { 9 import java.awt.Color; 14 10 15 @BeforeClass 16 public static void createJOSMFixture(){ 17 JOSMFixture.createUnitTestFixture().init() 11 import org.junit.Rule; 12 import org.junit.Test; 13 import org.openstreetmap.josm.data.osm.Node; 14 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.TagKeyReference; 15 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy; 16 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy; 17 import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel; 18 import org.openstreetmap.josm.testutils.JOSMTestRules; 19 20 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 21 22 /** 23 * Extended text directives tests. 24 */ 25 public class MapCSSWithExtendedTextDirectivesTest { 26 27 /** 28 * Setup rule 29 */ 30 @Rule 31 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 32 public JOSMTestRules test = new JOSMTestRules(); 33 34 /** 35 * Test {@link DeriveLabelFromNameTagsCompositionStrategy} 36 */ 37 @Test 38 public void testCreateAutoTextElement() { 39 MultiCascade mc = new MultiCascade(); 40 Cascade c = mc.getOrCreateCascade("default"); 41 c.put("text", new Keyword("auto")); 42 Node osm = new Node(); 43 osm.put("ref", "A456"); 44 Environment env = new Environment(osm, mc, "default", null); 45 46 TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */); 47 assertNotNull(te.labelCompositionStrategy); 48 assertTrue(te.labelCompositionStrategy instanceof DeriveLabelFromNameTagsCompositionStrategy); 18 49 } 19 50 51 /** 52 * Test {@link TagLookupCompositionStrategy}. 53 */ 20 54 @Test 21 public void createAutoTextElement() {22 MultiCascade mc = new MultiCascade() 23 Cascade c = mc.getOrCreateCascade("default") 24 c.put("text", new Keyword("auto"))25 Node osm = new Node() 26 osm.put(" ref", "A456");27 Environment env = new Environment(osm, mc, "default", null) 55 public void testCreateTextElementComposingTextFromTag() { 56 MultiCascade mc = new MultiCascade(); 57 Cascade c = mc.getOrCreateCascade("default"); 58 c.put("text", new TagKeyReference("my_name")); 59 Node osm = new Node(); 60 osm.put("my_name", "foobar"); 61 Environment env = new Environment(osm, mc, "default", null); 28 62 29 TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */) 30 assert te.labelCompositionStrategy != null 31 assert te.labelCompositionStrategy instanceof DeriveLabelFromNameTagsCompositionStrategy 63 TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */); 64 assertNotNull(te.labelCompositionStrategy); 65 assertTrue(te.labelCompositionStrategy instanceof TagLookupCompositionStrategy); 66 assertEquals("my_name", ((TagLookupCompositionStrategy) te.labelCompositionStrategy).getDefaultLabelTag()); 32 67 } 33 68 69 /** 70 * Test null strategy. 71 */ 34 72 @Test 35 public void createTextElementComposingTextFromTag() { 36 MultiCascade mc = new MultiCascade() 37 Cascade c = mc.getOrCreateCascade("default") 38 c.put("text", new TagKeyReference("my_name")) 39 Node osm = new Node() 40 osm.put("my_name", "foobar"); 41 Environment env = new Environment(osm, mc, "default", null) 73 public void testCreateNullStrategy() { 74 MultiCascade mc = new MultiCascade(); 75 Node osm = new Node(); 76 Environment env = new Environment(osm, mc, "default", null); 42 77 43 TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */) 44 assert te.labelCompositionStrategy != null 45 assert te.labelCompositionStrategy instanceof TagLookupCompositionStrategy 46 assert te.labelCompositionStrategy.getDefaultLabelTag() == "my_name" 47 } 48 49 @Test 50 public void createNullStrategy() { 51 MultiCascade mc = new MultiCascade() 52 Node osm = new Node() 53 Environment env = new Environment(osm, mc, "default", null) 54 55 TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */) 56 assert te == null 78 TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */); 79 assertNull(te); 57 80 } 58 81 } -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/AllMapCSSTests.java
r14043 r14048 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.mappaint.mapcss 2 package org.openstreetmap.josm.gui.mappaint.mapcss; 3 3 4 import junit.framework.TestCase 4 import org.junit.runner.RunWith; 5 import org.junit.runners.Suite; 5 6 6 import org.junit.runner.RunWith 7 import org.junit.runners.Suite 7 import junit.framework.TestCase; 8 8 9 /** 10 * All MapCSS tests. 11 */ 9 12 @RunWith(Suite.class) 10 @Suite.SuiteClasses( [13 @Suite.SuiteClasses({ 11 14 KeyValueConditionTest.class, 12 15 ParsingLinkSelectorTest.class, 13 16 KeyConditionTest.class, 14 17 MapCSSParserTest.class, 15 ChildOrParentSelectorTest 16 ])17 public class AllMapCSSTests extends TestCase{ }18 ChildOrParentSelectorTest.class 19 }) 20 public class AllMapCSSTests extends TestCase{ 18 21 22 } -
trunk/test/unit/org/openstreetmap/josm/io/OsmChangeBuilderTest.java
r14047 r14048 105 105 "<osmChange version=\"0.6\" generator=\"JOSM\">%n" + 106 106 "<create>%n" + 107 " <node id=' -6' changeset='1' lat='0.0' lon='0.0' />%n" +107 " <node id='" + n.getUniqueId() + "' changeset='1' lat='0.0' lon='0.0' />%n" + 108 108 "</create>%n" + 109 109 "</osmChange>%n"), builder.getDocument()); … … 183 183 "</delete>%n" + 184 184 "<create>%n" + 185 " <node id=' -3' changeset='1' lat='0.0' lon='0.0' />%n" +185 " <node id='" + n2.getUniqueId() + "' changeset='1' lat='0.0' lon='0.0' />%n" + 186 186 "</create>%n" + 187 187 "<modify>%n" +
Note:
See TracChangeset
for help on using the changeset viewer.