5
5
import static org .hamcrest .CoreMatchers .is ;
6
6
import static org .hamcrest .CoreMatchers .nullValue ;
7
7
import static org .hamcrest .MatcherAssert .assertThat ;
8
- import static org .junit .Assert .assertEquals ;
9
- import static org .junit .Assert .assertTrue ;
8
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
9
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
10
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
10
11
11
12
import java .util .Arrays ;
12
13
import java .util .Collection ;
17
18
import java .util .stream .Collectors ;
18
19
import java .util .stream .IntStream ;
19
20
import java .util .stream .Stream ;
20
- import org .junit .Rule ;
21
- import org .junit .Test ;
21
+
22
+ import org .junit .jupiter .api .Test ;
23
+ import org .junit .jupiter .api .Timeout ;
22
24
import org .openstreetmap .josm .data .coor .LatLon ;
23
- import org .openstreetmap .josm .testutils .JOSMTestRules ;
25
+ import org .openstreetmap .josm .testutils .annotations . I18n ;
24
26
import org .wikipedia .data .WikidataEntry ;
25
27
import org .wikipedia .data .WikipediaEntry ;
26
28
27
- public class WikipediaAppTest {
28
-
29
- /**
30
- * Setup test.
31
- */
32
- @ Rule
33
- public JOSMTestRules rules = new JOSMTestRules ().preferences ().timeout (20_000 ).i18n ("en" );
34
-
29
+ @ Timeout (20 )
30
+ @ I18n
31
+ class WikipediaAppTest {
35
32
@ Test
36
- public void testMediawikiLocale () throws Exception {
33
+ void testMediawikiLocale () {
37
34
assertThat (WikipediaApp .getMediawikiLocale (Locale .GERMANY ), is ("de-de" ));
38
35
assertThat (WikipediaApp .getMediawikiLocale (Locale .GERMAN ), is ("de" ));
39
36
assertThat (WikipediaApp .getMediawikiLocale (Locale .UK ), is ("en-gb" ));
40
37
assertThat (WikipediaApp .getMediawikiLocale (Locale .CANADA ), is ("en-ca" ));
41
38
}
42
39
43
40
@ Test
44
- public void testPartitionList () {
41
+ void testPartitionList () {
45
42
assertThat (
46
43
WikipediaApp .partitionList (Arrays .asList (1 , 2 , 3 , 4 , 5 ), 2 ),
47
44
is (Arrays .asList (
48
45
Arrays .asList (1 , 2 ),
49
46
Arrays .asList (3 , 4 ),
50
- Arrays . asList (5 )
47
+ Collections . singletonList (5 )
51
48
))
52
49
);
53
50
}
54
51
55
52
@ Test
56
- public void testGetInterwikiArticles1 () {
53
+ void testGetInterwikiArticles1 () {
57
54
final Collection <WikipediaEntry > iw = WikipediaApp .forLanguage ("de" ).getInterwikiArticles ("Österreich" );
58
55
assertThat (iw , hasItem (new WikipediaEntry ("en" , "Austria" )));
59
56
assertThat (iw , hasItem (new WikipediaEntry ("nb" , "Østerrike" )));
60
57
assertThat (iw , hasItem (new WikipediaEntry ("ko" , "오스트리아" )));
61
58
}
62
59
63
60
@ Test
64
- public void testGetInterwikiArticles2 () {
61
+ void testGetInterwikiArticles2 () {
65
62
final Collection <WikipediaEntry > iw = WikipediaApp .forLanguage ("en" ).getInterwikiArticles ("Ampersand" );
66
63
assertThat (iw , hasItem (new WikipediaEntry ("fi" , "&" )));
67
64
}
68
65
69
66
@ Test
70
- public void testGetCoordinates () throws Exception {
67
+ void testGetCoordinates () {
71
68
assertThat (WikipediaApp .forLanguage ("de" ).getCoordinateForArticle ("Marchreisenspitze" ), is (new LatLon (47.1725 , 11.30833333 )));
72
69
assertThat (WikipediaApp .forLanguage ("en" ).getCoordinateForArticle ("Austria" ), is (new LatLon (47.33333333 , 13.33333333 )));
73
70
assertThat (WikipediaApp .forLanguage ("en" ).getCoordinateForArticle ("Foobar2000" ), nullValue ());
74
71
}
75
72
76
73
@ Test
77
- public void testFromCoordinates () throws Exception {
74
+ void testFromCoordinates () {
78
75
final List <WikipediaEntry > entries = WikipediaApp .forLanguage ("de" )
79
76
.getEntriesFromCoordinates (new LatLon (52.5179786 , 13.3753321 ), new LatLon (52.5192215 , 13.3768705 ));
80
77
final long c = entries .stream ()
@@ -84,7 +81,7 @@ public void testFromCoordinates() throws Exception {
84
81
}
85
82
86
83
@ Test
87
- public void testForQuery () {
84
+ void testForQuery () {
88
85
final List <WikidataEntry > de = WikipediaApp .getWikidataEntriesForQuery ("de" , "Österreich" , Locale .GERMAN );
89
86
final List <WikidataEntry > en = WikipediaApp .getWikidataEntriesForQuery ("de" , "Österreich" , Locale .ENGLISH );
90
87
assertThat (de .get (0 ).article , is ("Q40" ));
@@ -96,7 +93,7 @@ public void testForQuery() {
96
93
}
97
94
98
95
@ Test
99
- public void testFromCoordinatesWikidata () throws Exception {
96
+ void testFromCoordinatesWikidata () {
100
97
final List <WikipediaEntry > entries = WikipediaApp .forLanguage ("wikidata" )
101
98
.getEntriesFromCoordinates (new LatLon (47.20 , 11.30 ), new LatLon (47.22 , 11.32 ));
102
99
final long c = entries .stream ()
@@ -107,7 +104,7 @@ public void testFromCoordinatesWikidata() throws Exception {
107
104
}
108
105
109
106
@ Test
110
- public void testGetWikidataForArticles () {
107
+ void testGetWikidataForArticles () {
111
108
final Map <String , String > map = WikipediaApp .forLanguage ("en" )
112
109
.getWikidataForArticles (Arrays .asList ("London" , "Vienna" , "Völs, Tyrol" , "a-non-existing-article" ));
113
110
assertThat (map .get ("London" ), is ("Q84" ));
@@ -118,7 +115,7 @@ public void testGetWikidataForArticles() {
118
115
}
119
116
120
117
@ Test
121
- public void testGetWikidataForArticlesResolveRedirects () throws Exception {
118
+ void testGetWikidataForArticlesResolveRedirects () {
122
119
final Map <String , String > map = WikipediaApp .forLanguage ("en" )
123
120
.getWikidataForArticles (Arrays .asList ("einstein" , "USA" ));
124
121
assertThat (map .get ("einstein" ), is ("Q937" ));
@@ -127,7 +124,7 @@ public void testGetWikidataForArticlesResolveRedirects() throws Exception {
127
124
}
128
125
129
126
@ Test
130
- public void testTicket13991 () {
127
+ void testTicket13991 () {
131
128
final Map <String , String > map = WikipediaApp .forLanguage ("en" )
132
129
.getWikidataForArticles (Stream .iterate ("London" , x -> x ).limit (100 ).collect (Collectors .toList ()));
133
130
assertThat (map , is (Collections .singletonMap ("London" , "Q84" )));
@@ -138,7 +135,7 @@ public void testTicket13991() {
138
135
}
139
136
140
137
@ Test
141
- public void testGetLabelForWikidata () throws Exception {
138
+ void testGetLabelForWikidata () {
142
139
assertThat (WikipediaApp .getLabelForWikidata ("Q1741" , Locale .GERMAN ), is ("Wien" ));
143
140
assertThat (WikipediaApp .getLabelForWikidata ("Q1741" , Locale .ENGLISH ), is ("Vienna" ));
144
141
// fallback to any label
@@ -152,13 +149,13 @@ public void testGetLabelForWikidata() throws Exception {
152
149
assertThat (twoLabels .get (1 ).label , is ("Wien" ));
153
150
}
154
151
155
- @ Test ( expected = RuntimeException . class )
156
- public void testGetLabelForWikidataInvalidId () throws Exception {
157
- WikipediaApp .getLabelForWikidata ("Qxyz" , Locale .ENGLISH );
152
+ @ Test
153
+ void testGetLabelForWikidataInvalidId () {
154
+ assertThrows ( RuntimeException . class , () -> WikipediaApp .getLabelForWikidata ("Qxyz" , Locale .ENGLISH ) );
158
155
}
159
156
160
157
@ Test
161
- public void testWIWOSMStatus () throws Exception {
158
+ void testWIWOSMStatus () {
162
159
final WikipediaEntry entry1 = new WikipediaEntry ("en" , "Vienna" );
163
160
final WikipediaEntry entry2 = new WikipediaEntry ("en" , "London" );
164
161
final WikipediaEntry entry3 = new WikipediaEntry ("en" , "a-non-existing-article" );
@@ -169,13 +166,13 @@ public void testWIWOSMStatus() throws Exception {
169
166
}
170
167
171
168
@ Test
172
- public void testCategoriesForPrefix () throws Exception {
169
+ void testCategoriesForPrefix () {
173
170
final List <String > categories = WikipediaApp .forLanguage ("de" ).getCategoriesForPrefix ("Gemeinde in Öster" );
174
171
assertTrue (categories .contains ("Gemeinde in Österreich" ));
175
172
}
176
173
177
174
@ Test
178
- public void testEntriesFromClipboard () {
175
+ void testEntriesFromClipboard () {
179
176
List <WikipediaEntry > entries = WikipediaApp .getEntriesFromClipboard ("de" , "foo\n de:bar\n en:baz\n " );
180
177
assertThat (entries .size (), is (3 ));
181
178
assertThat (entries .get (0 ), is (new WikipediaEntry ("de" , "foo" )));
@@ -184,7 +181,7 @@ public void testEntriesFromClipboard() {
184
181
}
185
182
186
183
@ Test
187
- public void testEntriesFromClipboardWikidata () {
184
+ void testEntriesFromClipboardWikidata () {
188
185
List <WikipediaEntry > entries = WikipediaApp .getEntriesFromClipboard ("wikidata" , "Q40\n Q151897" );
189
186
assertThat (entries .size (), is (2 ));
190
187
assertThat (entries .get (0 ).article , is ("Q40" ));
0 commit comments