29 * Short description of the module test: |
29 * Short description of the module test: |
30 * <li>Collection of tests to test Spacer's API functionality.<br> |
30 * <li>Collection of tests to test Spacer's API functionality.<br> |
31 * |
31 * |
32 * @created 1.8.2008 |
32 * @created 1.8.2008 |
33 */ |
33 */ |
34 public class SpacerTest extends SWTTestCase { |
34 public class SpacerTest extends SWTTestCase |
|
35 { |
35 |
36 |
36 private static final int WIDTH = 100; |
37 private static final int WIDTH = 100; |
37 private static final int HEIGHT = 100; |
38 private static final int HEIGHT = 100; |
38 |
39 |
39 /** |
40 /** |
40 * Constructor. |
41 * Constructor. |
41 */ |
42 */ |
42 public SpacerTest() { |
43 public SpacerTest() |
|
44 { |
43 } |
45 } |
44 |
46 |
45 /** |
47 /** |
46 * Constructor. |
48 * Constructor. |
47 * |
49 * |
48 * @param sTestName name of the test |
50 * @param sTestName name of the test |
49 * @param rTestMethod TestMethod used |
51 * @param rTestMethod TestMethod used |
50 */ |
52 */ |
51 public SpacerTest(String sTestName) { |
53 public SpacerTest(String sTestName) |
|
54 { |
52 super(sTestName); |
55 super(sTestName); |
53 } |
56 } |
54 |
57 |
55 /** |
58 /** |
56 * Any pre-test setup can be done here |
59 * Any pre-test setup can be done here |
57 */ |
60 */ |
58 protected void setUp() throws Exception { |
61 protected void setUp() throws Exception |
|
62 { |
59 } |
63 } |
60 |
64 |
61 /** |
65 /** |
62 * To create the test suite. You need to add a new aSuite.addTest entry for |
66 * To create the test suite. You need to add a new aSuite.addTest entry for |
63 * any new test methods. |
67 * any new test methods. |
64 * |
68 * |
65 * @return New TestSuite. |
69 * @return New TestSuite. |
66 */ |
70 */ |
67 public static Test suite() { |
71 public static Test suite() |
68 TestSuite suite = new TestSuite(); |
72 { |
|
73 TestSuite suite = new TestSuite(); |
69 |
74 |
70 java.util.Vector methodNames; |
75 java.util.Vector methodNames; |
71 java.util.Enumeration e; |
76 java.util.Enumeration e; |
72 |
77 |
73 // Add widget tests |
78 // Add widget tests |
74 methodNames = SpacerTest.methodNames(); |
79 methodNames = SpacerTest.methodNames(); |
75 e = methodNames.elements(); |
80 e = methodNames.elements(); |
76 while (e.hasMoreElements()) { |
81 while(e.hasMoreElements()) |
77 suite.addTest(new SpacerTest((String)e.nextElement())); |
82 { |
78 } |
83 suite.addTest(new SpacerTest((String)e.nextElement())); |
|
84 } |
79 |
85 |
80 return suite; |
86 return suite; |
81 } |
87 } |
82 |
88 |
83 public static java.util.Vector methodNames() { |
89 public static java.util.Vector methodNames() |
|
90 { |
84 java.util.Vector methodNames = new java.util.Vector(); |
91 java.util.Vector methodNames = new java.util.Vector(); |
85 methodNames.addElement("testAccessors"); |
92 methodNames.addElement("testAccessors"); |
86 return methodNames; |
93 return methodNames; |
87 } |
94 } |
88 |
95 |
89 protected void runTest() throws Throwable { |
96 protected void runTest() throws Throwable |
90 if (getName().equals("testAccessors")) testAccessors(); |
97 { |
|
98 if(getName().equals("testAccessors")) testAccessors(); |
91 else super.runTest(); |
99 else super.runTest(); |
92 } |
100 } |
93 |
101 |
94 /** |
102 /** |
95 * Test method. |
103 * Test method. |
96 */ |
104 */ |
97 public void testAccessors() { |
105 public void testAccessors() |
|
106 { |
98 Spacer spacer; |
107 Spacer spacer; |
99 |
108 |
100 try { |
109 try |
|
110 { |
101 spacer = new Spacer(-1, -1); |
111 spacer = new Spacer(-1, -1); |
102 fail("no IllegalArgumentException is thrown when parameters are" |
112 fail("no IllegalArgumentException is thrown when parameters are" |
103 + " incorrect in constructor"); |
113 + " incorrect in constructor"); |
104 } |
114 } |
105 catch (IllegalArgumentException e) { |
115 catch(IllegalArgumentException e) |
|
116 { |
106 //OK |
117 //OK |
107 } |
118 } |
108 spacer = new Spacer(WIDTH, HEIGHT); |
119 spacer = new Spacer(WIDTH, HEIGHT); |
109 Command ok = new Command("Ok", "", Command.ITEM, 0); |
120 Command ok = new Command("Ok", "", Command.ITEM, 0); |
110 try { |
121 try |
|
122 { |
111 spacer.addCommand(ok); |
123 spacer.addCommand(ok); |
112 fail("no IllegalStateException is thrown when adding command"); |
124 fail("no IllegalStateException is thrown when adding command"); |
113 } |
125 } |
114 catch (IllegalStateException e) { |
126 catch(IllegalStateException e) |
|
127 { |
115 //OK |
128 //OK |
116 } |
129 } |
117 try { |
130 try |
|
131 { |
118 spacer.setDefaultCommand(ok); |
132 spacer.setDefaultCommand(ok); |
119 fail("no IllegalStateException is thrown when setting default " |
133 fail("no IllegalStateException is thrown when setting default " |
120 + " command"); |
134 + " command"); |
121 } |
135 } |
122 catch (IllegalStateException e) { |
136 catch(IllegalStateException e) |
|
137 { |
123 //OK |
138 //OK |
124 } |
139 } |
125 try { |
140 try |
|
141 { |
126 spacer.setLabel("some label"); |
142 spacer.setLabel("some label"); |
127 fail("no IllegalStateException is thrown when setting label"); |
143 fail("no IllegalStateException is thrown when setting label"); |
128 } |
144 } |
129 catch (IllegalStateException e) { |
145 catch(IllegalStateException e) |
|
146 { |
130 //OK |
147 //OK |
131 } |
148 } |
132 try { |
149 try |
|
150 { |
133 spacer.setMinimumSize(-1, -1); |
151 spacer.setMinimumSize(-1, -1); |
134 fail("no IllegalArgumentException is thrown when setting minimum " |
152 fail("no IllegalArgumentException is thrown when setting minimum " |
135 + "size less then 0"); |
153 + "size less then 0"); |
136 } |
154 } |
137 catch (IllegalArgumentException e) { |
155 catch(IllegalArgumentException e) |
|
156 { |
138 //OK |
157 //OK |
139 } |
158 } |
140 } |
159 } |
141 } |
160 } |