|
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 import javax.microedition.location.*; |
|
18 |
|
19 /* |
|
20 * This suite of testcases tests that: |
|
21 * - AddressInfo object can be created and changed |
|
22 * - legal parameters are accepted |
|
23 * - illegal parameters are not accepted |
|
24 */ |
|
25 public class AddressInfoTest extends ViperUnitTest |
|
26 { |
|
27 private AddressInfo currentAddressInfo; |
|
28 |
|
29 public AddressInfoTest() |
|
30 { |
|
31 super("AddressInfoTest"); |
|
32 } |
|
33 |
|
34 protected void runTest() throws java.lang.Throwable |
|
35 { |
|
36 testConstructor(); |
|
37 testSetters(); |
|
38 testIllegalArgumentSet(); |
|
39 testIllegalArgumentGet(); |
|
40 } |
|
41 |
|
42 // Test that constructor works and that default values are correct. |
|
43 void testConstructor() |
|
44 { |
|
45 setCurrentTest("testConstructor()"); |
|
46 |
|
47 // Create a AddressInfo object with correct parameters and check that |
|
48 // the values are unchanged when read. |
|
49 AddressInfo addrInfo = new AddressInfo(); |
|
50 |
|
51 // Check the defaults |
|
52 assertTrue(addrInfo.getField(AddressInfo.EXTENSION) == null |
|
53 && addrInfo.getField(AddressInfo.STREET) == null |
|
54 && addrInfo.getField(AddressInfo.POSTAL_CODE) == null |
|
55 && addrInfo.getField(AddressInfo.CITY) == null |
|
56 && addrInfo.getField(AddressInfo.COUNTY) == null |
|
57 && addrInfo.getField(AddressInfo.DISTRICT) == null |
|
58 && addrInfo.getField(AddressInfo.STATE) == null |
|
59 && addrInfo.getField(AddressInfo.COUNTRY) == null |
|
60 && addrInfo.getField(AddressInfo.COUNTRY_CODE) == null |
|
61 && addrInfo.getField(AddressInfo.BUILDING_NAME) == null |
|
62 && addrInfo.getField(AddressInfo.BUILDING_FLOOR) == null |
|
63 && addrInfo.getField(AddressInfo.BUILDING_ROOM) == null |
|
64 && addrInfo.getField(AddressInfo.BUILDING_ZONE) == null |
|
65 && addrInfo.getField(AddressInfo.CROSSING1) == null |
|
66 && addrInfo.getField(AddressInfo.CROSSING2) == null |
|
67 && addrInfo.getField(AddressInfo.URL) == null |
|
68 && addrInfo.getField(AddressInfo.PHONE_NUMBER) == null, |
|
69 "Default AddressInfo values incorrect"); |
|
70 |
|
71 } |
|
72 |
|
73 // Test that all the setters work correctly. |
|
74 void testSetters() |
|
75 { |
|
76 setCurrentTest("testSetters()"); |
|
77 |
|
78 // List the new values |
|
79 String extension = "Flat 4"; |
|
80 String street = "11 Mount Avenue"; |
|
81 String city = "London"; |
|
82 String county = "Ealing"; |
|
83 String postal_code = "W5 1QB"; |
|
84 String state = "England"; |
|
85 String district = "Middlesex"; |
|
86 String country = "United Kingdom"; |
|
87 String country_code = "GB"; |
|
88 String building_name = "The Castle"; |
|
89 String building_floor = "3"; |
|
90 String building_room = "Front Room"; |
|
91 String building_zone = "Upstairs"; |
|
92 String crossing1 = "Mount Avenue"; |
|
93 String crossing2 = "Eaton Rise"; |
|
94 String url = "http://www.upmystreet.co.uk"; |
|
95 String phone_number = "+358401234567"; |
|
96 |
|
97 // Define a AddressInfo object with non-default parameters and check |
|
98 // that the values are unchanged when read. |
|
99 AddressInfo addrInfo = new AddressInfo(); |
|
100 addrInfo.setField(AddressInfo.EXTENSION, extension); |
|
101 addrInfo.setField(AddressInfo.STREET, street); |
|
102 addrInfo.setField(AddressInfo.POSTAL_CODE, postal_code); |
|
103 addrInfo.setField(AddressInfo.CITY, city); |
|
104 addrInfo.setField(AddressInfo.COUNTY, county); |
|
105 addrInfo.setField(AddressInfo.DISTRICT, district); |
|
106 addrInfo.setField(AddressInfo.STATE, state); |
|
107 addrInfo.setField(AddressInfo.COUNTRY, country); |
|
108 addrInfo.setField(AddressInfo.COUNTRY_CODE, country_code); |
|
109 addrInfo.setField(AddressInfo.BUILDING_NAME, building_name); |
|
110 addrInfo.setField(AddressInfo.BUILDING_FLOOR, building_floor); |
|
111 addrInfo.setField(AddressInfo.BUILDING_ROOM, building_room); |
|
112 addrInfo.setField(AddressInfo.BUILDING_ZONE, building_zone); |
|
113 addrInfo.setField(AddressInfo.CROSSING1, crossing1); |
|
114 addrInfo.setField(AddressInfo.CROSSING2, crossing2); |
|
115 addrInfo.setField(AddressInfo.URL, url); |
|
116 addrInfo.setField(AddressInfo.PHONE_NUMBER, phone_number); |
|
117 |
|
118 // Check that the retrieved values are the same as the input ones |
|
119 assertTrue( |
|
120 addrInfo.getField(AddressInfo.EXTENSION) == extension |
|
121 && addrInfo.getField(AddressInfo.STREET) == street |
|
122 && addrInfo.getField(AddressInfo.POSTAL_CODE) == postal_code |
|
123 && addrInfo.getField(AddressInfo.CITY) == city |
|
124 && addrInfo.getField(AddressInfo.COUNTY) == county |
|
125 && addrInfo.getField(AddressInfo.DISTRICT) == district |
|
126 && addrInfo.getField(AddressInfo.STATE) == state |
|
127 && addrInfo.getField(AddressInfo.COUNTRY) == country |
|
128 && addrInfo.getField(AddressInfo.COUNTRY_CODE) == country_code |
|
129 && addrInfo.getField(AddressInfo.BUILDING_NAME) == building_name |
|
130 && addrInfo.getField(AddressInfo.BUILDING_FLOOR) == building_floor |
|
131 && addrInfo.getField(AddressInfo.BUILDING_ROOM) == building_room |
|
132 && addrInfo.getField(AddressInfo.BUILDING_ZONE) == building_zone |
|
133 && addrInfo.getField(AddressInfo.CROSSING1) == crossing1 |
|
134 && addrInfo.getField(AddressInfo.CROSSING2) == crossing2 |
|
135 && addrInfo.getField(AddressInfo.URL) == url |
|
136 && addrInfo.getField(AddressInfo.PHONE_NUMBER) == phone_number, |
|
137 "Retrieved AddressInfo values different from input"); |
|
138 |
|
139 } |
|
140 |
|
141 // Test that an exception is thrown if the field used in setter is |
|
142 // undefined. |
|
143 void testIllegalArgumentSet() |
|
144 { |
|
145 setCurrentTest("testIllegalArgumentSet()"); |
|
146 |
|
147 AddressInfo addrInfo = new AddressInfo(); |
|
148 |
|
149 // List the illegal field and value to set |
|
150 int illegalField = 77; |
|
151 String street = "11 Mount Avenue"; |
|
152 |
|
153 try |
|
154 { |
|
155 addrInfo.setField(illegalField, street); |
|
156 |
|
157 // If this point is reached, something is wrong |
|
158 assertTrue(false, "No exception thrown when illegal field used"); |
|
159 |
|
160 } |
|
161 catch (IllegalArgumentException iae) |
|
162 { |
|
163 // Exception was thrown correctly |
|
164 } |
|
165 } |
|
166 |
|
167 // Test that an exception is thrown if the requested field is undefined. |
|
168 void testIllegalArgumentGet() |
|
169 { |
|
170 setCurrentTest("testIllegalArgumentGet()"); |
|
171 |
|
172 AddressInfo addrInfo = new AddressInfo(); |
|
173 |
|
174 int illegalField = 77; |
|
175 |
|
176 try |
|
177 { |
|
178 addrInfo.getField(illegalField); |
|
179 |
|
180 // If this point is reached, something is wrong |
|
181 assertTrue(false, "No exception thrown when illegal field used"); |
|
182 |
|
183 } |
|
184 catch (IllegalArgumentException iae) |
|
185 { |
|
186 // Exception was thrown correctly |
|
187 } |
|
188 } |
|
189 } |