1 package com.android.contacts.interactions;
2 
3 import android.content.ContentValues;
4 import android.provider.CallLog.Calls;
5 import android.test.AndroidTestCase;
6 
7 import java.util.ArrayList;
8 import java.util.List;
9 
10 /**
11  * Tests {@link CallLogInteractionsLoader}
12  */
13 public class CallLogInteractionsLoaderTest extends AndroidTestCase {
14 
testCallLogInteractions_pruneDuplicates_containsDuplicates()15     public void testCallLogInteractions_pruneDuplicates_containsDuplicates() {
16         List<ContactInteraction> interactions = new ArrayList<>();
17         int maxToRetrieve = 5;
18 
19         ContentValues interactionOneValues = new ContentValues();
20         interactionOneValues.put(Calls.DATE, 1L);
21         interactions.add(new CallLogInteraction(interactionOneValues));
22 
23         ContentValues interactionTwoValues = new ContentValues();
24         interactionTwoValues.put(Calls.DATE, 1L);
25         interactions.add(new CallLogInteraction(interactionTwoValues));
26 
27         interactions = CallLogInteractionsLoader.pruneDuplicateCallLogInteractions(interactions,
28                 maxToRetrieve);
29         assertEquals(1, interactions.size());
30     }
31 
testCallLogInteractions_pruneDuplicates_containsNoDuplicates()32     public void testCallLogInteractions_pruneDuplicates_containsNoDuplicates() {
33         List<ContactInteraction> interactions = new ArrayList<>();
34         int maxToRetrieve = 5;
35 
36         ContentValues interactionOneValues = new ContentValues();
37         interactionOneValues.put(Calls.DATE, 1L);
38         interactions.add(new CallLogInteraction(interactionOneValues));
39 
40         ContentValues interactionTwoValues = new ContentValues();
41         interactionTwoValues.put(Calls.DATE, 5L);
42         interactions.add(new CallLogInteraction(interactionTwoValues));
43 
44         interactions = CallLogInteractionsLoader.pruneDuplicateCallLogInteractions(interactions,
45                 maxToRetrieve);
46         assertEquals(2, interactions.size());
47     }
48 
testCallLogInteractions_maxToRetrieve()49     public void testCallLogInteractions_maxToRetrieve() {
50         List<ContactInteraction> interactions = new ArrayList<>();
51         int maxToRetrieve = 1;
52 
53         ContentValues interactionOneValues = new ContentValues();
54         interactionOneValues.put(Calls.DATE, 1L);
55         interactions.add(new CallLogInteraction(interactionOneValues));
56 
57         ContentValues interactionTwoValues = new ContentValues();
58         interactionTwoValues.put(Calls.DATE, 5L);
59         interactions.add(new CallLogInteraction(interactionTwoValues));
60 
61         interactions = CallLogInteractionsLoader.pruneDuplicateCallLogInteractions(interactions,
62                 maxToRetrieve);
63         assertEquals(1, interactions.size());
64     }
65 }
66