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;
22
23import java.io.File;
24
25public class SyncManagerTest extends AndroidTestCase {
26    private static class MyContext extends ContextWrapper {
27        public boolean isGetFileStreamPathCalled;
28
29        public MyContext(Context base) {
30            super(base);
31        }
32
33        @Override
34        public File getFileStreamPath(String name) {
35            isGetFileStreamPathCalled = true;
36            return super.getFileStreamPath(name);
37        }
38    }
39
40    public void testGetDeviceId() throws Exception {
41        final MyContext context = new MyContext(getContext());
42
43        final String id = SyncManager.getDeviceId(context);
44
45        // Consists of alpha-numeric
46        assertTrue(id.matches("^[a-zA-Z0-9]+$"));
47
48        // getDeviceId may have been called in other tests, so we don't check
49        // isGetFileStreamPathCalled here.
50
51        context.isGetFileStreamPathCalled = false;
52        final String cachedId = SyncManager.getDeviceId(context);
53
54        // Should be the same.
55        assertEquals(id, cachedId);
56        // Should be cached.  (If cached, this method won't be called.)
57        assertFalse(context.isGetFileStreamPathCalled);
58    }
59}
60