1 package de.java2html.util.test; 2 3 import de.java2html.util.RGB; 4 import junit.framework.TestCase; 5 6 9 public class RGBTest extends TestCase { 10 11 public void testCreate() { 12 RGB rgb = new RGB(1, 2, 3); 13 assertEquals(1, rgb.getRed()); 14 assertEquals(2, rgb.getGreen()); 15 assertEquals(3, rgb.getBlue()); 16 } 17 18 public void testIllegalArgumentsInConstructor() { 19 assertConstructorArgumentsThrowsIllegalArgumentException(-1, 0, 0); 20 assertConstructorArgumentsThrowsIllegalArgumentException(0, -1, 0); 21 assertConstructorArgumentsThrowsIllegalArgumentException(0, 0, -1); 22 assertConstructorArgumentsThrowsIllegalArgumentException(256, 0, 0); 23 assertConstructorArgumentsThrowsIllegalArgumentException(0, 256, 0); 24 assertConstructorArgumentsThrowsIllegalArgumentException(0, 0, 256); 25 } 26 27 private void assertConstructorArgumentsThrowsIllegalArgumentException(int red, int green, int blue) { 28 try { 29 new RGB(red, green, blue); 30 fail(); 31 } 32 catch (IllegalArgumentException expected) { 33 } 35 } 36 37 public void testSameEquals() { 38 RGB rgb = new RGB(1, 2, 3); 39 assertEquals(rgb, rgb); 40 } 41 42 public void testEqualEquals() { 43 assertEquals(new RGB(1, 2, 3), new RGB(1, 2, 3)); 44 } 45 46 public void testEqualHasEqualHashCode() { 47 assertEquals(new RGB(1, 2, 3).hashCode(), new RGB(1, 2, 3).hashCode()); 48 } 49 50 public void testDifferentNotEquals() { 51 assertFalse(new RGB(0, 0, 0).equals(new RGB(1, 0, 0))); 52 assertFalse(new RGB(0, 0, 0).equals(new RGB(0, 1, 0))); 53 assertFalse(new RGB(0, 0, 0).equals(new RGB(0, 0, 1))); 54 } 55 } | Popular Tags |