diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_SWT.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_SWT.java index 4334095ed0a..d6193dcd0a8 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_SWT.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_SWT.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,10 +14,11 @@ *******************************************************************************/ package org.eclipse.swt.tests.junit; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.nio.file.Paths; import java.security.CodeSigner; @@ -29,183 +30,130 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.SWTError; import org.eclipse.swt.SWTException; -import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; /** - * Automated Test Suite for class org.eclipse.swt.SWT - * - * @see org.eclipse.swt.SWT + * Automated Test Suite for class {@link org.eclipse.swt.SWT}. */ public class Test_org_eclipse_swt_SWT { -@Test -public void test_Constructor() { - // Do nothing. Class SWT is not intended to be subclassed. -} + @Test + public void test_errorI() { + // Test that we throw the expected kinds of errors for the given error types. + assertThrows(IllegalArgumentException.class, () -> SWT.error(SWT.ERROR_NULL_ARGUMENT), + "did not correctly throw exception for ERROR_NULL_ARGUMENT"); + assertThrows(SWTException.class, () -> SWT.error(SWT.ERROR_FAILED_EXEC), + "did not correctly throw exception for ERROR_FAILED_EXEC"); + assertThrows(SWTError.class, () -> SWT.error(SWT.ERROR_NO_HANDLES), + "did not correctly throw exception for ERROR_NO_HANDLES"); + assertThrows(SWTError.class, () -> SWT.error(-1), + "did not correctly throw exception for error(-1)"); + } -@Test -public void test_errorI() { - // Test that we throw the expected kinds of errors for the given error types. - boolean passed = false; - try { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } catch (IllegalArgumentException ex) { - passed = true; - } catch (Throwable t) { } - assertTrue ("did not correctly throw exception for ERROR_NULL_ARGUMENT", passed); - passed = false; - try { - SWT.error(SWT.ERROR_FAILED_EXEC); - } catch (SWTException ex) { - passed = true; - } catch (Throwable t) { } - assertTrue ("did not correctly throw exception for ERROR_FAILED_EXEC", passed); - passed = false; - try { - SWT.error(SWT.ERROR_NO_HANDLES); - } catch (SWTError ex) { - passed = true; - } catch (Throwable t) { } - assertTrue ("did not correctly throw exception for ERROR_NO_HANDLES", passed); - passed = false; - try { - SWT.error(-1); - } catch (SWTError ex) { - passed = true; - } catch (Throwable t) { } - assertTrue ("did not correctly throw exception for error(-1)", passed); -} + @Test + public void test_errorILjava_lang_Throwable() { + // Test that the causing throwable is filled in. + Throwable cause = new RuntimeException("Just for testing"); + SWTException e1 = assertThrows(SWTException.class, () -> SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT, cause)); + + assertTrue(e1.throwable == cause, "did not correctly throw exception for ERROR_UNSUPPORTED_FORMAT"); + SWTError e2 = assertThrows(SWTError.class, () -> SWT.error(SWT.ERROR_NOT_IMPLEMENTED, cause)); + assertTrue(e2.throwable == cause, "did not correctly throw exception for ERROR_NOT_IMPLEMENTED"); + SWTError e3 = assertThrows(SWTError.class, () -> SWT.error(-1, cause)); + assertTrue(e3.throwable == cause, "did not correctly throw exception for error(-1)"); + } -@Test -public void test_errorILjava_lang_Throwable() { - // Test that the causing throwable is filled in. - Throwable cause = new RuntimeException("Just for testing"); - boolean passed = false; - try { - SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT, cause); - } catch (SWTException ex) { - passed = ex.throwable == cause; - } catch (Throwable t) { } - assertTrue ("did not correctly throw exception for ERROR_UNSUPPORTED_FORMAT", passed); - passed = false; - try { - SWT.error(SWT.ERROR_NOT_IMPLEMENTED, cause); - } catch (SWTError ex) { - passed = ex.throwable == cause; - } catch (Throwable t) { } - assertTrue ("did not correctly throw exception for ERROR_NOT_IMPLEMENTED", passed); - passed = false; - try { - SWT.error(-1, cause); - } catch (SWTError ex) { - passed = ex.throwable == cause; - } catch (Throwable t) { } - assertTrue ("did not correctly throw exception for error(-1)", passed); -} + @Test + public void test_getMessageLjava_lang_String() { + assertThrows(IllegalArgumentException.class, () -> SWT.getMessage(null), + "did not correctly throw exception with null argument"); + assertNotNull(SWT.getMessage("SWT_Yes")); + assertEquals( + "_NOT_FOUND_IN_PROPERTIES_", SWT.getMessage("_NOT_FOUND_IN_PROPERTIES_"), + "invalid key did not return as itself"); -@Test -public void test_getMessageLjava_lang_String() { - boolean passed = false; - try { - passed = false; - SWT.getMessage(null); - } catch (IllegalArgumentException ex) { - passed = true; } - assertTrue ("did not correctly throw exception with null argument", passed); - try { - SWT.getMessage("SWT_Yes"); - } catch (Throwable t) { - fail ("exception " + t + " generated for SWT_Yes"); - } - assertEquals ( - "invalid key did not return as itself", - "_NOT_FOUND_IN_PROPERTIES_", SWT.getMessage("_NOT_FOUND_IN_PROPERTIES_")); -} + private String pathFromClass(Class classValue) { + String filePrefix = SwtTestUtil.isWindows ? "file:/" : "file:"; -private String pathFromClass(Class classValue) { - String filePrefix = SwtTestUtil.isWindows ? "file:/" : "file:"; + String url = classValue.getProtectionDomain().getCodeSource().getLocation().toString(); + assertTrue(url.startsWith(filePrefix)); - String url = classValue.getProtectionDomain().getCodeSource().getLocation().toString(); - assertTrue(url.startsWith(filePrefix)); + String urlPath = url.substring(filePrefix.length()); + String path = Paths.get(urlPath).toAbsolutePath().toString(); - String urlPath = url.substring(filePrefix.length()); - String path = Paths.get(urlPath).toAbsolutePath().toString(); + // On Windows, use / for consistency + return path.replace('\\', '/'); + } - // On Windows, use / for consistency - return path.replace('\\', '/'); -} + private List signersFromClass(Class classValue) { + List result = new ArrayList<>(); -private List signersFromClass(Class classValue) { - List result = new ArrayList<>(); + CodeSigner[] signers = classValue.getProtectionDomain().getCodeSource().getCodeSigners(); + if (signers == null) { + return result; + } - CodeSigner[] signers = classValue.getProtectionDomain().getCodeSource().getCodeSigners(); - if (signers == null) { - return result; - } + for (CodeSigner signer : signers) { + Certificate cert = signer.getSignerCertPath().getCertificates().get(0); + if (!(cert instanceof X509Certificate x509cert)) { + continue; + } - for (CodeSigner signer : signers) { - Certificate cert = signer.getSignerCertPath().getCertificates().get(0); - if (!(cert instanceof X509Certificate)) { - continue; + result.add(x509cert.getSubjectX500Principal().getName()); } - X509Certificate x509cert = (X509Certificate)cert; - result.add(x509cert.getSubjectX500Principal().getName()); + return result; } - return result; -} + /** + * Ensure that SWT being tested was built together with the tests. This + * is a test designed for build scripts, such as the one that checks + * GitHub Pull Requests. + */ + @Test + @EnabledIfSystemProperty(named = "org.eclipse.swt.tests.junit.disable.test_isLocal", matches = "true") + public void test_isLocal() { + String swtPath = pathFromClass(SWT.class); + String tstPath = pathFromClass(Test_org_eclipse_swt_SWT.class); + List swtSigners = signersFromClass(SWT.class); + + // If SWT is signed by Eclipse, that's a good sign that it wasn't built locally + for (String signer : swtSigners) { + if (signer.toLowerCase().contains("cn=eclipse.org")) { + fail("Tested SWT is signed by Eclipse: (SWT='" + swtPath + "' signer='" + signer + "')"); + } + } -/** - * Ensure that SWT being tested was built together with the tests. This - * is a test designed for build scripts, such as the one that checks - * GitHub Pull Requests. - */ -@Test -public void test_isLocal() { - // If you change default to NO, make sure that this test runs on GitHub - Assume.assumeFalse(Boolean.getBoolean("org.eclipse.swt.tests.junit.disable.test_isLocal")); - - String swtPath = pathFromClass(SWT.class); - String tstPath = pathFromClass(Test_org_eclipse_swt_SWT.class); - List swtSigners = signersFromClass(SWT.class); - - // If SWT is signed by Eclipse, that's a good sign that it wasn't built locally - for (String signer : swtSigners) { - if (signer.toLowerCase().contains("cn=eclipse.org")) { - fail("Tested SWT is signed by Eclipse: (SWT='" + swtPath + "' signer='" + signer + "')"); + // It's hard to devise a condition that would hold for all possible + // locations of compiled classes. For example, my own project uses + // output directories different from what Eclipse does by default. + + // SWT shouldn't be published in maven. Note that SWT's local build + // may still be cached in maven. We observed the following paths: + // GitHub, bad: + // $HOME/.m2/repository/p2/osgi/bundle/org.eclipse.swt.gtk.linux.x86_64/3.121.0.v20220701-1002/org.eclipse.swt.gtk.linux.x86_64-3.121.0.v20220701-1002.jar + // Jenkins, good: + // $HOME/.m2/repository/org/eclipse/swt/org.eclipse.swt.gtk.linux.x86_64/3.121.0-SNAPSHOT/org.eclipse.swt.gtk.linux.x86_64-3.121.0-SNAPSHOT.jar + // The difference here is '/p2/osgi'. + if (swtPath.contains("/.m2/repository/p2/osgi/")) { + fail("Tested SWT path is on maven OSGI: (SWT='" + swtPath + "' Test='" + tstPath + "'"); } } - // It's hard to devise a condition that would hold for all possible - // locations of compiled classes. For example, my own project uses - // output directories different from what Eclipse does by default. - - // SWT shouldn't be published in maven. Note that SWT's local build - // may still be cached in maven. We observed the following paths: - // GitHub, bad: $HOME/.m2/repository/p2/osgi/bundle/org.eclipse.swt.gtk.linux.x86_64/3.121.0.v20220701-1002/org.eclipse.swt.gtk.linux.x86_64-3.121.0.v20220701-1002.jar - // Jenkins, good: $HOME/.m2/repository/org/eclipse/swt/org.eclipse.swt.gtk.linux.x86_64/3.121.0-SNAPSHOT/org.eclipse.swt.gtk.linux.x86_64-3.121.0-SNAPSHOT.jar - // The difference here is '/p2/osgi'. - if (swtPath.contains("/.m2/repository/p2/osgi/")) { - fail("Tested SWT path is on maven OSGI: (SWT='" + swtPath + "' Test='" + tstPath + "'"); + @Test + public void test_getPlatform() { + // Can't test the list of platforms, since this may change, + // so just test to see it returns something. + assertNotNull(SWT.getPlatform(), "returned null platform name"); } -} - -@Test -public void test_getPlatform() { - // Can't test the list of platforms, since this may change, - // so just test to see it returns something. - assertNotNull ("returned null platform name", SWT.getPlatform()); -} -@Test -public void test_getVersion() { - // Test that the version number which is returned is reasonable. - int ver = SWT.getVersion(); - assertTrue ("unreasonable value returned", ver > 0 && ver < 1000000); - System.out.println("SWT.getVersion(): " + ver); -} + @Test + public void test_getVersion() { + // Test that the version number which is returned is reasonable. + int ver = SWT.getVersion(); + assertTrue(ver > 0 && ver < 1000000, "unreasonable value returned:" + ver); + } } diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGB.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGB.java index 52f505aa1da..259d2042c0e 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGB.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGB.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,10 +14,13 @@ *******************************************************************************/ package org.eclipse.swt.tests.junit; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import org.eclipse.swt.graphics.RGB; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Automated Test Suite for class org.eclipse.swt.graphics.RGB @@ -26,380 +29,304 @@ */ public class Test_org_eclipse_swt_graphics_RGB { -@Test -public void test_ConstructorIII() { - // Test RGB(int red, int green, int blue) - new RGB(20,100,200); - - new RGB(0,0,0); - - - - try { - new RGB(-1, 20, 50); - fail("No exception thrown for red < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGB(256, 20, 50); - fail("No exception thrown for red > 255"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGB(20, -1, 50); - fail("No exception thrown for green < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGB(20, 256, 50); - fail("No exception thrown for green > 255"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGB(20, 50, -1); - fail("No exception thrown for blue < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGB(20, 50, 256); - fail("No exception thrown for blue > 255"); - } - catch (IllegalArgumentException e) { - } - -} - -@Test -public void test_ConstructorFFF() { - - new RGB(0f,0f,0f); - - new RGB(0f,1f,0f); - new RGB(0f,0f,1f); - new RGB(0f,0.6f,0.4f); - new RGB(1f,0f,1f); - new RGB(1f,1f,1f); - new RGB(1f,0f,1f); - new RGB(1f,1f,0f); - new RGB(1f,0.6f,0.4f); - new RGB(59f,0f,1f); - new RGB(59f,1f,1f); - new RGB(59f,0f,1f); - new RGB(59f,1f,0f); - new RGB(59f,0.6f,0.4f); - new RGB(60f,0f,1f); - new RGB(60f,1f,1f); - new RGB(60f,0f,1f); - new RGB(60f,1f,0f); - new RGB(60f,0.6f,0.4f); - new RGB(61f,0f,1f); - new RGB(61f,1f,1f); - new RGB(61f,0f,1f); - new RGB(61f,1f,0f); - new RGB(61f,0.6f,0.4f); - new RGB(119f,0f,1f); - new RGB(119f,1f,1f); - new RGB(119f,0f,1f); - new RGB(119f,1f,0f); - new RGB(119f,0.6f,0.4f); - new RGB(120f,0f,1f); - new RGB(120f,1f,1f); - new RGB(120f,0f,1f); - new RGB(120f,1f,0f); - new RGB(120f,0.6f,0.4f); - new RGB(121f,0f,1f); - new RGB(121f,1f,1f); - new RGB(121f,0f,1f); - new RGB(121f,1f,0f); - new RGB(121f,0.6f,0.4f); - new RGB(179f,0f,1f); - new RGB(179f,1f,1f); - new RGB(179f,0f,1f); - new RGB(179f,1f,0f); - new RGB(179f,0.6f,0.4f); - new RGB(180f,0f,1f); - new RGB(180f,1f,1f); - new RGB(180f,0f,1f); - new RGB(180f,1f,0f); - new RGB(180f,0.6f,0.4f); - new RGB(181f,0f,1f); - new RGB(181f,1f,1f); - new RGB(181f,0f,1f); - new RGB(181f,1f,0f); - new RGB(181f,0.6f,0.4f); - new RGB(239f,0f,1f); - new RGB(239f,1f,1f); - new RGB(239f,0f,1f); - new RGB(239f,1f,0f); - new RGB(239f,0.6f,0.4f); - new RGB(240f,0f,1f); - new RGB(240f,1f,1f); - new RGB(240f,0f,1f); - new RGB(240f,1f,0f); - new RGB(240f,0.6f,0.4f); - new RGB(241f,0f,1f); - new RGB(241f,1f,1f); - new RGB(241f,0f,1f); - new RGB(241f,1f,0f); - new RGB(241f,0.6f,0.4f); - new RGB(299f,0f,1f); - new RGB(299f,1f,1f); - new RGB(299f,0f,1f); - new RGB(299f,1f,0f); - new RGB(299f,0.6f,0.4f); - new RGB(300f,0f,1f); - new RGB(300f,1f,1f); - new RGB(300f,0f,1f); - new RGB(300f,1f,0f); - new RGB(300f,0.6f,0.4f); - new RGB(301f,0f,1f); - new RGB(301f,1f,1f); - new RGB(301f,0f,1f); - new RGB(301f,1f,0f); - new RGB(301f,0.6f,0.4f); - new RGB(359f,0f,1f); - new RGB(359f,1f,1f); - new RGB(359f,0f,1f); - new RGB(359f,1f,0f); - new RGB(359f,0.6f,0.4f); - new RGB(360f,0f,1f); - new RGB(360f,1f,1f); - new RGB(360f,0f,1f); - new RGB(360f,1f,0f); - new RGB(360f,0.6f,0.4f); - - try { - new RGB(400f, 0.5f, 0.5f); - fail("No exception thrown for hue > 360"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGB(-5f, 0.5f, 0.5f); - fail("No exception thrown for hue < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGB(200f, -0.5f, 0.5f); - fail("No exception thrown for saturation < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGB(200f, 300f, 0.5f); - fail("No exception thrown for saturation > 1"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGB(200f, 0.5f, -0.5f); - fail("No exception thrown for brightness < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGB(200f, 0.5f, 400f); - fail("No exception thrown for brightness > 1"); - } - catch (IllegalArgumentException e) { - } -} - -@Test -public void test_equalsLjava_lang_Object() { - int r = 0, g = 127, b = 254; - RGB rgb1 = new RGB(r, g, b); - RGB rgb2; - - rgb2 = rgb1; - if (!rgb1.equals(rgb2)) { - fail("Two references to the same RGB instance not found equal"); - } + @Test + public void test_ConstructorIII() { + // Test RGB(int red, int green, int blue) + new RGB(20, 100, 200); + + new RGB(0, 0, 0); + + assertThrows(IllegalArgumentException.class, () -> new RGB(-1, 20, 50), "No exception thrown for red < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGB(256, 20, 50), "No exception thrown for red > 255"); + assertThrows(IllegalArgumentException.class, () -> new RGB(20, -1, 50), "No exception thrown for green < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGB(20, 256, 50), "No exception thrown for green > 255"); + assertThrows(IllegalArgumentException.class, () -> new RGB(20, 50, -1), "No exception thrown for blue < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGB(20, 50, 256), "No exception thrown for blue > 255"); + } + + @Test + public void test_ConstructorFFF() { + + new RGB(0f, 0f, 0f); + + new RGB(0f, 1f, 0f); + new RGB(0f, 0f, 1f); + new RGB(0f, 0.6f, 0.4f); + new RGB(1f, 0f, 1f); + new RGB(1f, 1f, 1f); + new RGB(1f, 0f, 1f); + new RGB(1f, 1f, 0f); + new RGB(1f, 0.6f, 0.4f); + new RGB(59f, 0f, 1f); + new RGB(59f, 1f, 1f); + new RGB(59f, 0f, 1f); + new RGB(59f, 1f, 0f); + new RGB(59f, 0.6f, 0.4f); + new RGB(60f, 0f, 1f); + new RGB(60f, 1f, 1f); + new RGB(60f, 0f, 1f); + new RGB(60f, 1f, 0f); + new RGB(60f, 0.6f, 0.4f); + new RGB(61f, 0f, 1f); + new RGB(61f, 1f, 1f); + new RGB(61f, 0f, 1f); + new RGB(61f, 1f, 0f); + new RGB(61f, 0.6f, 0.4f); + new RGB(119f, 0f, 1f); + new RGB(119f, 1f, 1f); + new RGB(119f, 0f, 1f); + new RGB(119f, 1f, 0f); + new RGB(119f, 0.6f, 0.4f); + new RGB(120f, 0f, 1f); + new RGB(120f, 1f, 1f); + new RGB(120f, 0f, 1f); + new RGB(120f, 1f, 0f); + new RGB(120f, 0.6f, 0.4f); + new RGB(121f, 0f, 1f); + new RGB(121f, 1f, 1f); + new RGB(121f, 0f, 1f); + new RGB(121f, 1f, 0f); + new RGB(121f, 0.6f, 0.4f); + new RGB(179f, 0f, 1f); + new RGB(179f, 1f, 1f); + new RGB(179f, 0f, 1f); + new RGB(179f, 1f, 0f); + new RGB(179f, 0.6f, 0.4f); + new RGB(180f, 0f, 1f); + new RGB(180f, 1f, 1f); + new RGB(180f, 0f, 1f); + new RGB(180f, 1f, 0f); + new RGB(180f, 0.6f, 0.4f); + new RGB(181f, 0f, 1f); + new RGB(181f, 1f, 1f); + new RGB(181f, 0f, 1f); + new RGB(181f, 1f, 0f); + new RGB(181f, 0.6f, 0.4f); + new RGB(239f, 0f, 1f); + new RGB(239f, 1f, 1f); + new RGB(239f, 0f, 1f); + new RGB(239f, 1f, 0f); + new RGB(239f, 0.6f, 0.4f); + new RGB(240f, 0f, 1f); + new RGB(240f, 1f, 1f); + new RGB(240f, 0f, 1f); + new RGB(240f, 1f, 0f); + new RGB(240f, 0.6f, 0.4f); + new RGB(241f, 0f, 1f); + new RGB(241f, 1f, 1f); + new RGB(241f, 0f, 1f); + new RGB(241f, 1f, 0f); + new RGB(241f, 0.6f, 0.4f); + new RGB(299f, 0f, 1f); + new RGB(299f, 1f, 1f); + new RGB(299f, 0f, 1f); + new RGB(299f, 1f, 0f); + new RGB(299f, 0.6f, 0.4f); + new RGB(300f, 0f, 1f); + new RGB(300f, 1f, 1f); + new RGB(300f, 0f, 1f); + new RGB(300f, 1f, 0f); + new RGB(300f, 0.6f, 0.4f); + new RGB(301f, 0f, 1f); + new RGB(301f, 1f, 1f); + new RGB(301f, 0f, 1f); + new RGB(301f, 1f, 0f); + new RGB(301f, 0.6f, 0.4f); + new RGB(359f, 0f, 1f); + new RGB(359f, 1f, 1f); + new RGB(359f, 0f, 1f); + new RGB(359f, 1f, 0f); + new RGB(359f, 0.6f, 0.4f); + new RGB(360f, 0f, 1f); + new RGB(360f, 1f, 1f); + new RGB(360f, 0f, 1f); + new RGB(360f, 1f, 0f); + new RGB(360f, 0.6f, 0.4f); + + assertThrows(IllegalArgumentException.class, () -> new RGB(400f, 0.5f, 0.5f), + "No exception thrown for hue > 360"); + assertThrows(IllegalArgumentException.class, () -> new RGB(-5f, 0.5f, 0.5f), "No exception thrown for hue < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGB(200f, -0.5f, 0.5f), + "No exception thrown for saturation < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGB(200f, 300f, 0.5f), + "No exception thrown for saturation > 1"); + assertThrows(IllegalArgumentException.class, () -> new RGB(200f, 0.5f, -0.5f), + "No exception thrown for brightness < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGB(200f, 0.5f, 400f), + "No exception thrown for brightness > 1"); + } + + @Test + public void test_equalsLjava_lang_Object() { + int r = 0, g = 127, b = 254; + RGB rgb1 = new RGB(r, g, b); + RGB rgb2; + + rgb2 = rgb1; + if (!rgb1.equals(rgb2)) { + fail("Two references to the same RGB instance not found equal"); + } - rgb2 = new RGB(r, g, b); - if (!rgb1.equals(rgb2)) { - fail("References to two different RGB instances with same R G B parameters not found equal"); - } + rgb2 = new RGB(r, g, b); + if (!rgb1.equals(rgb2)) { + fail("References to two different RGB instances with same R G B parameters not found equal"); + } - if (rgb1.equals(new RGB(r+1, g, b)) || - rgb1.equals(new RGB(r, g+1, b)) || - rgb1.equals(new RGB(r, g, b+1)) || - rgb1.equals(new RGB(r+1, g+1, b+1))) { - fail("Comparing two RGB instances with different combination of R G B parameters found equal"); - } + if (rgb1.equals(new RGB(r + 1, g, b)) || + rgb1.equals(new RGB(r, g + 1, b)) || + rgb1.equals(new RGB(r, g, b + 1)) || + rgb1.equals(new RGB(r + 1, g + 1, b + 1))) { + fail("Comparing two RGB instances with different combination of R G B parameters found equal"); + } - float hue = 220f, sat = 0.6f, bright = 0.7f; - rgb1 = new RGB(hue, sat, bright); - rgb2 = rgb1; - if (!rgb1.equals(rgb2)) { - fail("Two references to the same RGB instance not found equal"); - } + float hue = 220f, sat = 0.6f, bright = 0.7f; + rgb1 = new RGB(hue, sat, bright); + rgb2 = rgb1; + if (!rgb1.equals(rgb2)) { + fail("Two references to the same RGB instance not found equal"); + } - rgb2 = new RGB(hue, sat, bright); - if (!rgb1.equals(rgb2)) { - fail("References to two different RGB instances with same H S B parameters not found equal"); - } + rgb2 = new RGB(hue, sat, bright); + if (!rgb1.equals(rgb2)) { + fail("References to two different RGB instances with same H S B parameters not found equal"); + } - if (rgb1.equals(new RGB(hue+1, sat, bright)) || - rgb1.equals(new RGB(hue, sat+0.1f, bright)) || - rgb1.equals(new RGB(hue, sat, bright+0.1f)) || - rgb1.equals(new RGB(hue+1, sat+0.1f, bright+0.1f))) { - fail("Comparing two RGB instances with different combination of H S B parameters found equal"); + if (rgb1.equals(new RGB(hue + 1, sat, bright)) || + rgb1.equals(new RGB(hue, sat + 0.1f, bright)) || + rgb1.equals(new RGB(hue, sat, bright + 0.1f)) || + rgb1.equals(new RGB(hue + 1, sat + 0.1f, bright + 0.1f))) { + fail("Comparing two RGB instances with different combination of H S B parameters found equal"); + } } -} -@Test -public void test_getHSB() { - float[] hsb = new float[] { - 0f,0f,0f, - 0f,1f,1f, - 0f,1f,0f, - 0f,0f,1f, - 0f,0.6f,0.4f, - 1f,0f,1f, - 1f,1f,1f, - 1f,0f,1f, - 1f,1f,0f, - 1f,0.6f,0.4f, - 59f,0f,1f, - 59f,1f,1f, - 59f,0f,1f, - 59f,1f,0f, - 59f,0.6f,0.4f, - 60f,0f,1f, - 60f,1f,1f, - 60f,0f,1f, - 60f,1f,0f, - 60f,0.6f,0.4f, - 61f,0f,1f, - 61f,1f,1f, - 61f,0f,1f, - 61f,1f,0f, - 61f,0.6f,0.4f, - 119f,0f,1f, - 119f,1f,1f, - 119f,0f,1f, - 119f,1f,0f, - 119f,0.6f,0.4f, - 120f,0f,1f, - 120f,1f,1f, - 120f,0f,1f, - 120f,1f,0f, - 120f,0.6f,0.4f, - 121f,0f,1f, - 121f,1f,1f, - 121f,0f,1f, - 121f,1f,0f, - 121f,0.6f,0.4f, - 179f,0f,1f, - 179f,1f,1f, - 179f,0f,1f, - 179f,1f,0f, - 179f,0.6f,0.4f, - 180f,0f,1f, - 180f,1f,1f, - 180f,0f,1f, - 180f,1f,0f, - 180f,0.6f,0.4f, - 181f,0f,1f, - 181f,1f,1f, - 181f,0f,1f, - 181f,1f,0f, - 181f,0.6f,0.4f, - 239f,0f,1f, - 239f,1f,1f, - 239f,0f,1f, - 239f,1f,0f, - 239f,0.6f,0.4f, - 240f,0f,1f, - 240f,1f,1f, - 240f,0f,1f, - 240f,1f,0f, - 240f,0.6f,0.4f, - 241f,0f,1f, - 241f,1f,1f, - 241f,0f,1f, - 241f,1f,0f, - 241f,0.6f,0.4f, - 299f,0f,1f, - 299f,1f,1f, - 299f,0f,1f, - 299f,1f,0f, - 299f,0.6f,0.4f, - 300f,0f,1f, - 300f,1f,1f, - 300f,0f,1f, - 300f,1f,0f, - 300f,0.6f,0.4f, - 301f,0f,1f, - 301f,1f,1f, - 301f,0f,1f, - 301f,1f,0f, - 301f,0.6f,0.4f, - 359f,0f,1f, - 359f,1f,1f, - 359f,0f,1f, - 359f,1f,0f, - 359f,0.6f,0.4f, - 360f,0f,1f, - 360f,1f,1f, - 360f,0f,1f, - 360f,1f,0f, - 360f,0.6f,0.4f, - 220f,0.6f,0.7f}; - for (int i = 0; i < hsb.length; i+=3) { - RGB rgb1 = new RGB(hsb[i], hsb[i+1], hsb[i+2]); - float[] hsb2 = rgb1.getHSB(); - RGB rgb2 = new RGB(hsb2[0], hsb2[1], hsb2[2]); - if (!rgb1.equals(rgb2)) { - fail("Two references to the same RGB using getHSB() function not found equal"); + @Test + public void test_getHSB() { + float[] hsb = new float[] { + 0f, 0f, 0f, + 0f, 1f, 1f, + 0f, 1f, 0f, + 0f, 0f, 1f, + 0f, 0.6f, 0.4f, + 1f, 0f, 1f, + 1f, 1f, 1f, + 1f, 0f, 1f, + 1f, 1f, 0f, + 1f, 0.6f, 0.4f, + 59f, 0f, 1f, + 59f, 1f, 1f, + 59f, 0f, 1f, + 59f, 1f, 0f, + 59f, 0.6f, 0.4f, + 60f, 0f, 1f, + 60f, 1f, 1f, + 60f, 0f, 1f, + 60f, 1f, 0f, + 60f, 0.6f, 0.4f, + 61f, 0f, 1f, + 61f, 1f, 1f, + 61f, 0f, 1f, + 61f, 1f, 0f, + 61f, 0.6f, 0.4f, + 119f, 0f, 1f, + 119f, 1f, 1f, + 119f, 0f, 1f, + 119f, 1f, 0f, + 119f, 0.6f, 0.4f, + 120f, 0f, 1f, + 120f, 1f, 1f, + 120f, 0f, 1f, + 120f, 1f, 0f, + 120f, 0.6f, 0.4f, + 121f, 0f, 1f, + 121f, 1f, 1f, + 121f, 0f, 1f, + 121f, 1f, 0f, + 121f, 0.6f, 0.4f, + 179f, 0f, 1f, + 179f, 1f, 1f, + 179f, 0f, 1f, + 179f, 1f, 0f, + 179f, 0.6f, 0.4f, + 180f, 0f, 1f, + 180f, 1f, 1f, + 180f, 0f, 1f, + 180f, 1f, 0f, + 180f, 0.6f, 0.4f, + 181f, 0f, 1f, + 181f, 1f, 1f, + 181f, 0f, 1f, + 181f, 1f, 0f, + 181f, 0.6f, 0.4f, + 239f, 0f, 1f, + 239f, 1f, 1f, + 239f, 0f, 1f, + 239f, 1f, 0f, + 239f, 0.6f, 0.4f, + 240f, 0f, 1f, + 240f, 1f, 1f, + 240f, 0f, 1f, + 240f, 1f, 0f, + 240f, 0.6f, 0.4f, + 241f, 0f, 1f, + 241f, 1f, 1f, + 241f, 0f, 1f, + 241f, 1f, 0f, + 241f, 0.6f, 0.4f, + 299f, 0f, 1f, + 299f, 1f, 1f, + 299f, 0f, 1f, + 299f, 1f, 0f, + 299f, 0.6f, 0.4f, + 300f, 0f, 1f, + 300f, 1f, 1f, + 300f, 0f, 1f, + 300f, 1f, 0f, + 300f, 0.6f, 0.4f, + 301f, 0f, 1f, + 301f, 1f, 1f, + 301f, 0f, 1f, + 301f, 1f, 0f, + 301f, 0.6f, 0.4f, + 359f, 0f, 1f, + 359f, 1f, 1f, + 359f, 0f, 1f, + 359f, 1f, 0f, + 359f, 0.6f, 0.4f, + 360f, 0f, 1f, + 360f, 1f, 1f, + 360f, 0f, 1f, + 360f, 1f, 0f, + 360f, 0.6f, 0.4f, + 220f, 0.6f, 0.7f }; + for (int i = 0; i < hsb.length; i += 3) { + RGB rgb1 = new RGB(hsb[i], hsb[i + 1], hsb[i + 2]); + float[] hsb2 = rgb1.getHSB(); + RGB rgb2 = new RGB(hsb2[0], hsb2[1], hsb2[2]); + assertEquals(rgb1, rgb2, + "Two references to the same RGB using getHSB() function not found equal"); } } -} - -@Test -public void test_hashCode() { - int r = 255, g = 100, b = 0; - RGB rgb1 = new RGB(r, g, b); - RGB rgb2 = new RGB(r, g, b); - int hash1 = rgb1.hashCode(); - int hash2 = rgb2.hashCode(); + @Test + public void test_hashCode() { + int r = 255, g = 100, b = 0; + RGB rgb1 = new RGB(r, g, b); + RGB rgb2 = new RGB(r, g, b); - if (hash1 != hash2) { - fail("Two RGB instances with same R G B parameters returned different hash codes"); - } + int hash1 = rgb1.hashCode(); + int hash2 = rgb2.hashCode(); + assertEquals(hash1, hash2, "Two RGB instances with same R G B parameters returned different hash codes"); - if (rgb1.hashCode() == new RGB(g, b, r).hashCode() || - rgb1.hashCode() == new RGB(b, r, g).hashCode()) { - fail("Two RGB instances with different R G B parameters returned the same hash code"); + assertTrue(rgb1.hashCode() != new RGB(g, b, r).hashCode() && + rgb1.hashCode() != new RGB(b, r, g).hashCode(), + "Two RGB instances with different R G B parameters returned the same hash code"); } -} -@Test -public void test_toString() { - RGB rgb = new RGB(0, 100, 200); + @Test + public void test_toString() { + RGB rgb = new RGB(0, 100, 200); - String s = rgb.toString(); - - if (s == null || s.length() == 0) { - fail("RGB.toString returns a null or empty String"); + String s = rgb.toString(); + assertTrue(s != null && s.length() != 0, "RGB.toString returns a null or empty String"); } } -} diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGBA.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGBA.java index d2aec50ce0d..ef96ab9f406 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGBA.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_RGBA.java @@ -14,10 +14,14 @@ *******************************************************************************/ package org.eclipse.swt.tests.junit; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import org.eclipse.swt.graphics.RGBA; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Automated Test Suite for class org.eclipse.swt.graphics.RGBA @@ -26,425 +30,336 @@ */ public class Test_org_eclipse_swt_graphics_RGBA { -@Test -public void test_ConstructorIIII() { - // Test RGBA(int red, int green, int blue, int alpha) - new RGBA(20,100,200,255); - - new RGBA(0,0,0,0); - - - - try { - new RGBA(-1, 20, 50, 255); - fail("No exception thrown for red < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(256, 20, 50, 255); - fail("No exception thrown for red > 255"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(20, -1, 50, 0); - fail("No exception thrown for green < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(20, 256, 50, 0); - fail("No exception thrown for green > 255"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(20, 50, -1, 0); - fail("No exception thrown for blue < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(20, 50, 256, 0); - fail("No exception thrown for blue > 255"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(20, 50, 10, -1); - fail("No exception thrown for alpha < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(20, 50, 10, 256); - fail("No exception thrown for alpha > 255"); - } - catch (IllegalArgumentException e) { - } -} - -@Test -public void test_ConstructorFFFF() { - - new RGBA(0f,0f,0f,0f); - - new RGBA(0f,1f,0f,0f); - new RGBA(0f,0f,1f,1f); - new RGBA(0f,0.6f,0.4f,0.8f); - new RGBA(1f,0f,1f,1f); - new RGBA(1f,1f,1f,1f); - new RGBA(1f,0f,1f,0f); - new RGBA(1f,1f,0f,1f); - new RGBA(1f,0.6f,0.4f,0.8f); - new RGBA(59f,0f,1f,1f); - new RGBA(59f,1f,1f,1f); - new RGBA(59f,0f,1f,1f); - new RGBA(59f,1f,0f,1f); - new RGBA(59f,0.6f,0.4f,0.8f); - new RGBA(60f,0f,1f,1f); - new RGBA(60f,1f,1f,1f); - new RGBA(60f,0f,1f,1f); - new RGBA(60f,1f,0f,1f); - new RGBA(60f,0.6f,0.4f,0.8f); - new RGBA(61f,0f,1f,1f); - new RGBA(61f,1f,1f,1f); - new RGBA(61f,0f,1f,1f); - new RGBA(61f,1f,0f,1f); - new RGBA(61f,0.6f,0.4f,0.8f); - new RGBA(119f,0f,1f,1f); - new RGBA(119f,1f,1f,1f); - new RGBA(119f,0f,1f,1f); - new RGBA(119f,1f,0f,0f); - new RGBA(119f,0.6f,0.4f,0.8f); - new RGBA(120f,0f,1f,1f); - new RGBA(120f,1f,1f,1f); - new RGBA(120f,0f,1f,1f); - new RGBA(120f,1f,0f,0f); - new RGBA(120f,0.6f,0.4f,0.8f); - new RGBA(121f,0f,1f,1f); - new RGBA(121f,1f,1f,1f); - new RGBA(121f,0f,1f,1f); - new RGBA(121f,1f,0f,0f); - new RGBA(121f,0.6f,0.4f,0.8f); - new RGBA(179f,0f,1f,1f); - new RGBA(179f,1f,1f,1f); - new RGBA(179f,0f,1f,1f); - new RGBA(179f,1f,0f,0f); - new RGBA(179f,0.6f,0.4f,0.8f); - new RGBA(180f,0f,1f,1f); - new RGBA(180f,1f,1f,1f); - new RGBA(180f,0f,1f,1f); - new RGBA(180f,1f,0f,0f); - new RGBA(180f,0.6f,0.4f,0.8f); - new RGBA(181f,0f,1f,1f); - new RGBA(181f,1f,1f,1f); - new RGBA(181f,0f,1f,1f); - new RGBA(181f,1f,0f,0f); - new RGBA(181f,0.6f,0.4f,0.8f); - new RGBA(239f,0f,1f,1f); - new RGBA(239f,1f,1f,1f); - new RGBA(239f,0f,1f,1f); - new RGBA(239f,1f,0f,0f); - new RGBA(239f,0.6f,0.4f,0.8f); - new RGBA(240f,0f,1f,1f); - new RGBA(240f,1f,1f,1f); - new RGBA(240f,0f,1f,1f); - new RGBA(240f,1f,0f,0f); - new RGBA(240f,0.6f,0.4f,0.8f); - new RGBA(241f,0f,1f,1f); - new RGBA(241f,1f,1f,1f); - new RGBA(241f,0f,1f,1f); - new RGBA(241f,1f,0f,0f); - new RGBA(241f,0.6f,0.4f,0.8f); - new RGBA(299f,0f,1f,1f); - new RGBA(299f,1f,1f,1f); - new RGBA(299f,0f,1f,1f); - new RGBA(299f,1f,0f,0f); - new RGBA(299f,0.6f,0.4f,0.8f); - new RGBA(300f,0f,1f,1f); - new RGBA(300f,1f,1f,1f); - new RGBA(300f,0f,1f,1f); - new RGBA(300f,1f,0f,0f); - new RGBA(300f,0.6f,0.4f,0.8f); - new RGBA(301f,0f,1f,1f); - new RGBA(301f,1f,1f,1f); - new RGBA(301f,0f,1f,1f); - new RGBA(301f,1f,0f,0f); - new RGBA(301f,0.6f,0.4f,0.8f); - new RGBA(359f,0f,1f,1f); - new RGBA(359f,1f,1f,1f); - new RGBA(359f,0f,1f,1f); - new RGBA(359f,1f,0f,0f); - new RGBA(359f,0.6f,0.4f,0.8f); - new RGBA(360f,0f,1f,1f); - new RGBA(360f,1f,1f,1f); - new RGBA(360f,0f,1f,1f); - new RGBA(360f,1f,0f,0f); - new RGBA(360f,0.6f,0.4f,0.8f); - - try { - new RGBA(400f, 0.5f, 0.5f, 0.8f); - fail("No exception thrown for hue > 360"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(-5f, 0.5f, 0.5f, 0.8f); - fail("No exception thrown for hue < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(200f, -0.5f, 0.5f, 0.8f); - fail("No exception thrown for saturation < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(200f, 300f, 0.5f, 0.8f); - fail("No exception thrown for saturation > 1"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(200f, 0.5f, -0.5f, 0.8f); - fail("No exception thrown for brightness < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(200f, 0.5f, 400f, 0.8f); - fail("No exception thrown for brightness > 1"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(200f, 0.5f, 0.5f, -0.5f); - fail("No exception thrown for alpha < 0"); - } - catch (IllegalArgumentException e) { - } - - try { - new RGBA(200f, 0.5f, 0.5f, 400f); - fail("No exception thrown for alpha > 1"); - } - catch (IllegalArgumentException e) { - } -} - -@Test -public void test_equalsLjava_lang_Object() { - int r = 0, g = 127, b = 254, a = 254; - RGBA rgba1 = new RGBA(r, g, b, a); - RGBA rgba2; - - rgba2 = rgba1; - if (!rgba1.equals(rgba2)) { - fail("Two references to the same RGBA instance not found equal"); - } + @Test + public void test_ConstructorIIII() { + // Test RGBA(int red, int green, int blue, int alpha) + new RGBA(20, 100, 200, 255); + + new RGBA(0, 0, 0, 0); + + assertThrows(IllegalArgumentException.class, () -> new RGBA(-1, 20, 50, 255), + "No exception thrown for red < 0"); + + assertThrows(IllegalArgumentException.class, () -> new RGBA(256, 20, 50, 255), + "No exception thrown for red > 255"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(20, -1, 50, 0), + "No exception thrown for green < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(20, 256, 50, 0), + "No exception thrown for green > 255"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(20, 50, -1, 0), "No exception thrown for blue < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(20, 50, 256, 0), + "No exception thrown for blue > 255"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(20, 50, 10, -1), + "No exception thrown for alpha < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(20, 50, 10, 256), + "No exception thrown for alpha > 255"); + } + + @Test + public void test_ConstructorFFFF() { + + new RGBA(0f, 0f, 0f, 0f); + + new RGBA(0f, 1f, 0f, 0f); + new RGBA(0f, 0f, 1f, 1f); + new RGBA(0f, 0.6f, 0.4f, 0.8f); + new RGBA(1f, 0f, 1f, 1f); + new RGBA(1f, 1f, 1f, 1f); + new RGBA(1f, 0f, 1f, 0f); + new RGBA(1f, 1f, 0f, 1f); + new RGBA(1f, 0.6f, 0.4f, 0.8f); + new RGBA(59f, 0f, 1f, 1f); + new RGBA(59f, 1f, 1f, 1f); + new RGBA(59f, 0f, 1f, 1f); + new RGBA(59f, 1f, 0f, 1f); + new RGBA(59f, 0.6f, 0.4f, 0.8f); + new RGBA(60f, 0f, 1f, 1f); + new RGBA(60f, 1f, 1f, 1f); + new RGBA(60f, 0f, 1f, 1f); + new RGBA(60f, 1f, 0f, 1f); + new RGBA(60f, 0.6f, 0.4f, 0.8f); + new RGBA(61f, 0f, 1f, 1f); + new RGBA(61f, 1f, 1f, 1f); + new RGBA(61f, 0f, 1f, 1f); + new RGBA(61f, 1f, 0f, 1f); + new RGBA(61f, 0.6f, 0.4f, 0.8f); + new RGBA(119f, 0f, 1f, 1f); + new RGBA(119f, 1f, 1f, 1f); + new RGBA(119f, 0f, 1f, 1f); + new RGBA(119f, 1f, 0f, 0f); + new RGBA(119f, 0.6f, 0.4f, 0.8f); + new RGBA(120f, 0f, 1f, 1f); + new RGBA(120f, 1f, 1f, 1f); + new RGBA(120f, 0f, 1f, 1f); + new RGBA(120f, 1f, 0f, 0f); + new RGBA(120f, 0.6f, 0.4f, 0.8f); + new RGBA(121f, 0f, 1f, 1f); + new RGBA(121f, 1f, 1f, 1f); + new RGBA(121f, 0f, 1f, 1f); + new RGBA(121f, 1f, 0f, 0f); + new RGBA(121f, 0.6f, 0.4f, 0.8f); + new RGBA(179f, 0f, 1f, 1f); + new RGBA(179f, 1f, 1f, 1f); + new RGBA(179f, 0f, 1f, 1f); + new RGBA(179f, 1f, 0f, 0f); + new RGBA(179f, 0.6f, 0.4f, 0.8f); + new RGBA(180f, 0f, 1f, 1f); + new RGBA(180f, 1f, 1f, 1f); + new RGBA(180f, 0f, 1f, 1f); + new RGBA(180f, 1f, 0f, 0f); + new RGBA(180f, 0.6f, 0.4f, 0.8f); + new RGBA(181f, 0f, 1f, 1f); + new RGBA(181f, 1f, 1f, 1f); + new RGBA(181f, 0f, 1f, 1f); + new RGBA(181f, 1f, 0f, 0f); + new RGBA(181f, 0.6f, 0.4f, 0.8f); + new RGBA(239f, 0f, 1f, 1f); + new RGBA(239f, 1f, 1f, 1f); + new RGBA(239f, 0f, 1f, 1f); + new RGBA(239f, 1f, 0f, 0f); + new RGBA(239f, 0.6f, 0.4f, 0.8f); + new RGBA(240f, 0f, 1f, 1f); + new RGBA(240f, 1f, 1f, 1f); + new RGBA(240f, 0f, 1f, 1f); + new RGBA(240f, 1f, 0f, 0f); + new RGBA(240f, 0.6f, 0.4f, 0.8f); + new RGBA(241f, 0f, 1f, 1f); + new RGBA(241f, 1f, 1f, 1f); + new RGBA(241f, 0f, 1f, 1f); + new RGBA(241f, 1f, 0f, 0f); + new RGBA(241f, 0.6f, 0.4f, 0.8f); + new RGBA(299f, 0f, 1f, 1f); + new RGBA(299f, 1f, 1f, 1f); + new RGBA(299f, 0f, 1f, 1f); + new RGBA(299f, 1f, 0f, 0f); + new RGBA(299f, 0.6f, 0.4f, 0.8f); + new RGBA(300f, 0f, 1f, 1f); + new RGBA(300f, 1f, 1f, 1f); + new RGBA(300f, 0f, 1f, 1f); + new RGBA(300f, 1f, 0f, 0f); + new RGBA(300f, 0.6f, 0.4f, 0.8f); + new RGBA(301f, 0f, 1f, 1f); + new RGBA(301f, 1f, 1f, 1f); + new RGBA(301f, 0f, 1f, 1f); + new RGBA(301f, 1f, 0f, 0f); + new RGBA(301f, 0.6f, 0.4f, 0.8f); + new RGBA(359f, 0f, 1f, 1f); + new RGBA(359f, 1f, 1f, 1f); + new RGBA(359f, 0f, 1f, 1f); + new RGBA(359f, 1f, 0f, 0f); + new RGBA(359f, 0.6f, 0.4f, 0.8f); + new RGBA(360f, 0f, 1f, 1f); + new RGBA(360f, 1f, 1f, 1f); + new RGBA(360f, 0f, 1f, 1f); + new RGBA(360f, 1f, 0f, 0f); + new RGBA(360f, 0.6f, 0.4f, 0.8f); + + assertThrows(IllegalArgumentException.class, () -> new RGBA(400f, 0.5f, 0.5f, 0.8f), + "No exception thrown for hue > 360"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(-5f, 0.5f, 0.5f, 0.8f), + "No exception thrown for hue < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(200f, -0.5f, 0.5f, 0.8f), + "No exception thrown for saturation < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(200f, 300f, 0.5f, 0.8f), + "No exception thrown for saturation > 1"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(200f, 0.5f, -0.5f, 0.8f), + "No exception thrown for brightness < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(200f, 0.5f, 400f, 0.8f), + "No exception thrown for brightness > 1"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(200f, 0.5f, 0.5f, -0.5f), + "No exception thrown for alpha < 0"); + assertThrows(IllegalArgumentException.class, () -> new RGBA(200f, 0.5f, 0.5f, 400f), + "No exception thrown for alpha > 1"); + } + + @Test + public void test_equalsLjava_lang_Object() { + int r = 0, g = 127, b = 254, a = 254; + RGBA rgba1 = new RGBA(r, g, b, a); + RGBA rgba2; + + rgba2 = rgba1; + if (!rgba1.equals(rgba2)) { + fail("Two references to the same RGBA instance not found equal"); + } - rgba2 = new RGBA(r, g, b, a); - if (!rgba1.equals(rgba2)) { - fail("References to two different RGBA instances with same R G B A parameters not found equal"); - } + rgba2 = new RGBA(r, g, b, a); + if (!rgba1.equals(rgba2)) { + fail("References to two different RGBA instances with same R G B A parameters not found equal"); + } - if (rgba1.equals(new RGBA(r+1, g, b, a)) || - rgba1.equals(new RGBA(r, g+1, b, a)) || - rgba1.equals(new RGBA(r, g, b+1, a)) || - rgba1.equals(new RGBA(r, g, b, a+1)) || - rgba1.equals(new RGBA(r+1, g+1, b+1, a+1))) { - fail("Comparing two RGBA instances with different combination of R G B A parameters found equal"); - } + if (rgba1.equals(new RGBA(r + 1, g, b, a)) || + rgba1.equals(new RGBA(r, g + 1, b, a)) || + rgba1.equals(new RGBA(r, g, b + 1, a)) || + rgba1.equals(new RGBA(r, g, b, a + 1)) || + rgba1.equals(new RGBA(r + 1, g + 1, b + 1, a + 1))) { + fail("Comparing two RGBA instances with different combination of R G B A parameters found equal"); + } - float hue = 220f, sat = 0.6f, bright = 0.7f, alpha = 0.5f; - rgba1 = new RGBA(hue, sat, bright, alpha); - rgba2 = rgba1; - if (!rgba1.equals(rgba2)) { - fail("Two references to the same RGBA instance not found equal"); - } + float hue = 220f, sat = 0.6f, bright = 0.7f, alpha = 0.5f; + rgba1 = new RGBA(hue, sat, bright, alpha); + rgba2 = rgba1; + if (!rgba1.equals(rgba2)) { + fail("Two references to the same RGBA instance not found equal"); + } - rgba2 = new RGBA(hue, sat, bright, alpha); - if (!rgba1.equals(rgba2)) { - fail("References to two different RGBA instances with same H S B A parameters not found equal"); - } + rgba2 = new RGBA(hue, sat, bright, alpha); + if (!rgba1.equals(rgba2)) { + fail("References to two different RGBA instances with same H S B A parameters not found equal"); + } - if (rgba1.equals(new RGBA(hue+1, sat, bright, alpha)) || - rgba1.equals(new RGBA(hue, sat+0.1f, bright, alpha)) || - rgba1.equals(new RGBA(hue, sat, bright+0.1f, alpha)) || - rgba1.equals(new RGBA(hue, sat, bright, alpha+1f)) || - rgba1.equals(new RGBA(hue+1, sat+0.1f, bright+0.1f, alpha+1f))) { - fail("Comparing two RGBA instances with different combination of H S B A parameters found equal"); + if (rgba1.equals(new RGBA(hue + 1, sat, bright, alpha)) || + rgba1.equals(new RGBA(hue, sat + 0.1f, bright, alpha)) || + rgba1.equals(new RGBA(hue, sat, bright + 0.1f, alpha)) || + rgba1.equals(new RGBA(hue, sat, bright, alpha + 1f)) || + rgba1.equals(new RGBA(hue + 1, sat + 0.1f, bright + 0.1f, alpha + 1f))) { + fail("Comparing two RGBA instances with different combination of H S B A parameters found equal"); + } } -} -@Test -public void test_getHSBA() { - float[] hsba = new float[] { - 0f,0f,0f,0f, - 0f,1f,1f,1f, - 0f,1f,0f,0f, - 0f,0f,1f,1f, - 0f,0.6f,0.4f,0.8f, - 1f,0f,1f,1f, - 1f,1f,1f,1f, - 1f,0f,1f,1f, - 1f,1f,0f,0f, - 1f,0.6f,0.4f,0.8f, - 59f,0f,1f,1f, - 59f,1f,1f,1f, - 59f,0f,1f,1f, - 59f,1f,0f,0f, - 59f,0.6f,0.4f,0.8f, - 60f,0f,1f,1f, - 60f,1f,1f,1f, - 60f,0f,1f,1f, - 60f,1f,0f,0f, - 60f,0.6f,0.4f,0.8f, - 61f,0f,1f,1f, - 61f,1f,1f,1f, - 61f,0f,1f,1f, - 61f,1f,0f,0f, - 61f,0.6f,0.4f,0.8f, - 119f,0f,1f,1f, - 119f,1f,1f,1f, - 119f,0f,1f,1f, - 119f,1f,0f,0f, - 119f,0.6f,0.4f,0.8f, - 120f,0f,1f,1f, - 120f,1f,1f,1f, - 120f,0f,1f,1f, - 120f,1f,0f,0f, - 120f,0.6f,0.4f,0.8f, - 121f,0f,1f,1f, - 121f,1f,1f,1f, - 121f,0f,1f,1f, - 121f,1f,0f,0f, - 121f,0.6f,0.4f,0.8f, - 179f,0f,1f,1f, - 179f,1f,1f,1f, - 179f,0f,1f,1f, - 179f,1f,0f,0f, - 179f,0.6f,0.4f,0.8f, - 180f,0f,1f,1f, - 180f,1f,1f,1f, - 180f,0f,1f,1f, - 180f,1f,0f,0f, - 180f,0.6f,0.4f,0.8f, - 181f,0f,1f,1f, - 181f,1f,1f,1f, - 181f,0f,1f,1f, - 181f,1f,0f,0f, - 181f,0.6f,0.4f,0.8f, - 239f,0f,1f,1f, - 239f,1f,1f,1f, - 239f,0f,1f,1f, - 239f,1f,0f,0f, - 239f,0.6f,0.4f,0.8f, - 240f,0f,1f,1f, - 240f,1f,1f,1f, - 240f,0f,1f,1f, - 240f,1f,0f,0f, - 240f,0.6f,0.4f,0.8f, - 241f,0f,1f,1f, - 241f,1f,1f,1f, - 241f,0f,1f,1f, - 241f,1f,0f,0f, - 241f,0.6f,0.4f,0.8f, - 299f,0f,1f,1f, - 299f,1f,1f,1f, - 299f,0f,1f,1f, - 299f,1f,0f,0f, - 299f,0.6f,0.4f,0.8f, - 300f,0f,1f,1f, - 300f,1f,1f,1f, - 300f,0f,1f,1f, - 300f,1f,0f,0f, - 300f,0.6f,0.4f,0.8f, - 301f,0f,1f,1f, - 301f,1f,1f,1f, - 301f,0f,1f,1f, - 301f,1f,0f,0f, - 301f,0.6f,0.4f,0.8f, - 359f,0f,1f,1f, - 359f,1f,1f,1f, - 359f,0f,1f,1f, - 359f,1f,0f,0f, - 359f,0.6f,0.4f,0.8f, - 360f,0f,1f,1f, - 360f,1f,1f,1f, - 360f,0f,1f,1f, - 360f,1f,0f,0f, - 360f,0.6f,0.4f,0.8f, - 220f,0.6f,0.7f,0.8f}; - for (int i = 0; i < hsba.length; i+=4) { - RGBA rgba1 = new RGBA(hsba[i], hsba[i+1], hsba[i+2], hsba[i+3]); - float[] hsba2 = rgba1.getHSBA(); - RGBA rgba2 = new RGBA(hsba2[0], hsba2[1], hsba2[2], hsba2[3]); - if (!rgba1.equals(rgba2)) { - fail("Two references to the same RGBA using getHSB() function not found equal"); + @Test + public void test_getHSBA() { + float[] hsba = new float[] { + 0f, 0f, 0f, 0f, + 0f, 1f, 1f, 1f, + 0f, 1f, 0f, 0f, + 0f, 0f, 1f, 1f, + 0f, 0.6f, 0.4f, 0.8f, + 1f, 0f, 1f, 1f, + 1f, 1f, 1f, 1f, + 1f, 0f, 1f, 1f, + 1f, 1f, 0f, 0f, + 1f, 0.6f, 0.4f, 0.8f, + 59f, 0f, 1f, 1f, + 59f, 1f, 1f, 1f, + 59f, 0f, 1f, 1f, + 59f, 1f, 0f, 0f, + 59f, 0.6f, 0.4f, 0.8f, + 60f, 0f, 1f, 1f, + 60f, 1f, 1f, 1f, + 60f, 0f, 1f, 1f, + 60f, 1f, 0f, 0f, + 60f, 0.6f, 0.4f, 0.8f, + 61f, 0f, 1f, 1f, + 61f, 1f, 1f, 1f, + 61f, 0f, 1f, 1f, + 61f, 1f, 0f, 0f, + 61f, 0.6f, 0.4f, 0.8f, + 119f, 0f, 1f, 1f, + 119f, 1f, 1f, 1f, + 119f, 0f, 1f, 1f, + 119f, 1f, 0f, 0f, + 119f, 0.6f, 0.4f, 0.8f, + 120f, 0f, 1f, 1f, + 120f, 1f, 1f, 1f, + 120f, 0f, 1f, 1f, + 120f, 1f, 0f, 0f, + 120f, 0.6f, 0.4f, 0.8f, + 121f, 0f, 1f, 1f, + 121f, 1f, 1f, 1f, + 121f, 0f, 1f, 1f, + 121f, 1f, 0f, 0f, + 121f, 0.6f, 0.4f, 0.8f, + 179f, 0f, 1f, 1f, + 179f, 1f, 1f, 1f, + 179f, 0f, 1f, 1f, + 179f, 1f, 0f, 0f, + 179f, 0.6f, 0.4f, 0.8f, + 180f, 0f, 1f, 1f, + 180f, 1f, 1f, 1f, + 180f, 0f, 1f, 1f, + 180f, 1f, 0f, 0f, + 180f, 0.6f, 0.4f, 0.8f, + 181f, 0f, 1f, 1f, + 181f, 1f, 1f, 1f, + 181f, 0f, 1f, 1f, + 181f, 1f, 0f, 0f, + 181f, 0.6f, 0.4f, 0.8f, + 239f, 0f, 1f, 1f, + 239f, 1f, 1f, 1f, + 239f, 0f, 1f, 1f, + 239f, 1f, 0f, 0f, + 239f, 0.6f, 0.4f, 0.8f, + 240f, 0f, 1f, 1f, + 240f, 1f, 1f, 1f, + 240f, 0f, 1f, 1f, + 240f, 1f, 0f, 0f, + 240f, 0.6f, 0.4f, 0.8f, + 241f, 0f, 1f, 1f, + 241f, 1f, 1f, 1f, + 241f, 0f, 1f, 1f, + 241f, 1f, 0f, 0f, + 241f, 0.6f, 0.4f, 0.8f, + 299f, 0f, 1f, 1f, + 299f, 1f, 1f, 1f, + 299f, 0f, 1f, 1f, + 299f, 1f, 0f, 0f, + 299f, 0.6f, 0.4f, 0.8f, + 300f, 0f, 1f, 1f, + 300f, 1f, 1f, 1f, + 300f, 0f, 1f, 1f, + 300f, 1f, 0f, 0f, + 300f, 0.6f, 0.4f, 0.8f, + 301f, 0f, 1f, 1f, + 301f, 1f, 1f, 1f, + 301f, 0f, 1f, 1f, + 301f, 1f, 0f, 0f, + 301f, 0.6f, 0.4f, 0.8f, + 359f, 0f, 1f, 1f, + 359f, 1f, 1f, 1f, + 359f, 0f, 1f, 1f, + 359f, 1f, 0f, 0f, + 359f, 0.6f, 0.4f, 0.8f, + 360f, 0f, 1f, 1f, + 360f, 1f, 1f, 1f, + 360f, 0f, 1f, 1f, + 360f, 1f, 0f, 0f, + 360f, 0.6f, 0.4f, 0.8f, + 220f, 0.6f, 0.7f, 0.8f }; + for (int i = 0; i < hsba.length; i += 4) { + RGBA rgba1 = new RGBA(hsba[i], hsba[i + 1], hsba[i + 2], hsba[i + 3]); + float[] hsba2 = rgba1.getHSBA(); + RGBA rgba2 = new RGBA(hsba2[0], hsba2[1], hsba2[2], hsba2[3]); + assertEquals(rgba1, rgba2, "Two references to the same RGBA using getHSB() function not found equal"); } } -} -@Test -public void test_hashCode() { - int r = 255, g = 100, b = 0, a = 0, different = 150; - RGBA rgba1 = new RGBA(r, g, b, a); - RGBA rgba2 = new RGBA(r, g, b, a); + @Test + public void test_hashCode() { + int r = 255, g = 100, b = 0, a = 0, different = 150; + RGBA rgba1 = new RGBA(r, g, b, a); + RGBA rgba2 = new RGBA(r, g, b, a); - int hash1 = rgba1.hashCode(); - int hash2 = rgba2.hashCode(); + int hash1 = rgba1.hashCode(); + int hash2 = rgba2.hashCode(); - if (hash1 != hash2) { - fail("Two RGBA instances with same R G B A parameters returned different hash codes"); - } + assertEquals(hash1, hash2, "Two RGBA instances with same R G B A parameters returned different hash codes"); - if (rgba1.hashCode() == new RGBA(g, b, r, a).hashCode() || - rgba1.hashCode() == new RGBA(b, r, g, a).hashCode()) { - fail("Two RGB instances with different R G B A parameters returned the same hash code"); - } + assertTrue(rgba1.hashCode() != new RGBA(g, b, r, a).hashCode() && + rgba1.hashCode() != new RGBA(b, r, g, a).hashCode(), + "Two RGB instances with different R G B A parameters returned the same hash code"); - if (rgba1.hashCode() == new RGBA(different, g, b, a).hashCode()) { - fail("Two RGBA instances with different RED parameters returned the same hash code"); - } + assertNotEquals(rgba1.hashCode(), new RGBA(different, g, b, a).hashCode(), + "Two RGBA instances with different RED parameters returned the same hash code"); - if (rgba1.hashCode() == new RGBA(r, different, b, a).hashCode()) { - fail("Two RGBA instances with different GREEN parameters returned the same hash code"); - } + assertNotEquals(rgba1.hashCode(), new RGBA(r, different, b, a).hashCode(), + "Two RGBA instances with different GREEN parameters returned the same hash code"); - if (rgba1.hashCode() == new RGBA(r, g, different, a).hashCode()) { - fail("Two RGBA instances with different BLUE parameters returned the same hash code"); - } + assertNotEquals(rgba1.hashCode(), new RGBA(r, g, different, a).hashCode(), + "Two RGBA instances with different BLUE parameters returned the same hash code"); - if (rgba1.hashCode() == new RGBA(r, g, b, different).hashCode()) { - fail("Two RGBA instances with different ALPHA parameters returned the same hash code"); + assertNotEquals(rgba1.hashCode(), new RGBA(r, g, b, different).hashCode(), + "Two RGBA instances with different ALPHA parameters returned the same hash code"); } -} -@Test -public void test_toString() { - RGBA rgba = new RGBA(0, 100, 200, 255); + @Test + public void test_toString() { + RGBA rgba = new RGBA(0, 100, 200, 255); - String s = rgba.toString(); + String s = rgba.toString(); - if (s == null || s.length() == 0) { - fail("RGBA.toString returns a null or empty String"); + if (s == null || s.length() == 0) { + fail("RGBA.toString returns a null or empty String"); + } } } -}