source: josm/trunk/test/unit/org/openstreetmap/josm/gui/dialogs/properties/RecentTagCollectionTest.java@ 10758

Last change on this file since 10758 was 10758, checked in by Don-vip, 8 years ago

sonar - squid:S3578 - Test methods should comply with a naming convention

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.properties;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertTrue;
7
8import java.util.Arrays;
9import java.util.Collections;
10
11import org.junit.BeforeClass;
12import org.junit.Test;
13import org.openstreetmap.josm.JOSMFixture;
14import org.openstreetmap.josm.actions.search.SearchAction;
15import org.openstreetmap.josm.actions.search.SearchCompiler;
16import org.openstreetmap.josm.data.osm.Tag;
17import org.openstreetmap.josm.data.preferences.CollectionProperty;
18
19/**
20 * Unit tests of {@link RecentTagCollection} class.
21 */
22public class RecentTagCollectionTest {
23
24 /**
25 * Setup tests
26 */
27 @BeforeClass
28 public static void setUpBeforeClass() {
29 JOSMFixture.createUnitTestFixture().init();
30 }
31
32 /**
33 * Performs various tests on a {@link RecentTagCollection}.
34 *
35 * @throws SearchCompiler.ParseError if an error has been encountered while compiling
36 */
37 @Test
38 public void testVarious() throws SearchCompiler.ParseError {
39 final RecentTagCollection recentTags = new RecentTagCollection(2);
40 assertTrue(recentTags.isEmpty());
41
42 final Tag foo = new Tag("name", "foo");
43 final Tag bar = new Tag("name", "bar");
44 final Tag baz = new Tag("name", "baz");
45 recentTags.add(foo);
46 recentTags.add(bar);
47 assertFalse(recentTags.isEmpty());
48 assertEquals(Arrays.asList(foo, bar), recentTags.toList());
49 recentTags.add(foo);
50 assertEquals(Arrays.asList(bar, foo), recentTags.toList());
51 recentTags.add(baz);
52 assertEquals(Arrays.asList(foo, baz), recentTags.toList());
53
54 final CollectionProperty pref = new CollectionProperty("properties.recent-tags", Collections.<String>emptyList());
55 recentTags.saveToPreference(pref);
56 assertEquals(Arrays.asList("name", "foo", "name", "baz"), pref.get());
57 pref.put(Arrays.asList("key=", "=value"));
58 recentTags.loadFromPreference(pref);
59 assertEquals(Collections.singletonList(new Tag("key=", "=value")), recentTags.toList());
60
61 recentTags.add(foo);
62 recentTags.add(bar);
63 recentTags.add(baz);
64 final SearchAction.SearchSetting searchSetting = new SearchAction.SearchSetting();
65 recentTags.ignoreTag(baz, searchSetting);
66 recentTags.ignoreTag(new Tag("something", "else"), searchSetting);
67 assertEquals("\"name\"=\"baz\" OR \"something\"=\"else\"", searchSetting.text);
68 assertEquals(Collections.singletonList(bar), recentTags.toList());
69 recentTags.add(baz);
70 assertEquals(Collections.singletonList(bar), recentTags.toList());
71 searchSetting.text = "";
72 recentTags.setTagsToIgnore(searchSetting);
73 assertEquals(Collections.singletonList(bar), recentTags.toList());
74 recentTags.add(baz);
75 assertEquals(Arrays.asList(bar, baz), recentTags.toList());
76 recentTags.ignoreTag(new Tag("name", /*all values */""), searchSetting);
77 assertEquals(Collections.emptyList(), recentTags.toList());
78 }
79}
Note: See TracBrowser for help on using the repository browser.