2 * Copyright (C) 2010 The Android Open Source Project
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.calendar;
19 import android.database.Cursor;
20 import android.database.MatrixCursor;
21 import android.test.suitebuilder.annotation.SmallTest;
23 import junit.framework.TestCase;
25 import java.util.HashMap;
29 * Test class for verifying helper functions in Calendar's Utils
31 * You can run these tests with the following command:
32 * "adb shell am instrument -w -e class com.android.calendar.UtilsTests
33 * com.android.calendar.tests/android.test.InstrumentationTestRunner"
35 public class UtilsTests extends TestCase {
36 HashMap<String, Boolean> mIsDuplicateName;
37 HashMap<String, Boolean> mIsDuplicateNameExpected;
38 MatrixCursor mDuplicateNameCursor;
40 private static final int NAME_COLUMN = 0;
41 private static final String[] DUPLICATE_NAME_COLUMNS = new String[] { "name" };
42 private static final String[][] DUPLICATE_NAMES = new String[][] {
55 mIsDuplicateName = new HashMap<String, Boolean> ();
56 mDuplicateNameCursor = new MatrixCursor(DUPLICATE_NAME_COLUMNS);
57 for (int i = 0; i < DUPLICATE_NAMES.length; i++) {
58 mDuplicateNameCursor.addRow(DUPLICATE_NAMES[i]);
61 mIsDuplicateNameExpected = new HashMap<String, Boolean> ();
62 mIsDuplicateNameExpected.put("Pepper Pots", true);
63 mIsDuplicateNameExpected.put("Green Goblin", false);
64 mIsDuplicateNameExpected.put("Peter Parker", false);
65 mIsDuplicateNameExpected.put("Silver Surfer", false);
66 mIsDuplicateNameExpected.put("John Jameson", true);
70 public void tearDown() {
71 mDuplicateNameCursor.close();
75 public void testCheckForDuplicateNames() {
76 Utils.checkForDuplicateNames(mIsDuplicateName, mDuplicateNameCursor, NAME_COLUMN);
77 assertEquals(mIsDuplicateName, mIsDuplicateNameExpected);