|
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 */ |
|
26 |
|
27 public class LandmarkTest extends TestCase |
|
28 { |
|
29 |
|
30 public LandmarkTest() |
|
31 { |
|
32 } |
|
33 |
|
34 public LandmarkTest(String sTestName, TestMethod rTestMethod) |
|
35 { |
|
36 super(sTestName, rTestMethod); |
|
37 } |
|
38 |
|
39 /*************************************************************************** |
|
40 * Creates the test suite. You need to add a new aSuite.addTest antry for |
|
41 * any new test methods, otherwise they won't be run. |
|
42 */ |
|
43 public Test suite() |
|
44 { |
|
45 TestSuite aSuite = new TestSuite(); |
|
46 |
|
47 aSuite.addTest(new LandmarkTest("testBadConstructor", new TestMethod() |
|
48 { |
|
49 public void run(TestCase tc) |
|
50 { |
|
51 ((LandmarkTest) tc).testBadConstructor(); |
|
52 } |
|
53 })); |
|
54 |
|
55 aSuite.addTest(new LandmarkTest("testConstructor", new TestMethod() |
|
56 { |
|
57 public void run(TestCase tc) |
|
58 { |
|
59 ((LandmarkTest) tc).testConstructor(); |
|
60 } |
|
61 })); |
|
62 |
|
63 aSuite.addTest(new LandmarkTest("testBadSetter", new TestMethod() |
|
64 { |
|
65 public void run(TestCase tc) |
|
66 { |
|
67 ((LandmarkTest) tc).testBadSetter(); |
|
68 } |
|
69 })); |
|
70 |
|
71 aSuite.addTest(new LandmarkTest("testSetters", new TestMethod() |
|
72 { |
|
73 public void run(TestCase tc) |
|
74 { |
|
75 ((LandmarkTest) tc).testSetters(); |
|
76 } |
|
77 })); |
|
78 |
|
79 return aSuite; |
|
80 |
|
81 } |
|
82 |
|
83 private void assertContinue(String aReason, boolean aCond) |
|
84 { |
|
85 if (!aCond) |
|
86 assertTrue(aReason, false); |
|
87 } |
|
88 |
|
89 public void testBadConstructor() |
|
90 { |
|
91 |
|
92 try |
|
93 { |
|
94 // Trying to create a landmark where name is null |
|
95 Landmark lm = new Landmark(null, null, null, null); |
|
96 assertContinue("No exception thrown for constructor values", false); |
|
97 } |
|
98 catch (NullPointerException npe) |
|
99 { |
|
100 // Exception thrown correctly |
|
101 } |
|
102 |
|
103 assertTrue("", true); |
|
104 } |
|
105 |
|
106 public void testConstructor() |
|
107 { |
|
108 |
|
109 // Create a Landmark object with correct parameters and check that |
|
110 // the values are unchanged when read. |
|
111 String name = "Office"; |
|
112 Landmark lm1 = new Landmark(name, null, null, null); |
|
113 |
|
114 String description = "Where I work"; |
|
115 Landmark lm2 = new Landmark(name, description, null, null); |
|
116 |
|
117 float hacc = 50.0f; |
|
118 float vacc = 80.0f; |
|
119 QualifiedCoordinates coords = new QualifiedCoordinates(57.0f, 17.0f, |
|
120 34.0f, hacc, vacc); |
|
121 |
|
122 Landmark lm3 = new Landmark(name, null, coords, null); |
|
123 Landmark lm4 = new Landmark(name, description, coords, null); |
|
124 |
|
125 AddressInfo address = new AddressInfo(); |
|
126 |
|
127 Landmark lm5 = new Landmark(name, null, null, address); |
|
128 Landmark lm6 = new Landmark(name, description, null, address); |
|
129 Landmark lm7 = new Landmark(name, null, coords, address); |
|
130 |
|
131 Landmark lm = new Landmark(name, description, coords, address); |
|
132 |
|
133 // Check the Landmark's values |
|
134 assertContinue("Retrieved Landmark values incorrect", |
|
135 lm.getName() == name && lm.getDescription() == description |
|
136 && lm.getQualifiedCoordinates() == coords |
|
137 && lm.getAddressInfo() == address); |
|
138 |
|
139 assertTrue("", true); |
|
140 } |
|
141 |
|
142 public void testBadSetter() |
|
143 { |
|
144 String name = "Office"; |
|
145 |
|
146 // Create a new unmodified Landmark object |
|
147 Landmark lm = new Landmark(name, null, null, null); |
|
148 |
|
149 try |
|
150 { |
|
151 lm.setName(null); |
|
152 assertContinue("No exception thrown for bad argument", false); |
|
153 } |
|
154 catch (NullPointerException npe) |
|
155 { |
|
156 // Exception thrown correctly |
|
157 } |
|
158 assertTrue("", true); |
|
159 } |
|
160 |
|
161 public void testSetters() |
|
162 { |
|
163 |
|
164 String name = "Office"; |
|
165 |
|
166 // Create a new unmodified Landmark object |
|
167 Landmark lm = new Landmark(name, null, null, null); |
|
168 |
|
169 String newName = "Home"; |
|
170 String description = "Where I live"; |
|
171 QualifiedCoordinates coords = new QualifiedCoordinates(57.0f, 17.0f, |
|
172 34.0f, 20.0f, 20.0f); |
|
173 AddressInfo address = new AddressInfo(); |
|
174 |
|
175 lm.setName(newName); |
|
176 lm.setDescription(description); |
|
177 lm.setQualifiedCoordinates(coords); |
|
178 lm.setAddressInfo(address); |
|
179 |
|
180 // Check the Landmark's values |
|
181 assertContinue("Retrieved Landmark values incorrect", |
|
182 lm.getName() == newName && lm.getDescription() == description |
|
183 && lm.getQualifiedCoordinates() == coords |
|
184 && lm.getAddressInfo() == address); |
|
185 |
|
186 assertTrue("", true); |
|
187 } |
|
188 } |