Changeset 14048 in josm for trunk/test


Ignore:
Timestamp:
2018-07-24T23:25:24+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16498 - convert more unit tests to Java

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  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.mappaint
     2package org.openstreetmap.josm.gui.mappaint;
    33
    4 import junit.framework.TestCase
     4import org.junit.runner.RunWith;
     5import org.junit.runners.Suite;
     6import org.openstreetmap.josm.gui.mappaint.mapcss.AllMapCSSTests;
    57
    6 import org.junit.runner.RunWith
    7 import org.junit.runners.Suite
    8 import org.openstreetmap.josm.gui.mappaint.mapcss.AllMapCSSTests
     8import junit.framework.TestCase;
    99
     10/**
     11 * All mappaint tests.
     12 */
    1013@RunWith(Suite.class)
    11 @Suite.SuiteClasses([
     14@Suite.SuiteClasses({
    1215    LabelCompositionStrategyTest.class,
    1316    MapCSSWithExtendedTextDirectivesTest.class,
    1417    AllMapCSSTests.class
     18})
     19public class AllMappaintTests extends TestCase{
    1520
    16 ])
    17 public class AllMappaintTests extends TestCase{}
    18 
     21}
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/LabelCompositionStrategyTest.java

    r14043 r14048  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.mappaint
     2package org.openstreetmap.josm.gui.mappaint;
    33
    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
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertNull;
    106
    11 class LabelCompositionStrategyTest {
     7import java.util.Arrays;
     8import java.util.Collections;
    129
    13     @BeforeClass
    14     public static void createJOSMFixture(){
    15         JOSMFixture.createUnitTestFixture().init()
     10import org.junit.Rule;
     11import org.junit.Test;
     12import org.openstreetmap.josm.data.osm.Node;
     13import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy;
     14import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy;
     15import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.StaticLabelCompositionStrategy;
     16import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy;
     17import org.openstreetmap.josm.testutils.JOSMTestRules;
     18
     19import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     20
     21/**
     22 * Unit tests of {@link LabelCompositionStrategy}.
     23 */
     24public 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));
    1645    }
    1746
     47    /**
     48     * Test {@link TagLookupCompositionStrategy}.
     49     */
    1850    @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");
    2154
    22         def strat = new StaticLabelCompositionStrategy(null)
    23         assert strat.compose(n) == null
     55        LabelCompositionStrategy strat = new TagLookupCompositionStrategy(null);
     56        assertNull(strat.compose(n));
    2457
    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));
    2763    }
    2864
     65    /**
     66     * Test {@link DeriveLabelFromNameTagsCompositionStrategy}.
     67     */
    2968    @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());
    3373
    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());
    3677
    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));
    3981
    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));
    6586    }
    6687}
    67 
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/MapCSSWithExtendedTextDirectivesTest.java

    r14043 r14048  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.mappaint
    3 import java.awt.Color
     2package org.openstreetmap.josm.gui.mappaint;
    43
    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
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertNotNull;
     6import static org.junit.Assert.assertNull;
     7import static org.junit.Assert.assertTrue;
    128
    13 class MapCSSWithExtendedTextDirectivesTest {
     9import java.awt.Color;
    1410
    15     @BeforeClass
    16     public static void createJOSMFixture(){
    17         JOSMFixture.createUnitTestFixture().init()
     11import org.junit.Rule;
     12import org.junit.Test;
     13import org.openstreetmap.josm.data.osm.Node;
     14import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.TagKeyReference;
     15import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy;
     16import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy;
     17import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel;
     18import org.openstreetmap.josm.testutils.JOSMTestRules;
     19
     20import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     21
     22/**
     23 * Extended text directives tests.
     24 */
     25public 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);
    1849    }
    1950
     51    /**
     52     * Test {@link TagLookupCompositionStrategy}.
     53     */
    2054    @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);
    2862
    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());
    3267    }
    3368
     69    /**
     70     * Test null strategy.
     71     */
    3472    @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);
    4277
    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);
    5780    }
    5881}
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/AllMapCSSTests.java

    r14043 r14048  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.mappaint.mapcss
     2package org.openstreetmap.josm.gui.mappaint.mapcss;
    33
    4 import junit.framework.TestCase
     4import org.junit.runner.RunWith;
     5import org.junit.runners.Suite;
    56
    6 import org.junit.runner.RunWith
    7 import org.junit.runners.Suite
     7import junit.framework.TestCase;
    88
     9/**
     10 * All MapCSS tests.
     11 */
    912@RunWith(Suite.class)
    10 @Suite.SuiteClasses([
     13@Suite.SuiteClasses({
    1114    KeyValueConditionTest.class,
    1215    ParsingLinkSelectorTest.class,
    1316    KeyConditionTest.class,
    1417    MapCSSParserTest.class,
    15     ChildOrParentSelectorTest
    16 ])
    17 public class AllMapCSSTests extends TestCase{}
     18    ChildOrParentSelectorTest.class
     19})
     20public class AllMapCSSTests extends TestCase{
    1821
     22}
  • trunk/test/unit/org/openstreetmap/josm/io/OsmChangeBuilderTest.java

    r14047 r14048  
    105105                "<osmChange version=\"0.6\" generator=\"JOSM\">%n" +
    106106                "<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" +
    108108                "</create>%n" +
    109109                "</osmChange>%n"), builder.getDocument());
     
    183183                "</delete>%n" +
    184184                "<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" +
    186186                "</create>%n" +
    187187                "<modify>%n" +
Note: See TracChangeset for help on using the changeset viewer.