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

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

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.properties;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertFalse;
6import static org.junit.jupiter.api.Assertions.assertTrue;
7
8import java.util.Arrays;
9import java.util.Collections;
10
11import org.junit.jupiter.api.extension.RegisterExtension;
12import org.junit.jupiter.api.Test;
13import org.openstreetmap.josm.data.osm.Tag;
14import org.openstreetmap.josm.data.osm.search.SearchParseError;
15import org.openstreetmap.josm.data.osm.search.SearchSetting;
16import org.openstreetmap.josm.data.preferences.ListProperty;
17import org.openstreetmap.josm.testutils.JOSMTestRules;
18
19import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
20
21/**
22 * Unit tests of {@link RecentTagCollection} class.
23 */
24class RecentTagCollectionTest {
25
26 /**
27 * Setup tests
28 */
29 @RegisterExtension
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 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 ListProperty pref = new ListProperty("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}
Note: See TracBrowser for help on using the repository browser.