Home | History | Annotate | Download | only in shadows
      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
     12   public static Uri withAppendedId(Uri contentUri, long id) {
     13     return Uri.withAppendedPath(contentUri, String.valueOf(id));
     14   }
     15 
     16   @Implementation
     17   public 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