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