| | 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 | */ |
| | 30 | @ParameterizedTest |
| | 31 | @MethodSource |
| | 32 | void testNonRegression21203(final Object object) { |
| | 33 | final HistoryComboBox historyComboBox = new HistoryComboBox(); |
| | 34 | // Sanity check |
| | 35 | assertEquals(0, historyComboBox.getModel().getSize()); |
| | 36 | historyComboBox.getEditor().setItem(object); |
| | 37 | assertDoesNotThrow(historyComboBox::addCurrentItemToHistory); |
| | 38 | } |
| | 39 | |
| | 40 | /** |
| | 41 | * This ensures that we do throw on unknown objects for #21203 |
| | 42 | */ |
| | 43 | @Test |
| | 44 | void testNonRegression21203Throws() { |
| | 45 | final HistoryComboBox historyComboBox = new HistoryComboBox(); |
| | 46 | // Sanity check |
| | 47 | assertEquals(0, historyComboBox.getModel().getSize()); |
| | 48 | historyComboBox.getEditor().setItem(new Object()); |
| | 49 | IllegalArgumentException illegalArgumentException = assertThrows(IllegalArgumentException.class, |
| | 50 | historyComboBox::addCurrentItemToHistory); |
| | 51 | assertEquals("Object is not supported in addCurrentItemToHistory", illegalArgumentException.getMessage()); |
| | 52 | } |
| | 53 | } |