1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.properties;
|
---|
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 java.util.Arrays;
|
---|
9 | import java.util.Collections;
|
---|
10 |
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
14 | import org.openstreetmap.josm.data.osm.search.SearchParseError;
|
---|
15 | import org.openstreetmap.josm.data.osm.search.SearchSetting;
|
---|
16 | import org.openstreetmap.josm.data.preferences.CollectionProperty;
|
---|
17 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
18 |
|
---|
19 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests of {@link RecentTagCollection} class.
|
---|
23 | */
|
---|
24 | public class RecentTagCollectionTest {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Setup tests
|
---|
28 | */
|
---|
29 | @Rule
|
---|
30 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
31 | public JOSMTestRules test = new JOSMTestRules().preferences();
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Performs various tests on a {@link RecentTagCollection}.
|
---|
35 | *
|
---|
36 | * @throws SearchParseError if an error has been encountered while compiling
|
---|
37 | */
|
---|
38 | @Test
|
---|
39 | public void testVarious() throws SearchParseError {
|
---|
40 | final RecentTagCollection recentTags = new RecentTagCollection(2);
|
---|
41 | assertTrue(recentTags.isEmpty());
|
---|
42 |
|
---|
43 | final Tag foo = new Tag("name", "foo");
|
---|
44 | final Tag bar = new Tag("name", "bar");
|
---|
45 | final Tag baz = new Tag("name", "baz");
|
---|
46 | recentTags.add(foo);
|
---|
47 | recentTags.add(bar);
|
---|
48 | assertFalse(recentTags.isEmpty());
|
---|
49 | assertEquals(Arrays.asList(foo, bar), recentTags.toList());
|
---|
50 | recentTags.add(foo);
|
---|
51 | assertEquals(Arrays.asList(bar, foo), recentTags.toList());
|
---|
52 | recentTags.add(baz);
|
---|
53 | assertEquals(Arrays.asList(foo, baz), recentTags.toList());
|
---|
54 |
|
---|
55 | final CollectionProperty pref = new CollectionProperty("properties.recent-tags", Collections.<String>emptyList());
|
---|
56 | recentTags.saveToPreference(pref);
|
---|
57 | assertEquals(Arrays.asList("name", "foo", "name", "baz"), pref.get());
|
---|
58 | pref.put(Arrays.asList("key=", "=value"));
|
---|
59 | recentTags.loadFromPreference(pref);
|
---|
60 | assertEquals(Collections.singletonList(new Tag("key=", "=value")), recentTags.toList());
|
---|
61 |
|
---|
62 | recentTags.add(foo);
|
---|
63 | recentTags.add(bar);
|
---|
64 | recentTags.add(baz);
|
---|
65 | final SearchSetting searchSetting = new SearchSetting();
|
---|
66 | recentTags.ignoreTag(baz, searchSetting);
|
---|
67 | recentTags.ignoreTag(new Tag("something", "else"), searchSetting);
|
---|
68 | assertEquals("\"name\"=\"baz\" OR \"something\"=\"else\"", searchSetting.text);
|
---|
69 | assertEquals(Collections.singletonList(bar), recentTags.toList());
|
---|
70 | recentTags.add(baz);
|
---|
71 | assertEquals(Collections.singletonList(bar), recentTags.toList());
|
---|
72 | searchSetting.text = "";
|
---|
73 | recentTags.setTagsToIgnore(searchSetting);
|
---|
74 | assertEquals(Collections.singletonList(bar), recentTags.toList());
|
---|
75 | recentTags.add(baz);
|
---|
76 | assertEquals(Arrays.asList(bar, baz), recentTags.toList());
|
---|
77 | recentTags.ignoreTag(new Tag("name", /*all values */""), searchSetting);
|
---|
78 | assertEquals(Collections.emptyList(), recentTags.toList());
|
---|
79 | }
|
---|
80 | }
|
---|