@@ -226,20 +226,10 @@ public static void testConstructorBytes() {
226226 assertEquals ("abcdef" , str );
227227 str = new String (bytes , 1 , 3 );
228228 assertEquals ("bcd" , str );
229- try {
230- new String (bytes , 1 , 6 );
231- assertTrue ("Should have thrown IOOB in JVM" , !isJvm ());
232- } catch (IndexOutOfBoundsException expected ) {
233- }
234- try {
235- new String (bytes , -1 , 2 );
236- assertTrue ("Should have thrown IOOB in JVM" , !isJvm ());
237- } catch (IndexOutOfBoundsException expected ) {
238- }
239- try {
240- new String (bytes , 6 , 2 );
241- assertTrue ("Should have thrown IOOB in JVM" , !isJvm ());
242- } catch (IndexOutOfBoundsException expected ) {
229+ if (isJvm ()) {
230+ assertThrows (IndexOutOfBoundsException .class , () -> new String (bytes , 1 , 6 ));
231+ assertThrows (IndexOutOfBoundsException .class , () -> new String (bytes , -1 , 2 ));
232+ assertThrows (IndexOutOfBoundsException .class , () -> new String (bytes , 6 , 2 ));
243233 }
244234 }
245235
@@ -261,35 +251,19 @@ private static void internalTestConstructorLatin1(String encoding)
261251 assertEquals ("àßçÐéf" , str );
262252 str = new String (bytes , 1 , 3 , encoding );
263253 assertEquals ("ßçÐ" , str );
264- try {
265- new String (bytes , 1 , 6 , encoding );
266- assertTrue ("Should have thrown IOOB in JVM" , !isJvm ());
267- } catch (IndexOutOfBoundsException expected ) {
268- }
269- try {
270- new String (bytes , -1 , 2 , encoding );
271- assertTrue ("Should have thrown IOOB in JVM" , !isJvm ());
272- } catch (IndexOutOfBoundsException expected ) {
273- }
274- try {
275- new String (bytes , 6 , 2 , encoding );
276- assertTrue ("Should have thrown IOOB in JVM" , !isJvm ());
277- } catch (IndexOutOfBoundsException expected ) {
278- }
279- try {
280- new String (bytes , 1 , 6 , Charset .forName (encoding ));
281- assertTrue ("Should have thrown IOOB in JVM" , !isJvm ());
282- } catch (IndexOutOfBoundsException expected ) {
283- }
284- try {
285- new String (bytes , -1 , 2 , Charset .forName (encoding ));
286- assertTrue ("Should have thrown IOOB in JVM" , !isJvm ());
287- } catch (IndexOutOfBoundsException expected ) {
288- }
289- try {
290- new String (bytes , 6 , 2 , Charset .forName (encoding ));
291- assertTrue ("Should have thrown IOOB in JVM" , !isJvm ());
292- } catch (IndexOutOfBoundsException expected ) {
254+ if (isJvm ()) {
255+ assertThrows (IndexOutOfBoundsException .class , () -> new String (bytes , 1 , 6 , encoding ));
256+ assertThrows (IndexOutOfBoundsException .class , () -> new String (bytes , -1 , 2 , encoding ));
257+ assertThrows (IndexOutOfBoundsException .class , () -> new String (bytes , 6 , 2 , encoding ));
258+ assertThrows (
259+ IndexOutOfBoundsException .class ,
260+ () -> new String (bytes , 1 , 6 , Charset .forName (encoding )));
261+ assertThrows (
262+ IndexOutOfBoundsException .class ,
263+ () -> new String (bytes , -1 , 2 , Charset .forName (encoding )));
264+ assertThrows (
265+ IndexOutOfBoundsException .class ,
266+ () -> new String (bytes , 6 , 2 , Charset .forName (encoding )));
293267 }
294268 }
295269
0 commit comments