19
19
import static org .junit .Assert .assertNotEquals ;
20
20
import static org .junit .Assert .assertNotNull ;
21
21
import static org .junit .Assert .assertNull ;
22
+ import static org .junit .Assert .assertThrows ;
22
23
import static org .junit .Assert .assertTrue ;
23
24
import static org .junit .Assert .fail ;
24
25
import static org .junit .Assume .assumeTrue ;
@@ -640,12 +641,8 @@ public void test_setBackgroundAlphaLorg_eclipse_swt_graphics_Color() {
640
641
public void test_setBackgroundDisposedColorLorg_eclipse_swt_graphics_Color () {
641
642
Color color = new Color (255 , 0 , 0 );
642
643
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 ));
649
646
}
650
647
@ Test
651
648
public void test_setBoundsIIII () {
@@ -665,12 +662,8 @@ public void test_setBoundsLorg_eclipse_swt_graphics_Rectangle() {
665
662
control .setBounds (new Rectangle (20 , 30 , 40 , 50 ));
666
663
assertNotEquals (new Rectangle (10 , 20 , 30 , 40 ), control .getBounds ());
667
664
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 ));
674
667
675
668
control .setBounds (new Rectangle (10 , 20 , 30 , 40 ));
676
669
}
@@ -735,12 +728,9 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() {
735
728
736
729
control .setFont (null );
737
730
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 );
744
734
}
745
735
@ Test
746
736
public void test_setForegroundLorg_eclipse_swt_graphics_Color () {
@@ -775,12 +765,8 @@ public void test_setForegroundAlphaLorg_eclipse_swt_graphics_Color() {
775
765
public void test_setForegroundDisposedColorLorg_eclipse_swt_graphics_Color () {
776
766
Color color = new Color (255 , 0 , 0 );
777
767
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 ));
784
770
}
785
771
@ Test
786
772
public void test_setLayoutDataLjava_lang_Object () {
@@ -808,12 +794,8 @@ public void test_setLocationII() {
808
794
}
809
795
@ Test
810
796
public 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 ));
817
799
818
800
Point loc = new Point (30 , 40 );
819
801
control .setLocation (loc );
@@ -881,12 +863,7 @@ public void test_setSizeLorg_eclipse_swt_graphics_Point() {
881
863
control .setSize (new Point (30 , 40 ));
882
864
assertEquals (new Point (30 , 40 ), control .getSize ());
883
865
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 ));
890
867
891
868
control .setSize (new Point (0 , 0 ));
892
869
@@ -921,12 +898,8 @@ public void test_toControlII() {
921
898
public void test_toControlLorg_eclipse_swt_graphics_Point () {
922
899
Point controlCoords = control .toControl (new Point (0 , 0 ));
923
900
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 ));
930
903
}
931
904
@ Test
932
905
public void test_toDisplayII () {
@@ -937,12 +910,8 @@ public void test_toDisplayII() {
937
910
public void test_toDisplayLorg_eclipse_swt_graphics_Point () {
938
911
Point displayCoords = control .toDisplay (new Point (0 , 0 ));
939
912
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 ));
946
915
}
947
916
@ Test
948
917
public void test_traverseI () {
0 commit comments