• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import java.util.HashMap;
4 import java.util.Map;
5 
6 import android.content.ContentProviderOperation;
7 import android.content.ContentProviderOperation.Builder;
8 import android.net.Uri;
9 
10 import com.xtremelabs.robolectric.Robolectric;
11 import com.xtremelabs.robolectric.internal.Implementation;
12 import com.xtremelabs.robolectric.internal.Implements;
13 
14 @Implements(ContentProviderOperation.class)
15 public class ShadowContentProviderOperation {
16     private final Map<String, Object> values = new HashMap<String, Object>();
17     private final Map<String, String[]> selections = new HashMap<String, String[]>();
18     private final Map<String, Integer> withValueBackReferences = new HashMap<String, Integer>();
19     private Uri uri;
20     private boolean isInsert;
21     private boolean isUpdate;
22     private boolean isDelete;
23 
24     @Implementation
newInsert(Uri uri)25     public static Builder newInsert(Uri uri) {
26         Builder builder = Robolectric.newInstanceOf(Builder.class);
27         ShadowContentProviderOperationBuilder shadowBuilder = Robolectric.shadowOf(builder);
28         shadowBuilder.setUri(uri);
29         shadowBuilder.setInsert(true);
30         return builder;
31     }
32 
33     @Implementation
newUpdate(Uri uri)34     public static Builder newUpdate(Uri uri) {
35         Builder builder = Robolectric.newInstanceOf(Builder.class);
36         ShadowContentProviderOperationBuilder shadowBuilder = Robolectric.shadowOf(builder);
37         shadowBuilder.setUri(uri);
38         shadowBuilder.setUpdate(true);
39         return builder;
40     }
41 
42     @Implementation
newDelete(Uri uri)43     public static Builder newDelete(Uri uri) {
44         Builder builder = Robolectric.newInstanceOf(Builder.class);
45         ShadowContentProviderOperationBuilder shadowBuilder = Robolectric.shadowOf(builder);
46         shadowBuilder.setUri(uri);
47         shadowBuilder.setDelete(true);
48         return builder;
49     }
50 
51     @Implementation
getUri()52     public Uri getUri() {
53         return uri;
54     }
55 
setUri(Uri uri)56     public void setUri(Uri uri) {
57         this.uri = uri;
58     }
59 
getValues()60     public Map<String, Object> getValues() {
61         return values;
62     }
63 
getSelections()64     public Map<String, String[]> getSelections() {
65         return selections;
66     }
67 
isInsert()68     public boolean isInsert() {
69         return isInsert;
70     }
71 
setInsert(boolean value)72     public void setInsert(boolean value) {
73         isInsert = value;
74     }
75 
isUpdate()76     public boolean isUpdate() {
77         return isUpdate;
78     }
79 
setUpdate(boolean value)80     public void setUpdate(boolean value) {
81         isUpdate = value;
82     }
83 
isDelete()84     public boolean isDelete() {
85         return isDelete;
86     }
87 
setDelete(boolean value)88     public void setDelete(boolean value) {
89         isDelete = value;
90     }
91 
setWithValueBackReference(String key, int previousResult)92     public void setWithValueBackReference(String key, int previousResult) {
93         withValueBackReferences.put(key, previousResult);
94     }
95 
getWithValueBackReference(String key)96     public int getWithValueBackReference(String key) {
97         return withValueBackReferences.get(key);
98     }
99 }
100