OSDN Git Service

e8159ba6caed7f04300d1d998e800d50f7c14aed
[android-x86/packages-apps-Calendar.git] / tests / src / com / android / calendar / UtilsTests.java
1 package com.android.calendar;
2
3 import android.database.Cursor;
4 import android.database.MatrixCursor;
5 import android.test.suitebuilder.annotation.SmallTest;
6
7 import junit.framework.TestCase;
8
9 import java.util.HashMap;
10 import java.util.Map;
11
12 /**
13  * Test class for verifying helper functions in Calendar's Utils
14  *
15  * You can run these tests with the following command:
16  * "adb shell am instrument -w -e class com.android.calendar.UtilsTests
17  *          com.android.calendar.tests/android.test.InstrumentationTestRunner"
18  */
19 public class UtilsTests extends TestCase {
20     HashMap<String, Boolean> mIsDuplicateName;
21     HashMap<String, Boolean> mIsDuplicateNameExpected;
22     MatrixCursor mDuplicateNameCursor;
23
24     private static final int NAME_COLUMN = 0;
25     private static final String[] DUPLICATE_NAME_COLUMNS = new String[] { "name" };
26     private static final String[][] DUPLICATE_NAMES = new String[][] {
27         {"Pepper Pots"},
28         {"Green Goblin"},
29         {"Pepper Pots"},
30         {"Peter Parker"},
31         {"Silver Surfer"},
32         {"John Jameson"},
33         {"John Jameson"},
34         {"Pepper Pots"}
35     };
36
37     @Override
38     public void setUp() {
39         mIsDuplicateName = new HashMap<String, Boolean> ();
40         mDuplicateNameCursor = new MatrixCursor(DUPLICATE_NAME_COLUMNS);
41         for (int i = 0; i < DUPLICATE_NAMES.length; i++) {
42             mDuplicateNameCursor.addRow(DUPLICATE_NAMES[i]);
43         }
44
45         mIsDuplicateNameExpected = new HashMap<String, Boolean> ();
46         mIsDuplicateNameExpected.put("Pepper Pots", true);
47         mIsDuplicateNameExpected.put("Green Goblin", false);
48         mIsDuplicateNameExpected.put("Peter Parker", false);
49         mIsDuplicateNameExpected.put("Silver Surfer", false);
50         mIsDuplicateNameExpected.put("John Jameson", true);
51     }
52
53     @Override
54     public void tearDown() {
55         mDuplicateNameCursor.close();
56     }
57
58     @SmallTest
59     public void testCheckForDuplicateNames() {
60         Utils.checkForDuplicateNames(mIsDuplicateName, mDuplicateNameCursor, NAME_COLUMN);
61         assertEquals(mIsDuplicateName, mIsDuplicateNameExpected);
62     }
63 }