|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.mj.test.lapi; |
|
18 |
|
19 import j2meunit.framework.*; |
|
20 import javax.microedition.location.*; |
|
21 |
|
22 /** |
|
23 * <b>TEST CASE SPECIFICATION</b> |
|
24 * |
|
25 * This suite of testcases tests that: - AddressInfo object can be created and |
|
26 * changed - legal parameters are accepted - illegal parameters are not accepted |
|
27 * |
|
28 */ |
|
29 |
|
30 public class AddressInfoTest extends TestCase |
|
31 { |
|
32 private AddressInfo currentAddressInfo; |
|
33 |
|
34 public AddressInfoTest() |
|
35 { |
|
36 } |
|
37 |
|
38 public AddressInfoTest(String sTestName, TestMethod rTestMethod) |
|
39 { |
|
40 super(sTestName, rTestMethod); |
|
41 } |
|
42 |
|
43 /*************************************************************************** |
|
44 * Creates the test suite. You need to add a new aSuite.addTest antry for |
|
45 * any new test methods, otherwise they won't be run. |
|
46 */ |
|
47 public Test suite() |
|
48 { |
|
49 TestSuite aSuite = new TestSuite(); |
|
50 |
|
51 aSuite.addTest(new AddressInfoTest("testConstructor", new TestMethod() |
|
52 { |
|
53 public void run(TestCase tc) |
|
54 { |
|
55 ((AddressInfoTest) tc).testConstructor(); |
|
56 } |
|
57 })); |
|
58 |
|
59 aSuite.addTest(new AddressInfoTest("testSetters", new TestMethod() |
|
60 { |
|
61 public void run(TestCase tc) |
|
62 { |
|
63 ((AddressInfoTest) tc).testSetters(); |
|
64 } |
|
65 })); |
|
66 |
|
67 aSuite.addTest(new AddressInfoTest("testIllegalArgumentSet", |
|
68 new TestMethod() |
|
69 { |
|
70 public void run(TestCase tc) |
|
71 { |
|
72 ((AddressInfoTest) tc).testIllegalArgumentSet(); |
|
73 } |
|
74 })); |
|
75 |
|
76 aSuite.addTest(new AddressInfoTest("testIllegalArgumentGet", |
|
77 new TestMethod() |
|
78 { |
|
79 public void run(TestCase tc) |
|
80 { |
|
81 ((AddressInfoTest) tc).testIllegalArgumentGet(); |
|
82 } |
|
83 })); |
|
84 |
|
85 return aSuite; |
|
86 |
|
87 } |
|
88 |
|
89 // Test that constructor works and that default values are correct. |
|
90 public void testConstructor() |
|
91 { |
|
92 // Create a AddressInfo object with correct parameters and check that |
|
93 // the values are unchanged when read. |
|
94 AddressInfo addrInfo = new AddressInfo(); |
|
95 |
|
96 // Check the defaults |
|
97 assertTrue("Default AddressInfo values incorrect", addrInfo |
|
98 .getField(AddressInfo.EXTENSION) == null |
|
99 && addrInfo.getField(AddressInfo.STREET) == null |
|
100 && addrInfo.getField(AddressInfo.POSTAL_CODE) == null |
|
101 && addrInfo.getField(AddressInfo.CITY) == null |
|
102 && addrInfo.getField(AddressInfo.COUNTY) == null |
|
103 && addrInfo.getField(AddressInfo.DISTRICT) == null |
|
104 && addrInfo.getField(AddressInfo.STATE) == null |
|
105 && addrInfo.getField(AddressInfo.COUNTRY) == null |
|
106 && addrInfo.getField(AddressInfo.COUNTRY_CODE) == null |
|
107 && addrInfo.getField(AddressInfo.BUILDING_NAME) == null |
|
108 && addrInfo.getField(AddressInfo.BUILDING_FLOOR) == null |
|
109 && addrInfo.getField(AddressInfo.BUILDING_ROOM) == null |
|
110 && addrInfo.getField(AddressInfo.BUILDING_ZONE) == null |
|
111 && addrInfo.getField(AddressInfo.CROSSING1) == null |
|
112 && addrInfo.getField(AddressInfo.CROSSING2) == null |
|
113 && addrInfo.getField(AddressInfo.URL) == null |
|
114 && addrInfo.getField(AddressInfo.PHONE_NUMBER) == null); |
|
115 } |
|
116 |
|
117 // Test that all the setters work correctly. |
|
118 public void testSetters() |
|
119 { |
|
120 |
|
121 // List the new values |
|
122 String extension = "Flat 4"; |
|
123 String street = "11 Mount Avenue"; |
|
124 String city = "London"; |
|
125 String county = "Ealing"; |
|
126 String postal_code = "W5 1QB"; |
|
127 String state = "England"; |
|
128 String district = "Middlesex"; |
|
129 String country = "United Kingdom"; |
|
130 String country_code = "GB"; |
|
131 String building_name = "The Castle"; |
|
132 String building_floor = "3"; |
|
133 String building_room = "Front Room"; |
|
134 String building_zone = "Upstairs"; |
|
135 String crossing1 = "Mount Avenue"; |
|
136 String crossing2 = "Eaton Rise"; |
|
137 String url = "http://www.upmystreet.co.uk"; |
|
138 String phone_number = "+358401234567"; |
|
139 |
|
140 // Define a AddressInfo object with non-default parameters and check |
|
141 // that the values are unchanged when read. |
|
142 AddressInfo addrInfo = new AddressInfo(); |
|
143 addrInfo.setField(AddressInfo.EXTENSION, extension); |
|
144 addrInfo.setField(AddressInfo.STREET, street); |
|
145 addrInfo.setField(AddressInfo.POSTAL_CODE, postal_code); |
|
146 addrInfo.setField(AddressInfo.CITY, city); |
|
147 addrInfo.setField(AddressInfo.COUNTY, county); |
|
148 addrInfo.setField(AddressInfo.DISTRICT, district); |
|
149 addrInfo.setField(AddressInfo.STATE, state); |
|
150 addrInfo.setField(AddressInfo.COUNTRY, country); |
|
151 addrInfo.setField(AddressInfo.COUNTRY_CODE, country_code); |
|
152 addrInfo.setField(AddressInfo.BUILDING_NAME, building_name); |
|
153 addrInfo.setField(AddressInfo.BUILDING_FLOOR, building_floor); |
|
154 addrInfo.setField(AddressInfo.BUILDING_ROOM, building_room); |
|
155 addrInfo.setField(AddressInfo.BUILDING_ZONE, building_zone); |
|
156 addrInfo.setField(AddressInfo.CROSSING1, crossing1); |
|
157 addrInfo.setField(AddressInfo.CROSSING2, crossing2); |
|
158 addrInfo.setField(AddressInfo.URL, url); |
|
159 addrInfo.setField(AddressInfo.PHONE_NUMBER, phone_number); |
|
160 |
|
161 // Check that the retrieved values are the same as the input ones |
|
162 assertTrue( |
|
163 "Retrieved AddressInfo values different from input", |
|
164 addrInfo.getField(AddressInfo.EXTENSION) == extension |
|
165 && addrInfo.getField(AddressInfo.STREET) == street |
|
166 && addrInfo.getField(AddressInfo.POSTAL_CODE) == postal_code |
|
167 && addrInfo.getField(AddressInfo.CITY) == city |
|
168 && addrInfo.getField(AddressInfo.COUNTY) == county |
|
169 && addrInfo.getField(AddressInfo.DISTRICT) == district |
|
170 && addrInfo.getField(AddressInfo.STATE) == state |
|
171 && addrInfo.getField(AddressInfo.COUNTRY) == country |
|
172 && addrInfo.getField(AddressInfo.COUNTRY_CODE) == country_code |
|
173 && addrInfo.getField(AddressInfo.BUILDING_NAME) == building_name |
|
174 && addrInfo.getField(AddressInfo.BUILDING_FLOOR) == building_floor |
|
175 && addrInfo.getField(AddressInfo.BUILDING_ROOM) == building_room |
|
176 && addrInfo.getField(AddressInfo.BUILDING_ZONE) == building_zone |
|
177 && addrInfo.getField(AddressInfo.CROSSING1) == crossing1 |
|
178 && addrInfo.getField(AddressInfo.CROSSING2) == crossing2 |
|
179 && addrInfo.getField(AddressInfo.URL) == url |
|
180 && addrInfo.getField(AddressInfo.PHONE_NUMBER) == phone_number); |
|
181 } |
|
182 |
|
183 // Test that an exception is thrown if the field used in setter is |
|
184 // undefined. |
|
185 public void testIllegalArgumentSet() |
|
186 { |
|
187 AddressInfo addrInfo = new AddressInfo(); |
|
188 |
|
189 // List the illegal field and value to set |
|
190 int illegalField = 77; |
|
191 String street = "11 Mount Avenue"; |
|
192 |
|
193 try |
|
194 { |
|
195 addrInfo.setField(illegalField, street); |
|
196 |
|
197 // If this point is reached, something is wrong |
|
198 assertTrue("No exception thrown when illegal field used", false); |
|
199 } |
|
200 catch (IllegalArgumentException iae) |
|
201 { |
|
202 // Exception was thrown correctly |
|
203 } |
|
204 } |
|
205 |
|
206 // Test that an exception is thrown if the requested field is undefined. |
|
207 public void testIllegalArgumentGet() |
|
208 { |
|
209 AddressInfo addrInfo = new AddressInfo(); |
|
210 |
|
211 int illegalField = 77; |
|
212 |
|
213 try |
|
214 { |
|
215 addrInfo.getField(illegalField); |
|
216 |
|
217 // If this point is reached, something is wrong |
|
218 assertTrue("No exception thrown when illegal field used", false); |
|
219 |
|
220 } |
|
221 catch (IllegalArgumentException iae) |
|
222 { |
|
223 // Exception was thrown correctly |
|
224 } |
|
225 } |
|
226 } |