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}
@@ -728,19 +721,15 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() {
728721 Font font = control .getFont ();
729722 control .setFont (font );
730723 assertEquals (font , control .getFont ());
724+ font .dispose ();
731725
732- font = new Font (control .getDisplay (), SwtTestUtil .testFontName , 10 , SWT .NORMAL );
733- control .setFont (font );
734- assertEquals (font , control .getFont ());
726+ Font font1 = new Font (control .getDisplay (), SwtTestUtil .testFontName , 10 , SWT .NORMAL );
727+ control .setFont (font1 );
728+ assertEquals (font1 , control .getFont ());
735729
736730 control .setFont (null );
737- 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+ font1 .dispose ();
732+ assertThrows ("No exception thrown for disposed font" , IllegalArgumentException .class , () -> control .setFont (font1 ));
744733}
745734@ Test
746735public void test_setForegroundLorg_eclipse_swt_graphics_Color () {
@@ -775,12 +764,8 @@ public void test_setForegroundAlphaLorg_eclipse_swt_graphics_Color() {
775764public void test_setForegroundDisposedColorLorg_eclipse_swt_graphics_Color () {
776765 Color color = new Color (255 , 0 , 0 );
777766 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- }
767+ assertThrows ("setting a disposed color object with Control.setForeground(Color) should throw an exception" ,
768+ IllegalArgumentException .class , () -> control .setForeground (color ));
784769}
785770@ Test
786771public void test_setLayoutDataLjava_lang_Object () {
@@ -808,12 +793,8 @@ public void test_setLocationII() {
808793}
809794@ Test
810795public 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- }
796+ assertThrows ("No exception thrown for location == null" , IllegalArgumentException .class ,
797+ () -> control .setLocation (null ));
817798
818799 Point loc = new Point (30 , 40 );
819800 control .setLocation (loc );
@@ -881,12 +862,7 @@ public void test_setSizeLorg_eclipse_swt_graphics_Point() {
881862 control .setSize (new Point (30 , 40 ));
882863 assertEquals (new Point (30 , 40 ), control .getSize ());
883864
884- try {
885- control .setSize (null );
886- fail ("No exception thrown for size == null" );
887- }
888- catch (IllegalArgumentException e ) {
889- }
865+ assertThrows ("No exception thrown for size == null" , IllegalArgumentException .class , () -> control .setSize (null ));
890866
891867 control .setSize (new Point (0 , 0 ));
892868
@@ -921,12 +897,8 @@ public void test_toControlII() {
921897public void test_toControlLorg_eclipse_swt_graphics_Point () {
922898 Point controlCoords = control .toControl (new Point (0 , 0 ));
923899 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- }
900+ assertThrows ("No exception thrown for point == null" , IllegalArgumentException .class ,
901+ () -> control .toControl (null ));
930902}
931903@ Test
932904public void test_toDisplayII () {
@@ -937,12 +909,8 @@ public void test_toDisplayII() {
937909public void test_toDisplayLorg_eclipse_swt_graphics_Point () {
938910 Point displayCoords = control .toDisplay (new Point (0 , 0 ));
939911 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- }
912+ assertThrows ("No exception thrown for display == null" , IllegalArgumentException .class ,
913+ () -> control .toDisplay (null ));
946914}
947915@ Test
948916public void test_traverseI () {
0 commit comments