source: josm/trunk/test/unit/org/openstreetmap/josm/gui/mappaint/MapCSSWithExtendedTextDirectivesTest.java

Last change on this file was 18853, checked in by taylor.smock, 7 months ago

See #16567: Update to JUnit 5

This removes new JOSMTestRules() with no additional setup and most
JOSMFixture calls.

Removing the bare JOSMTestRules speeds up the test suite since there are two
fewer System.gc() calls per test.

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertInstanceOf;
6import static org.junit.jupiter.api.Assertions.assertNotNull;
7import static org.junit.jupiter.api.Assertions.assertNull;
8
9import java.awt.Color;
10
11import org.junit.jupiter.api.Test;
12import org.openstreetmap.josm.data.osm.Node;
13import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.TagKeyReference;
14import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy;
15import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy;
16import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel;
17
18/**
19 * Extended text directives tests.
20 */
21class MapCSSWithExtendedTextDirectivesTest {
22 /**
23 * Test {@link DeriveLabelFromNameTagsCompositionStrategy}
24 */
25 @Test
26 void testCreateAutoTextElement() {
27 MultiCascade mc = new MultiCascade();
28 Cascade c = mc.getOrCreateCascade("default");
29 c.put("text", new Keyword("auto"));
30 Node osm = new Node();
31 osm.put("ref", "A456");
32 Environment env = new Environment(osm, mc, "default", null);
33
34 TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */);
35 assertNotNull(te.labelCompositionStrategy);
36 assertInstanceOf(DeriveLabelFromNameTagsCompositionStrategy.class, te.labelCompositionStrategy);
37 }
38
39 /**
40 * Test {@link TagLookupCompositionStrategy}.
41 */
42 @Test
43 void testCreateTextElementComposingTextFromTag() {
44 MultiCascade mc = new MultiCascade();
45 Cascade c = mc.getOrCreateCascade("default");
46 c.put("text", new TagKeyReference("my_name"));
47 Node osm = new Node();
48 osm.put("my_name", "foobar");
49 Environment env = new Environment(osm, mc, "default", null);
50
51 TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */);
52 assertNotNull(te.labelCompositionStrategy);
53 assertInstanceOf(TagLookupCompositionStrategy.class, te.labelCompositionStrategy);
54 assertEquals("my_name", ((TagLookupCompositionStrategy) te.labelCompositionStrategy).getDefaultLabelTag());
55 }
56
57 /**
58 * Test null strategy.
59 */
60 @Test
61 void testCreateNullStrategy() {
62 MultiCascade mc = new MultiCascade();
63 Node osm = new Node();
64 Environment env = new Environment(osm, mc, "default", null);
65
66 TextLabel te = TextLabel.create(env, Color.WHITE, false /* no default annotate */);
67 assertNull(te);
68 }
69}
Note: See TracBrowser for help on using the repository browser.