public Cursor retrieveSmsFromDevice(byte directoryType, ContentResolver resolver) {
Cursor cursor = null;
try {
if (directoryType == 0 || resolver == null) {
throw new RetrieveSmsException();
}
switch (directoryType) {
case SmsDPConstant.INBOX:
Uri inbox = Uri.parse(SmsDPConstant.INBOX_URI);
cursor = resolver.query(inbox, SMS_PROJECTION, null, null, SORT_ORDER);
return cursor;
case SmsDPConstant.SENT:
Uri send = Uri.parse(SmsDPConstant.SENT_URI);
cursor = resolver.query(send, SMS_PROJECTION, null, null, SORT_ORDER);
return cursor;
case SmsDPConstant.DRAFT:
Uri draft = Uri.parse(SmsDPConstant.DRAFT_URI);
cursor = resolver.query(draft, SMS_PROJECTION, null, null, SORT_ORDER);
return cursor;
}
} catch (RetrieveSmsException e) {
e.printStackTrace();
} finally {
return cursor;
}
}
When I am calling this function from robolectric test function I am getting Cursor object as NULL.
I am passing ContentResolver object. I am creating ContentResolver using robolectric.
Code Snippet:
ContentResolver mResolver = RuntimeEnvironment.application.getContentResolver();Please help me. How do I need to create shadow ContentProvider.
--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class SmsDataPoolerTest {
private Context mContext;
private ContentResolver mResolver;
@Before
public void setUp() throws Exception {
initMocks(this);
mResolver = RuntimeEnvironment.application.getContentResolver();
}
@After
public void tearDown() throws Exception {
mContext = null;
}
@Test
public void getInstance() throws Exception{
SmsDataPooler dataPooler = SmsDataPooler.getInstance();
assertNotNull(dataPooler);
}
@Test
public void retrieveSmsFromDevice() throws Exception {
ContentValues values = new ContentValues();
values.put("address", "123456789");
values.put("body", "foo bar");
Uri uri = mResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values);
System.out.println(uri.toString());
SmsDataPooler dataPooler = SmsDataPooler.getInstance();
Cursor cursor = dataPooler.retrieveSmsFromDevice(SmsDPConstant.INBOX, mResolver);
assertNotNull(cursor);
Cursor cursor1 = dataPooler.retrieveSmsFromDevice(SmsDPConstant.SENT, mResolver);
assertNotNull(cursor1);
Cursor cursor2 = dataPooler.retrieveSmsFromDevice(SmsDPConstant.DRAFT, mResolver);
assertNotNull(cursor2);
}
@Test
public void retrieveSmsFromDeviceNegetive() throws Exception {
SmsDataPooler dataPooler = SmsDataPooler.getInstance();
ContentResolver resolver = null;
Cursor cursor = dataPooler.retrieveSmsFromDevice((byte)0, resolver);
assertNull(cursor);
}
}
This is my test class. I am getting null value for Cursor object when I am calling retrieveSmsFromDevice(byte directoryType, ContentResolver resolver) function.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
public Cursor retrieveSmsFromDevice(byte directoryType, ContentResolver resolver) {
Cursor cursor = null;
try {
if (directoryType == 0 || resolver == null) {
throw new RetrieveSmsException();
}
switch (directoryType) {
case SmsDPConstant.INBOX:
cursor = resolver.query(Telephony.Sms.Inbox.CONTENT_URI,
SMS_PROJECTION, null, null, SORT_ORDER);
return cursor;
case SmsDPConstant.SENT:
cursor = resolver.query(Telephony.Sms.Sent.CONTENT_URI,
SMS_PROJECTION, null, null, SORT_ORDER);
return cursor;
case SmsDPConstant.DRAFT:
cursor = resolver.query(Telephony.Sms.Draft.CONTENT_URI,
SMS_PROJECTION, null, null, SORT_ORDER);
return cursor;
}
} catch (RetrieveSmsException e) {
e.printStackTrace();
} finally {
return cursor;
}
}
--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric+unsubscribe@googlegroups.com.