1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.widgets;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
---|
7 |
|
---|
8 | import java.util.stream.Stream;
|
---|
9 |
|
---|
10 | import org.junit.jupiter.api.Test;
|
---|
11 | import org.junit.jupiter.params.ParameterizedTest;
|
---|
12 | import org.junit.jupiter.params.provider.Arguments;
|
---|
13 | import org.junit.jupiter.params.provider.MethodSource;
|
---|
14 | import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
|
---|
15 | import org.openstreetmap.josm.testutils.annotations.FullPreferences;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Test class for {@link HistoryComboBox}
|
---|
19 | * @author Taylor Smock
|
---|
20 | */
|
---|
21 | @FullPreferences
|
---|
22 | class 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 | }
|
---|