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.BeforeClass;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.JOSMFixture;
|
---|
14 | import org.openstreetmap.josm.actions.search.SearchAction;
|
---|
15 | import org.openstreetmap.josm.actions.search.SearchCompiler;
|
---|
16 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
17 | import org.openstreetmap.josm.data.preferences.CollectionProperty;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Unit tests of {@link RecentTagCollection} class.
|
---|
21 | */
|
---|
22 | public 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 | }
|
---|