OSDN Git Service

b/2635283 UtilsTest.java was missing copyright notice.
[android-x86/packages-apps-Calendar.git] / tests / src / com / android / calendar / UtilsTests.java
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
17 package com.android.calendar;
18
19 import android.database.Cursor;
20 import android.database.MatrixCursor;
21 import android.test.suitebuilder.annotation.SmallTest;
22
23 import junit.framework.TestCase;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 /**
29  * Test class for verifying helper functions in Calendar's Utils
30  *
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"
34  */
35 public class UtilsTests extends TestCase {
36     HashMap<String, Boolean> mIsDuplicateName;
37     HashMap<String, Boolean> mIsDuplicateNameExpected;
38     MatrixCursor mDuplicateNameCursor;
39
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[][] {
43         {"Pepper Pots"},
44         {"Green Goblin"},
45         {"Pepper Pots"},
46         {"Peter Parker"},
47         {"Silver Surfer"},
48         {"John Jameson"},
49         {"John Jameson"},
50         {"Pepper Pots"}
51     };
52
53     @Override
54     public void setUp() {
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]);
59         }
60
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);
67     }
68
69     @Override
70     public void tearDown() {
71         mDuplicateNameCursor.close();
72     }
73
74     @SmallTest
75     public void testCheckForDuplicateNames() {
76         Utils.checkForDuplicateNames(mIsDuplicateName, mDuplicateNameCursor, NAME_COLUMN);
77         assertEquals(mIsDuplicateName, mIsDuplicateNameExpected);
78     }
79 }