source: josm/trunk/test/unit/org/openstreetmap/josm/gui/widgets/HistoryComboBoxTest.java@ 18126

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

fix #21203 - CCE in HistoryComboBox#addCurrentItemToHistory (patch by taylor.smock)

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.widgets;
3
4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
5import static org.junit.jupiter.api.Assertions.assertEquals;
6import static org.junit.jupiter.api.Assertions.assertThrows;
7
8import java.util.stream.Stream;
9
10import org.junit.jupiter.api.Test;
11import org.junit.jupiter.params.ParameterizedTest;
12import org.junit.jupiter.params.provider.Arguments;
13import org.junit.jupiter.params.provider.MethodSource;
14import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
15import org.openstreetmap.josm.testutils.annotations.FullPreferences;
16
17/**
18 * Test class for {@link HistoryComboBox}
19 * @author Taylor Smock
20 */
21@FullPreferences
22class HistoryComboBoxTest {
23 static Stream<Arguments> testNonRegression21203() {
24 return Stream.of(Arguments.of("Hello world"), Arguments.of(new AutoCompletionItem("Hello world2")));
25 }
26
27 /**
28 * Non-regression test for #21203
29 * @param object object to set as editor item
30 */
31 @ParameterizedTest
32 @MethodSource
33 void testNonRegression21203(final Object object) {
34 final HistoryComboBox historyComboBox = new HistoryComboBox();
35 // Sanity check
36 assertEquals(0, historyComboBox.getModel().getSize());
37 historyComboBox.getEditor().setItem(object);
38 assertDoesNotThrow(historyComboBox::addCurrentItemToHistory);
39 }
40
41 /**
42 * This ensures that we do throw on unknown objects for #21203
43 */
44 @Test
45 void testNonRegression21203Throws() {
46 final HistoryComboBox historyComboBox = new HistoryComboBox();
47 // Sanity check
48 assertEquals(0, historyComboBox.getModel().getSize());
49 historyComboBox.getEditor().setItem(new Object());
50 IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class,
51 historyComboBox::addCurrentItemToHistory);
52 assertEquals("Object is not supported in addCurrentItemToHistory", illegalArgumentException.getMessage());
53 }
54}
Note: See TracBrowser for help on using the repository browser.