1 package org.robolectric.shadows; 2 3 import android.content.ContentProviderOperation; 4 import android.content.ContentValues; 5 import java.util.Map; 6 import org.robolectric.annotation.HiddenApi; 7 import org.robolectric.annotation.Implementation; 8 import org.robolectric.annotation.Implements; 9 import org.robolectric.annotation.RealObject; 10 import org.robolectric.util.ReflectionHelpers; 11 12 @Implements(ContentProviderOperation.class) 13 public class ShadowContentProviderOperation { 14 public final static int TYPE_INSERT = 1; 15 public final static int TYPE_UPDATE = 2; 16 public final static int TYPE_DELETE = 3; 17 public final static int TYPE_ASSERT = 4; 18 19 @RealObject 20 private ContentProviderOperation realOperation; 21 22 @HiddenApi @Implementation getType()23 public int getType() { 24 return getFieldReflectively("mType", Integer.class); 25 } 26 getSelection()27 public String getSelection() { 28 return getFieldReflectively("mSelection", String.class); 29 } getSelectionArgs()30 public String[] getSelectionArgs() { 31 return getFieldReflectively("mSelectionArgs", String[].class); 32 } 33 getContentValues()34 public ContentValues getContentValues() { 35 return getFieldReflectively("mValues", ContentValues.class); 36 } 37 getExpectedCount()38 public Integer getExpectedCount() { 39 return getFieldReflectively("mExpectedCount", Integer.class); 40 } 41 getValuesBackReferences()42 public ContentValues getValuesBackReferences() { 43 return getFieldReflectively("mValuesBackReferences", ContentValues.class); 44 } 45 46 @SuppressWarnings("unchecked") getSelectionArgsBackReferences()47 public Map<Integer, Integer> getSelectionArgsBackReferences() { 48 return getFieldReflectively("mSelectionArgsBackReferences", Map.class); 49 } 50 getFieldReflectively(String fieldName, Class<T> clazz)51 private <T> T getFieldReflectively(String fieldName, Class<T> clazz) { 52 return clazz.cast(ReflectionHelpers.getField(realOperation, fieldName)); 53 } 54 } 55