1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package com.android.exchange;
18
19import android.content.Context;
20import android.content.ContextWrapper;
21import android.test.AndroidTestCase;
22import android.test.suitebuilder.annotation.SmallTest;
23
24import java.io.File;
25@SmallTest
26public class ExchangeServiceTest extends AndroidTestCase {
27    private static class MyContext extends ContextWrapper {
28        public boolean isGetFileStreamPathCalled;
29
30        public MyContext(Context base) {
31            super(base);
32        }
33
34        @Override
35        public File getFileStreamPath(String name) {
36            isGetFileStreamPathCalled = true;
37            return super.getFileStreamPath(name);
38        }
39    }
40
41    public void testGetDeviceId() throws Exception {
42        final MyContext context = new MyContext(getContext());
43
44        final String id = ExchangeService.getDeviceId(context);
45
46        // Consists of alpha-numeric
47        assertTrue(id.matches("^[a-zA-Z0-9]+$"));
48
49        // getDeviceId may have been called in other tests, so we don't check
50        // isGetFileStreamPathCalled here.
51
52        context.isGetFileStreamPathCalled = false;
53        final String cachedId = ExchangeService.getDeviceId(context);
54
55        // Should be the same.
56        assertEquals(id, cachedId);
57        // Should be cached.  (If cached, this method won't be called.)
58        assertFalse(context.isGetFileStreamPathCalled);
59    }
60}
61