|
14 | 14 | import static org.junit.jupiter.api.Assertions.assertEquals; |
15 | 15 | import static org.junit.jupiter.api.Assertions.assertFalse; |
16 | 16 | import static org.junit.jupiter.api.Assertions.assertSame; |
| 17 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
17 | 18 | import static org.junit.jupiter.api.Assertions.assertTrue; |
18 | | -import static org.junit.jupiter.api.Assertions.fail; |
19 | 19 |
|
20 | 20 | import org.eclipse.terminal.model.ITerminalTextData; |
21 | 21 | import org.eclipse.terminal.model.ITerminalTextDataReadOnly; |
@@ -188,12 +188,7 @@ public void testResizeFailure() { |
188 | 188 | String s = "12345\n" + "abcde\n" + "ABCDE"; |
189 | 189 | fill(term, 0, 0, s); |
190 | 190 | assertEqualsTerm(s, toMultiLineText(term)); |
191 | | - try { |
192 | | - term.setDimensions(-3, 4); |
193 | | - fail(); |
194 | | - } catch (RuntimeException e) { |
195 | | - // OK |
196 | | - } |
| 191 | + assertThrows(IllegalArgumentException.class, () -> term.setDimensions(-3, 4)); |
197 | 192 | // assertEquals(5, term.getWidth()); |
198 | 193 | // assertEquals(3, term.getHeight()); |
199 | 194 | // assertEquals(s, toSimpleText(term)); |
@@ -303,36 +298,12 @@ public void testGetChar() { |
303 | 298 | assertEquals('C', term.getChar(2, 2)); |
304 | 299 | assertEquals('D', term.getChar(2, 3)); |
305 | 300 | assertEquals('E', term.getChar(2, 4)); |
306 | | - try { |
307 | | - term.getChar(0, -1); |
308 | | - fail(); |
309 | | - } catch (RuntimeException e) { |
310 | | - } |
311 | | - try { |
312 | | - term.getChar(-1, -1); |
313 | | - fail(); |
314 | | - } catch (RuntimeException e) { |
315 | | - } |
316 | | - try { |
317 | | - term.getChar(-1, 0); |
318 | | - fail(); |
319 | | - } catch (RuntimeException e) { |
320 | | - } |
321 | | - try { |
322 | | - term.getChar(0, 5); |
323 | | - fail(); |
324 | | - } catch (RuntimeException e) { |
325 | | - } |
326 | | - try { |
327 | | - term.getChar(3, 5); |
328 | | - fail(); |
329 | | - } catch (RuntimeException e) { |
330 | | - } |
331 | | - try { |
332 | | - term.getChar(3, 0); |
333 | | - fail(); |
334 | | - } catch (RuntimeException e) { |
335 | | - } |
| 301 | + assertThrows(IllegalArgumentException.class, () -> term.getChar(0, -1)); |
| 302 | + assertThrows(IllegalArgumentException.class, () -> term.getChar(-1, -1)); |
| 303 | + assertThrows(IllegalArgumentException.class, () -> term.getChar(-1, 0)); |
| 304 | + assertThrows(IllegalArgumentException.class, () -> term.getChar(0, 5)); |
| 305 | + assertThrows(IllegalArgumentException.class, () -> term.getChar(3, 5)); |
| 306 | + assertThrows(IllegalArgumentException.class, () -> term.getChar(3, 0)); |
336 | 307 | } |
337 | 308 |
|
338 | 309 | @Test |
@@ -398,12 +369,9 @@ public void testSetChars() { |
398 | 369 |
|
399 | 370 | term.setChars(3, 1, new char[] { '1', '2' }, null); |
400 | 371 | assertEqualsTerm("abc\n" + "bcd\n" + "cde\n" + "d12\n" + "efg\n" + "fgh", toMultiLineText(term)); |
401 | | - try { |
402 | | - // check if we cannot exceed the range |
403 | | - term.setChars(4, 1, new char[] { '1', '2', '3', '4', '5' }, null); |
404 | | - fail(); |
405 | | - } catch (RuntimeException e) { |
406 | | - } |
| 372 | + // check if we cannot exceed the range |
| 373 | + assertThrows(IllegalArgumentException.class, |
| 374 | + () -> term.setChars(4, 1, new char[] { '1', '2', '3', '4', '5' }, null)); |
407 | 375 |
|
408 | 376 | } |
409 | 377 |
|
@@ -433,33 +401,12 @@ public void testSetCharsLen() { |
433 | 401 | assertEqualsTerm("ZYXWVU\n" + "ab4567\n" + "ABCDEF", toMultiLineText(term)); |
434 | 402 |
|
435 | 403 | fill(term, s); |
436 | | - try { |
437 | | - term.setChars(1, 0, chars, 7, 10, null); |
438 | | - fail(); |
439 | | - } catch (RuntimeException e) { |
440 | | - } |
| 404 | + assertThrows(IllegalArgumentException.class, () -> term.setChars(1, 0, chars, 7, 10, null)); |
441 | 405 | fill(term, s); |
442 | | - try { |
443 | | - term.setChars(1, -1, chars, 0, 2, null); |
444 | | - fail(); |
445 | | - } catch (RuntimeException e) { |
446 | | - } |
447 | | - try { |
448 | | - term.setChars(-1, 1, chars, 0, 2, null); |
449 | | - fail(); |
450 | | - } catch (RuntimeException e) { |
451 | | - } |
452 | | - try { |
453 | | - term.setChars(1, 10, chars, 0, 2, null); |
454 | | - fail(); |
455 | | - } catch (RuntimeException e) { |
456 | | - } |
457 | | - try { |
458 | | - term.setChars(10, 1, chars, 0, 2, null); |
459 | | - fail(); |
460 | | - } catch (RuntimeException e) { |
461 | | - } |
462 | | - // assertEquals(s, toSimpleText(term)); |
| 406 | + assertThrows(IllegalArgumentException.class, () -> term.setChars(1, -1, chars, 0, 2, null)); |
| 407 | + assertThrows(IllegalArgumentException.class, () -> term.setChars(-1, 1, chars, 0, 2, null)); |
| 408 | + assertThrows(IllegalArgumentException.class, () -> term.setChars(1, 10, chars, 0, 2, null)); |
| 409 | + assertThrows(IllegalArgumentException.class, () -> term.setChars(10, 1, chars, 0, 2, null)); |
463 | 410 | } |
464 | 411 |
|
465 | 412 | @Test |
@@ -527,30 +474,14 @@ public void testSetCopyLines() { |
527 | 474 | assertEqualsSimple(s, toSimple(term)); |
528 | 475 | assertEqualsSimple("a2345", toSimple(termCopy)); |
529 | 476 |
|
530 | | - try { |
531 | | - fillSimple(termCopy, sCopy); |
532 | | - termCopy.copyRange(term, 1, 1, 5); |
533 | | - fail(); |
534 | | - } catch (RuntimeException e) { |
535 | | - } |
536 | | - try { |
537 | | - fillSimple(termCopy, sCopy); |
538 | | - termCopy.copyRange(term, 0, 0, 6); |
539 | | - fail(); |
540 | | - } catch (RuntimeException e) { |
541 | | - } |
542 | | - try { |
543 | | - fillSimple(termCopy, sCopy); |
544 | | - termCopy.copyRange(term, 7, 0, 1); |
545 | | - fail(); |
546 | | - } catch (RuntimeException e) { |
547 | | - } |
548 | | - try { |
549 | | - fillSimple(termCopy, sCopy); |
550 | | - termCopy.copyRange(term, 0, 7, 1); |
551 | | - fail(); |
552 | | - } catch (RuntimeException e) { |
553 | | - } |
| 477 | + fillSimple(termCopy, sCopy); |
| 478 | + assertThrows(IllegalArgumentException.class, () -> termCopy.copyRange(term, 1, 1, 5)); |
| 479 | + fillSimple(termCopy, sCopy); |
| 480 | + assertThrows(IllegalArgumentException.class, () -> termCopy.copyRange(term, 0, 0, 6)); |
| 481 | + fillSimple(termCopy, sCopy); |
| 482 | + assertThrows(IllegalArgumentException.class, () -> termCopy.copyRange(term, 7, 0, 1)); |
| 483 | + fillSimple(termCopy, sCopy); |
| 484 | + assertThrows(IllegalArgumentException.class, () -> termCopy.copyRange(term, 0, 7, 1)); |
554 | 485 | } |
555 | 486 |
|
556 | 487 | @Test |
@@ -690,16 +621,8 @@ public void testScrollPositive() { |
690 | 621 |
|
691 | 622 | @Test |
692 | 623 | public void testScrollFail() { |
693 | | - try { |
694 | | - scrollTest(5, 2, -1, "012345", "012345"); |
695 | | - fail(); |
696 | | - } catch (RuntimeException e) { |
697 | | - } |
698 | | - try { |
699 | | - scrollTest(0, 7, 1, "012345", " "); |
700 | | - fail(); |
701 | | - } catch (RuntimeException e) { |
702 | | - } |
| 624 | + assertThrows(IllegalArgumentException.class, () -> scrollTest(5, 2, -1, "012345", "012345")); |
| 625 | + assertThrows(IllegalArgumentException.class, () -> scrollTest(0, 7, 1, "012345", " ")); |
703 | 626 | } |
704 | 627 |
|
705 | 628 | /** |
|
0 commit comments