1919import static org .junit .Assert .assertNotEquals ;
2020import static org .junit .Assert .assertNotNull ;
2121import static org .junit .Assert .assertNull ;
22+ import static org .junit .Assert .assertThrows ;
2223import static org .junit .Assert .assertTrue ;
2324import static org .junit .Assert .fail ;
2425import static org .junit .Assume .assumeTrue ;
@@ -640,12 +641,8 @@ public void test_setBackgroundAlphaLorg_eclipse_swt_graphics_Color() {
640641public void test_setBackgroundDisposedColorLorg_eclipse_swt_graphics_Color () {
641642 Color color = new Color (255 , 0 , 0 );
642643 color .dispose ();
643- try {
644- control .setBackground (color );
645- fail ("setting a disposed color object with Control.setBackground(Color) should throw an exception" );
646- } catch (IllegalArgumentException e ) {
647- // expected, since the color is disposed
648- }
644+ assertThrows ("setting a disposed color object with Control.setBackground(Color) should throw an exception" ,
645+ IllegalArgumentException .class , () -> control .setBackground (color ));
649646}
650647@ Test
651648public void test_setBoundsIIII () {
@@ -665,12 +662,8 @@ public void test_setBoundsLorg_eclipse_swt_graphics_Rectangle() {
665662 control .setBounds (new Rectangle (20 , 30 , 40 , 50 ));
666663 assertNotEquals (new Rectangle (10 , 20 , 30 , 40 ), control .getBounds ());
667664
668- try {
669- control .setBounds (null );
670- fail ("No exception thrown for rectangle == null" );
671- }
672- catch (IllegalArgumentException e ) {
673- }
665+ assertThrows ("No exception thrown for rectangle == null" , IllegalArgumentException .class ,
666+ () -> control .setBounds (null ));
674667
675668 control .setBounds (new Rectangle (10 , 20 , 30 , 40 ));
676669}
@@ -735,12 +728,9 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() {
735728
736729 control .setFont (null );
737730 font .dispose ();
738- try {
739- control .setFont (font );
740- control .setFont (null );
741- fail ("No exception thrown for disposed font" );
742- } catch (IllegalArgumentException e ) {
743- }
731+ Font f = font ;
732+ assertThrows ("No exception thrown for disposed font" , IllegalArgumentException .class , () -> control .setFont (f ));
733+ control .setFont (null );
744734}
745735@ Test
746736public void test_setForegroundLorg_eclipse_swt_graphics_Color () {
@@ -775,12 +765,8 @@ public void test_setForegroundAlphaLorg_eclipse_swt_graphics_Color() {
775765public void test_setForegroundDisposedColorLorg_eclipse_swt_graphics_Color () {
776766 Color color = new Color (255 , 0 , 0 );
777767 color .dispose ();
778- try {
779- control .setForeground (color );
780- fail ("setting a disposed color object with Control.setForeground(Color) should throw an exception" );
781- } catch (IllegalArgumentException e ) {
782- // expected, since the color is disposed
783- }
768+ assertThrows ("setting a disposed color object with Control.setForeground(Color) should throw an exception" ,
769+ IllegalArgumentException .class , () -> control .setForeground (color ));
784770}
785771@ Test
786772public void test_setLayoutDataLjava_lang_Object () {
@@ -808,12 +794,8 @@ public void test_setLocationII() {
808794}
809795@ Test
810796public void test_setLocationLorg_eclipse_swt_graphics_Point () {
811- try {
812- control .setLocation (null );
813- fail ("No exception thrown for location == null" );
814- }
815- catch (IllegalArgumentException e ) {
816- }
797+ assertThrows ("No exception thrown for location == null" , IllegalArgumentException .class ,
798+ () -> control .setLocation (null ));
817799
818800 Point loc = new Point (30 , 40 );
819801 control .setLocation (loc );
@@ -881,12 +863,7 @@ public void test_setSizeLorg_eclipse_swt_graphics_Point() {
881863 control .setSize (new Point (30 , 40 ));
882864 assertEquals (new Point (30 , 40 ), control .getSize ());
883865
884- try {
885- control .setSize (null );
886- fail ("No exception thrown for size == null" );
887- }
888- catch (IllegalArgumentException e ) {
889- }
866+ assertThrows ("No exception thrown for size == null" , IllegalArgumentException .class , () -> control .setSize (null ));
890867
891868 control .setSize (new Point (0 , 0 ));
892869
@@ -921,12 +898,8 @@ public void test_toControlII() {
921898public void test_toControlLorg_eclipse_swt_graphics_Point () {
922899 Point controlCoords = control .toControl (new Point (0 , 0 ));
923900 assertEquals (new Point (0 , 0 ), control .toDisplay (controlCoords ));
924- try {
925- control .toControl (null );
926- fail ("No exception thrown for size == null" );
927- }
928- catch (IllegalArgumentException e ) {
929- }
901+ assertThrows ("No exception thrown for point == null" , IllegalArgumentException .class ,
902+ () -> control .toControl (null ));
930903}
931904@ Test
932905public void test_toDisplayII () {
@@ -937,12 +910,8 @@ public void test_toDisplayII() {
937910public void test_toDisplayLorg_eclipse_swt_graphics_Point () {
938911 Point displayCoords = control .toDisplay (new Point (0 , 0 ));
939912 assertEquals (new Point (0 , 0 ), control .toControl (displayCoords ));
940- try {
941- control .toDisplay (null );
942- fail ("No exception thrown for size == null" );
943- }
944- catch (IllegalArgumentException e ) {
945- }
913+ assertThrows ("No exception thrown for display == null" , IllegalArgumentException .class ,
914+ () -> control .toDisplay (null ));
946915}
947916@ Test
948917public void test_traverseI () {
0 commit comments