2 * Copyright (C) 2010 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.i18n.addressinput;
19 import com.android.i18n.addressinput.testing.AsyncTestCase;
22 * Tests for the ClientData class, to ensure it uses the cache data to correctly fetch data from the
23 * server and recovers if no data is present.
25 public class ClientDataTest extends AsyncTestCase {
26 private ClientData client;
30 client = new ClientData(new CacheData());
33 public void testGet() {
34 AddressVerificationNodeData data = client.get("data");
38 public void testGet2() {
39 AddressVerificationNodeData data;
41 data = client.get("data");
44 data = client.get("data");
48 public void testPrefetchCountry() {
49 delayTestFinish(60000);
51 client.prefetchCountry("TW", new DataLoadListener() {
52 boolean beginCalled = false;
55 public void dataLoadingBegin() {
60 public void dataLoadingEnd() {
61 assertTrue("dataLoadingBegin should be called", beginCalled);
62 // Currently this test only tests that the execution doesn't crash and eventually
63 // terminates. TODO: Write test cases to verify that correct data is loaded.
69 public void testFetchDataWithBadServer() {
70 CacheData badCache = new CacheData();
71 badCache.setUrl("http://www.google.com");
72 ClientData badServerClient = new ClientData(badCache);
74 AddressVerificationNodeData data = badServerClient.get("data/US");
76 // No data was available on the server or in the cache - it should check
77 // that there is nothing in region data constants, and should return the
80 String unitedStatesFormatInfo = data.get(AddressDataKey.FMT);
81 assertEquals("%N%n%O%n%A%n%C %S %Z", unitedStatesFormatInfo);