11/*******************************************************************************
2- * Copyright (c) 2000, 2017 IBM Corporation and others.
2+ * Copyright (c) 2000, 2025 IBM Corporation and others.
33 *
44 * This program and the accompanying materials
55 * are made available under the terms of the Eclipse Public License 2.0
1818import static org .junit .Assert .assertFalse ;
1919import static org .junit .Assert .assertNotEquals ;
2020import static org .junit .Assert .assertNull ;
21+ import static org .junit .Assert .assertSame ;
22+ import static org .junit .Assert .assertThrows ;
2123import static org .junit .Assert .assertTrue ;
22- import static org .junit .Assert .fail ;
2324
2425import org .eclipse .swt .SWT ;
2526import org .eclipse .swt .graphics .Font ;
@@ -52,12 +53,7 @@ public void setUp() {
5253
5354@ Test
5455public void test_ConstructorLorg_eclipse_swt_widgets_CanvasI () {
55- try {
56- new Caret (null , 0 );
57- fail ("No exception thrown for parent == null" );
58- }
59- catch (IllegalArgumentException e ) {
60- }
56+ assertThrows ("No exception thrown for null parent" , IllegalArgumentException .class , () -> new Caret (null , 0 ));
6157}
6258
6359@ Test
@@ -75,7 +71,7 @@ public void test_getBounds() {
7571public void test_getParent () {
7672 assertEquals (canvas , caret .getParent ());
7773
78- assertTrue (caret .getDisplay ()== shell .getDisplay ());
74+ assertSame (caret .getDisplay (), shell .getDisplay ());
7975}
8076
8177@ Test
@@ -108,59 +104,46 @@ public void test_setBoundsIIII() {
108104
109105@ Test
110106public void test_setBoundsLorg_eclipse_swt_graphics_Rectangle () {
111- caret .setBounds (new Rectangle (0 ,0 , 30 ,30 ));
107+ caret .setBounds (new Rectangle (0 , 0 , 30 , 30 ));
112108
113- try {
114- caret .setBounds (null );
115- fail ("No exception thrown for bounds == null" );
116- }
117- catch (IllegalArgumentException e ) {
118- }
109+ assertThrows ("No exception thrown for bounds == null" , IllegalArgumentException .class , () -> caret .setBounds (null ));
119110}
120111
121112@ Test
122113public void test_setFontLorg_eclipse_swt_graphics_Font () {
123- Font font = caret .getFont ();
124- caret .setFont (font );
125- assertEquals (font , caret .getFont ());
114+ Font font1 = caret .getFont ();
115+ caret .setFont (font1 );
116+ assertEquals (font1 , caret .getFont ());
126117 caret .setFont (null );
127118
128- font = new Font (caret .getDisplay (), SwtTestUtil .testFontName , 10 , SWT .NORMAL );
119+ Font font = new Font (caret .getDisplay (), SwtTestUtil .testFontName , 10 , SWT .NORMAL );
129120 caret .setFont (font );
130121 assertEquals (font , caret .getFont ());
131122
132123 caret .setFont (null );
133124 font .dispose ();
134- try {
135- caret .setFont (font );
136- caret .setFont (null );
137- fail ("No exception thrown for disposed font" );
138- } catch (IllegalArgumentException e ) {
139- }
125+ assertThrows ("No exception thrown for disposed font" , IllegalArgumentException .class , () -> caret .setFont (font ));
126+ caret .setFont (null );
140127}
141128
142129@ Test
143130public void test_setImageLorg_eclipse_swt_graphics_Image () {
144- Image image = caret .getImage ();
145- caret .setImage (image );
146- assertEquals (image , caret .getImage ());
131+ Image image1 = caret .getImage ();
132+ caret .setImage (image1 );
133+ assertEquals (image1 , caret .getImage ());
147134
148135 caret .setImage (null );
149136 assertNull (caret .getImage ());
150137
151138 ImageGcDrawer noOpGcDrawer = (gc , width , height ) -> {};
152- image = new Image (shell .getDisplay (), noOpGcDrawer , 10 , 10 );
139+ Image image = new Image (shell .getDisplay (), noOpGcDrawer , 10 , 10 );
153140 caret .setImage (image );
154141 assertEquals (image , caret .getImage ());
155142
156143 caret .setImage (null );
157144 image .dispose ();
158- try {
159- caret .setImage (image );
160- caret .setImage (null );
161- fail ("No exception thrown for disposed image" );
162- } catch (IllegalArgumentException e ) {
163- }
145+ assertThrows ("No exception thrown for disposed image" , IllegalArgumentException .class , () -> caret .setImage (image ));
146+ caret .setImage (null );
164147}
165148
166149@ Test
0 commit comments