01: package de.java2html.util.test;
02:
03: import de.java2html.util.RGB;
04: import junit.framework.TestCase;
05:
06: /**
07: * @author Markus Gebhard
08: */
09: 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,
20: 0);
21: assertConstructorArgumentsThrowsIllegalArgumentException(0, -1,
22: 0);
23: assertConstructorArgumentsThrowsIllegalArgumentException(0, 0,
24: -1);
25: assertConstructorArgumentsThrowsIllegalArgumentException(256,
26: 0, 0);
27: assertConstructorArgumentsThrowsIllegalArgumentException(0,
28: 256, 0);
29: assertConstructorArgumentsThrowsIllegalArgumentException(0, 0,
30: 256);
31: }
32:
33: private void assertConstructorArgumentsThrowsIllegalArgumentException(
34: int red, int green, int blue) {
35: try {
36: new RGB(red, green, blue);
37: fail();
38: } catch (IllegalArgumentException expected) {
39: //expected
40: }
41: }
42:
43: public void testSameEquals() {
44: RGB rgb = new RGB(1, 2, 3);
45: assertEquals(rgb, rgb);
46: }
47:
48: public void testEqualEquals() {
49: assertEquals(new RGB(1, 2, 3), new RGB(1, 2, 3));
50: }
51:
52: public void testEqualHasEqualHashCode() {
53: assertEquals(new RGB(1, 2, 3).hashCode(), new RGB(1, 2, 3)
54: .hashCode());
55: }
56:
57: public void testDifferentNotEquals() {
58: assertFalse(new RGB(0, 0, 0).equals(new RGB(1, 0, 0)));
59: assertFalse(new RGB(0, 0, 0).equals(new RGB(0, 1, 0)));
60: assertFalse(new RGB(0, 0, 0).equals(new RGB(0, 0, 1)));
61: }
62: }
|