99import java .util .List ;
1010import java .util .Map ;
1111
12- import static com .dampcake .bencode .Assert .assertThrows ;
1312import static org .hamcrest .CoreMatchers .instanceOf ;
13+ import static org .hamcrest .MatcherAssert .assertThat ;
1414import static org .junit .Assert .assertEquals ;
15- import static org .junit .Assert .assertThat ;
15+ import static org .junit .Assert .assertThrows ;
1616import static org .junit .Assert .assertTrue ;
1717
1818/**
@@ -108,38 +108,23 @@ public void testReadStringEmpty() throws Exception {
108108 public void testReadStringNaN () throws Exception {
109109 instantiate ("1c3:Testing" );
110110
111- assertThrows (InvalidObjectException .class , new Runnable () {
112- public void run () throws Exception {
113- instance .readString ();
114- }
115- });
116-
111+ assertThrows (InvalidObjectException .class , instance ::readString );
117112 assertEquals (10 , instance .available ());
118113 }
119114
120115 @ Test
121116 public void testReadStringEOF () throws Exception {
122117 instantiate ("123456" );
123118
124- assertThrows (EOFException .class , new Runnable () {
125- public void run () throws Exception {
126- instance .readString ();
127- }
128- });
129-
119+ assertThrows (EOFException .class , instance ::readString );
130120 assertEquals (0 , instance .available ());
131121 }
132122
133123 @ Test
134124 public void testReadStringEmptyStream () throws Exception {
135125 instantiate ("" );
136126
137- assertThrows (EOFException .class , new Runnable () {
138- public void run () throws Exception {
139- instance .readString ();
140- }
141- });
142-
127+ assertThrows (EOFException .class , instance ::readString );
143128 assertEquals (0 , instance .available ());
144129 }
145130
@@ -163,38 +148,23 @@ public void testReadStringEmptyByteArray() throws Exception {
163148 public void testReadStringNaNByteArray () throws Exception {
164149 instantiate ("1c3:Testing" );
165150
166- assertThrows (InvalidObjectException .class , new Runnable () {
167- public void run () throws Exception {
168- instance .readStringBytes ();
169- }
170- });
171-
151+ assertThrows (InvalidObjectException .class , instance ::readStringBytes );
172152 assertEquals (10 , instance .available ());
173153 }
174154
175155 @ Test
176156 public void testReadStringEOFByteArray () throws Exception {
177157 instantiate ("123456" );
178158
179- assertThrows (EOFException .class , new Runnable () {
180- public void run () throws Exception {
181- instance .readStringBytes ();
182- }
183- });
184-
159+ assertThrows (EOFException .class , instance ::readStringBytes );
185160 assertEquals (0 , instance .available ());
186161 }
187162
188163 @ Test
189164 public void testReadStringEmptyStreamByteArray () throws Exception {
190165 instantiate ("" );
191166
192- assertThrows (EOFException .class , new Runnable () {
193- public void run () throws Exception {
194- instance .readStringBytes ();
195- }
196- });
197-
167+ assertThrows (EOFException .class , instance ::readStringBytes );
198168 assertEquals (0 , instance .available ());
199169 }
200170
@@ -210,38 +180,23 @@ public void testReadNumber() throws Exception {
210180 public void testReadNumberNaN () throws Exception {
211181 instantiate ("i123cbve1" );
212182
213- assertThrows (NumberFormatException .class , new Runnable () {
214- public void run () throws Exception {
215- instance .readNumber ();
216- }
217- });
218-
183+ assertThrows (NumberFormatException .class , instance ::readNumber );
219184 assertEquals (1 , instance .available ());
220185 }
221186
222187 @ Test
223188 public void testReadNumberEOF () throws Exception {
224189 instantiate ("i123" );
225190
226- assertThrows (EOFException .class , new Runnable () {
227- public void run () throws Exception {
228- instance .readNumber ();
229- }
230- });
231-
191+ assertThrows (EOFException .class , instance ::readNumber );
232192 assertEquals (0 , instance .available ());
233193 }
234194
235195 @ Test
236196 public void testReadNumberEmptyStream () throws Exception {
237197 instantiate ("" );
238198
239- assertThrows (EOFException .class , new Runnable () {
240- public void run () throws Exception {
241- instance .readNumber ();
242- }
243- });
244-
199+ assertThrows (EOFException .class , instance ::readNumber );
245200 assertEquals (0 , instance .available ());
246201 }
247202
@@ -304,25 +259,15 @@ public void testReadListEmpty() throws Exception {
304259 public void testReadListInvalidItem () throws Exception {
305260 instantiate ("l2:Worlde" );
306261
307- assertThrows (InvalidObjectException .class , new Runnable () {
308- public void run () throws Exception {
309- instance .readList ();
310- }
311- });
312-
262+ assertThrows (InvalidObjectException .class , instance ::readList );
313263 assertEquals (4 , instance .available ());
314264 }
315265
316266 @ Test
317267 public void testReadListEOF () throws Exception {
318268 instantiate ("l5:Hello" );
319269
320- assertThrows (EOFException .class , new Runnable () {
321- public void run () throws Exception {
322- instance .readList ();
323- }
324- });
325-
270+ assertThrows (EOFException .class , instance ::readList );
326271 assertEquals (0 , instance .available ());
327272 }
328273
@@ -393,25 +338,15 @@ public void testReadDictionaryEmpty() throws Exception {
393338 public void testReadDictionaryInvalidItem () throws Exception {
394339 instantiate ("d4:item5:value3:testing" );
395340
396- assertThrows (InvalidObjectException .class , new Runnable () {
397- public void run () throws Exception {
398- instance .readDictionary ();
399- }
400- });
401-
341+ assertThrows (InvalidObjectException .class , instance ::readDictionary );
402342 assertEquals (4 , instance .available ());
403343 }
404344
405345 @ Test
406346 public void testReadDictionaryEOF () throws Exception {
407347 instantiate ("d4:item5:test" );
408348
409- assertThrows (EOFException .class , new Runnable () {
410- public void run () throws Exception {
411- instance .readDictionary ();
412- }
413- });
414-
349+ assertThrows (EOFException .class , instance ::readDictionary );
415350 assertEquals (0 , instance .available ());
416351 }
417352}
0 commit comments