1 package org.robolectric.shadows; 2 3 import android.content.ContentUris; 4 import android.net.Uri; 5 import org.robolectric.annotation.Implementation; 6 import org.robolectric.annotation.Implements; 7 8 @Implements(ContentUris.class) 9 public class ShadowContentUris { 10 11 @Implementation withAppendedId(Uri contentUri, long id)12 protected static Uri withAppendedId(Uri contentUri, long id) { 13 return Uri.withAppendedPath(contentUri, String.valueOf(id)); 14 } 15 16 @Implementation parseId(Uri contentUri)17 protected static long parseId(Uri contentUri) { 18 if (!contentUri.isHierarchical()) { 19 throw new UnsupportedOperationException(); 20 } 21 String path = contentUri.getLastPathSegment(); 22 if (path == null) return -1; 23 return Long.parseLong(path); 24 } 25 } 26