diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java index 5a52c53a757..4d225025354 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java @@ -137,10 +137,8 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceI() { @Test public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_ImageDataLorg_eclipse_swt_graphics_ImageDataII() { // Test new Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) - int numFormats = SwtTestUtil.imageFormats.length; String fileName = SwtTestUtil.imageFilenames[0]; - for (int i=0; i new Image(display, stream)); @@ -316,8 +316,7 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_String() // create valid images for (Display display : displays) { for (String fileName : SwtTestUtil.imageFilenames) { - for (int i = 0; i < SwtTestUtil.imageFormats.length; i++) { - String format = SwtTestUtil.imageFormats[i]; + for (String format : SwtTestUtil.imageFormats) { String pathName = getPath(fileName + "." + format).toString(); Image image = new Image(display, pathName); image.dispose(); @@ -868,10 +867,8 @@ public void test_toString() { /** Test implementation **/ void getImageData1() { - int numFormats = SwtTestUtil.imageFormats.length; String fileName = SwtTestUtil.imageFilenames[0]; - for (int i=0; i tests = new ArrayList<>(); // Compose a list of all supported formats @@ -117,9 +117,10 @@ public void test_blit() throws NoSuchMethodException, SecurityException, Illegal /** * Tests {@link ImageData#blit}: * Ensures that (MSB_FIRST, LSB_FIRST) round trip produces original. + * @throws Exception */ @Test -public void test_blit_MsbLsb() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { +public void test_blit_MsbLsb() throws Exception { List tests = new ArrayList<>(); { for (int depth : indexedDepths) { @@ -218,10 +219,8 @@ public void test_ConstructorLjava_io_InputStream() throws IOException { assertThrows("No exception thrown for invalid InputStream", SWTException.class, () ->new ImageData(stream1)); } - int numFormats = SwtTestUtil.imageFormats.length; String fileName = SwtTestUtil.imageFilenames[0]; - for (int i=0; i loaderListenerCalled = true; - try { - loader.addImageLoaderListener(null); - fail("No exception thrown for addImageLoaderListener with null argument"); - } catch (IllegalArgumentException e) { - } - + assertThrows(IllegalArgumentException.class, () -> loader.addImageLoaderListener(null), + "No exception thrown for addImageLoaderListener with null argument"); assertFalse(":a:", loader.hasListeners()); loader.addImageLoaderListener(loaderListener); assertTrue(":b:", loader.hasListeners()); @@ -66,13 +64,13 @@ public void test_addImageLoaderListenerLorg_eclipse_swt_graphics_ImageLoaderList loaderListenerCalled = false; try (InputStream stream = SwtTestUtil.class.getResourceAsStream("interlaced_target.png")) { loader.load(stream); - } catch (IOException e) {} + } assertTrue(":c:", loaderListenerCalled); loaderListenerCalled = false; try (InputStream stream = SwtTestUtil.class.getResourceAsStream("target.png")) { loader.load(stream); - } catch (IOException e) {} + } assertFalse(":d:", loaderListenerCalled); loaderListenerCalled = false; @@ -84,86 +82,61 @@ public void test_addImageLoaderListenerLorg_eclipse_swt_graphics_ImageLoaderList } @Test -public void test_loadLjava_io_InputStream() { - ImageLoader loader = new ImageLoader(); - try (InputStream stream = null) { - loader.load(stream); - fail("No exception thrown for load inputStream == null"); - } catch (IllegalArgumentException | IOException e) { - } +public void test_loadLjava_io_InputStream() throws IOException { + ImageLoader loader = new ImageLoader(); + assertThrows(IllegalArgumentException.class, () -> loader.load((InputStream) null), + "No exception thrown for load inputStream == null"); - try (InputStream stream = SwtTestUtil.class.getResourceAsStream("empty.txt")) { - loader.load(stream); - fail("No exception thrown for load from invalid inputStream"); - } catch (IOException|SWTException e) { - } + try (InputStream stream = SwtTestUtil.class.getResourceAsStream("empty.txt")) { + assertThrows(SWTException.class, () -> loader.load(stream), + "No exception thrown for load from invalid inputStream"); + } - int numFormats = SwtTestUtil.imageFormats.length; - String fileName = SwtTestUtil.imageFilenames[0]; - for (int i = 0; i < numFormats; i++) { - String format = SwtTestUtil.imageFormats[i]; - try (InputStream stream = SwtTestUtil.class.getResourceAsStream(fileName + "." + format)) { - loader.load(stream); - } catch (IOException e) { - } + String fileName = SwtTestUtil.imageFilenames[0]; + for (String format : SwtTestUtil.imageFormats) { + try (InputStream stream = SwtTestUtil.class.getResourceAsStream(fileName + "." + format)) { + loader.load(stream); } + } } @Test public void test_loadLjava_lang_String() { ImageLoader loader = new ImageLoader(); String filename = null; - try { - loader.load(filename); - fail("No exception thrown for load filename == null"); - } catch (IllegalArgumentException e) { - } + assertThrows(IllegalArgumentException.class, () -> loader.load(filename), + "No exception thrown for load filename == null"); } @Test -public void test_saveLjava_io_OutputStreamI() { +public void test_saveLjava_io_OutputStreamI() throws IOException { ImageLoader loader = new ImageLoader(); - ByteArrayOutputStream outStream = null; - try { - try { - loader.save(outStream, 0); - fail("No exception thrown for save outputStream == null"); - } catch (IllegalArgumentException e) { - } - outStream = new ByteArrayOutputStream(); - try { - loader.save(outStream, -1); - fail("No exception thrown for save to invalid outputStream format"); - } catch (SWTException e) { + OutputStream outStream1 = null; + assertThrows(IllegalArgumentException.class, () -> loader.save(outStream1, 0), + "No exception thrown for save outputStream == null"); + + OutputStream outStream2 = new ByteArrayOutputStream(); + assertThrows(SWTException.class, () -> loader.save(outStream2, -1), + "No exception thrown for save to invalid outputStream format"); + + boolean jpgSupported = Arrays.asList(SwtTestUtil.imageFormats).contains("jpg"); + if (jpgSupported) { + String filename = SwtTestUtil.imageFilenames[0]; + // must use jpg since save is not implemented yet in png format + String filetype = "jpg"; + try (InputStream inStream = SwtTestUtil.class.getResourceAsStream(filename + "." + filetype)) { + loader.load(inStream); } - boolean jpgSupported = false; - for (String imageFormat : SwtTestUtil.imageFormats) { - if (imageFormat.equals("jpg")) { - jpgSupported = true; + OutputStream outStream = new ByteArrayOutputStream(); + int i = 0; + for (String format : SwtTestUtil.imageFormats) { + if (format.equals(filetype)) { + // save using the appropriate format + loader.save(outStream, i++); break; } } - if (jpgSupported) { - String filename = SwtTestUtil.imageFilenames[0]; - // must use jpg since save is not implemented yet in png format - String filetype = "jpg"; - try (InputStream inStream = SwtTestUtil.class.getResourceAsStream(filename + "." + filetype)) { - loader.load(inStream); - } catch (IOException e) {} - for (int i = 0; i < SwtTestUtil.imageFormats.length; i++) { - if (SwtTestUtil.imageFormats[i].equals(filetype)) { - // save using the appropriate format - loader.save(outStream, i); - break; - } - } - } - } finally { - try { - outStream.close(); - } catch (Exception e) { - } } } @@ -171,11 +144,8 @@ public void test_saveLjava_io_OutputStreamI() { public void test_saveLjava_lang_StringI() { ImageLoader loader = new ImageLoader(); String filename = null; - try { - loader.save(filename, 0); - fail("No exception thrown for save filename == null"); - } catch (IllegalArgumentException e) { - } + assertThrows(IllegalArgumentException.class, () -> loader.save(filename, 0), + "No exception thrown for save filename == null"); } /** diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Decorations.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Decorations.java index 1d51966aae9..556fe2f1873 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Decorations.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Decorations.java @@ -21,6 +21,8 @@ import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; @@ -123,9 +125,9 @@ public void test_setDefaultButtonLorg_eclipse_swt_widgets_Button() { public void test_setImageLorg_eclipse_swt_graphics_Image() { assertNull(":a:", decorations.getImage()); loadImages(); - decorations.setImage(images[0]); - assertTrue(":b:", images[0] == decorations.getImage()); - assertTrue(":c:", images[1] != decorations.getImage()); + decorations.setImage(images.get(0)); + assertTrue(":b:", images.get(0) == decorations.getImage()); + assertTrue(":c:", images.get(1) != decorations.getImage()); decorations.setImage(null); assertNull(":d:", decorations.getImage()); freeImages(); @@ -189,7 +191,7 @@ public void test_setVisibleZ() { /* custom */ Decorations decorations; -Image[] images = new Image [SwtTestUtil.imageFormats.length*SwtTestUtil.imageFilenames.length]; +private List images = new ArrayList<>(); @Override protected void setWidget(Widget w) { @@ -201,15 +203,10 @@ protected void setWidget(Widget w) { // this method must be private or protected so the auto-gen tool keeps it private void loadImages() { - int numFormats = SwtTestUtil.imageFormats.length; - int numFiles = SwtTestUtil.imageFilenames.length; - for (int i=0; i