Android MockContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android MockContext class.

This code example shows how to use the following methods:getSharedPreferences
		socializeSessionFactory = AndroidMock.createMock(SocializeSessionFactory.class);
	} 
	 
	public void testPreferencePersistDelete() throws JSONException { 
 
		AndroidMock.expect(context.getSharedPreferences("SocializeSession", Context.MODE_PRIVATE)).andReturn(prefs);
		AndroidMock.expect(prefs.edit()).andReturn(editor);
		AndroidMock.expect(editor.clear()).andReturn(editor);
		AndroidMock.expect(editor.commit()).andReturn(true);
		 
		AndroidMock.replay(context);
		AndroidMock.replay(prefs);
		AndroidMock.replay(editor);
		 
		PreferenceSessionPersister persister = new PreferenceSessionPersister(userFactory, socializeSessionFactory);
		 
		persister.delete(context);
		 
		AndroidMock.verify(context);
		AndroidMock.verify(prefs);

7
CodeRank
This code example shows how to use the following methods:
		Container container = AndroidMock.createMock(Container.class);
		InputStream in = AndroidMock.createMock(InputStream.class);
		 
		InputStream[] inArray = {in};
		 
		MockContext mockContext = new MockContext();
		 
		AndroidIOC ioc = new AndroidIOC();
		 
		final int returned = 10;
		 
		AndroidMock.expect(builder.build(AndroidMock.eq(mockContext), AndroidMock.eq(inArray))).andReturn(container);
		AndroidMock.expect(container.size()).andReturn(returned);
		 
		AndroidMock.replay(builder);
		AndroidMock.replay(container);
		 
		ioc.init(mockContext, builder, inArray);
		 
		assertEquals(10, ioc.size());

6
CodeRank
This code example shows how to use the following methods:
import com.google.android.testing.mocking.AndroidMock; 
 
public class RequestProxyImplTest extends AbstractTest { 
 
    public void testSendRequest() throws Exception { 
        Context context = new MockContext();
        SendRequestParams params = new SendRequestParams(
                "body1", 
                new String[] {"r1", "r2"},
                "url1", 
                "mobileUrl1", 
                "image1"); 
        SendRequestCallbackHandler handler = new SendRequestCallbackHandler(context);
        Map<String, String> parameterMap = params.convertParameterMap();
         
        MixiContainer mixiContainer = AndroidMock.createMock(MixiContainer.class);
        mixiContainer.showDialog(context, "/requests", parameterMap, handler);
        AndroidMock.replay(mixiContainer);
         
        RequestProxyImpl target = new RequestProxyImpl(mixiContainer);

6
CodeRank
This code example shows how to use the following methods:
 
    @SmallTest 
    public void testPutInvalidTypeThrowsException() { 
        boolean exceptionThrown = false;
        try { 
            ContextTypes.getInstance().put(new MockContext(), -1);
        } catch (IllegalArgumentException e) {
            exceptionThrown = true;
        } 
        assertTrue(exceptionThrown);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:
 
    private GetIdCallbackHandler target;
     
    @Override 
    protected void setUp() { 
        target = new GetIdCallbackHandler(new MockContext());
    } 
     
    @Override 
    protected void tearDown() { 
        target = null;
    } 
     
    public void testSimple() throws Exception { 
        String json = "{\"id\":\"id1\"}";
        Bundle bundle = new Bundle();
        bundle.putString("response", json);
         
        target.onComplete(bundle);
         
5
CodeRank
This code example shows how to use the following methods:
     
    private SendRequestCallbackHandler target;
     
    @Override 
    protected void setUp() { 
        target = new SendRequestCallbackHandler(new MockContext());
    } 
     
    @Override 
    protected void tearDown() { 
        target = null;
    } 
     
    public void testSimple() throws Exception { 
        Bundle bundle = new Bundle();
        bundle.putString("request_member", "123,456");
        bundle.putString("request_id", "requestId1");
         
        target.onComplete(bundle);
         
5
CodeRank
This code example shows how to use the following methods:
import jp.mixi.android.sdk.MixiContainer; 
 
public class GroupsProxyImplTest extends AbstractTest { 
     
    public void testGetMyGroups() throws Exception { 
        GetGroupsCallbackHandler handler = new GetGroupsCallbackHandler(new MockContext());
         
        MixiContainer mixiContainer = AndroidMock.createMock(MixiContainer.class);
        mixiContainer.send("/groups/@me", handler);
        AndroidMock.replay(mixiContainer);
         
        GroupsProxyImpl target = new GroupsProxyImpl(mixiContainer);
        target.getMyGroups(handler);
         
        AndroidMock.verify(mixiContainer);
    } 
 
    public void testGetMyGroupsWithParams() throws Exception { 
        GetGroupsCallbackHandler handler = new GetGroupsCallbackHandler(new MockContext());
        Map<String, String> paramMap = new HashMap<String, String>();
5
CodeRank
This code example shows how to use the following methods:
import com.google.android.testing.mocking.AndroidMock; 
 
public class SearchProxyImplTest extends AbstractTest { 
 
    public void testGetPeople() throws Exception { 
        GetPeopleCallbackHandler handler = new GetPeopleCallbackHandler(new MockContext());
        Map<String, String> params = new HashMap<String, String>();
        params.put("q", "e1,e2,e3");
         
        MixiContainer mixiContainer = AndroidMock.createMock(MixiContainer.class);
        mixiContainer.send("/search/people/@all", params, handler);
        AndroidMock.replay(mixiContainer);
         
        SearchProxyImpl target = new SearchProxyImpl(mixiContainer);
        String[] emails = {"e1", "e2", "e3"};
        target.getPeople("@all", emails, handler);
         
        AndroidMock.verify(mixiContainer);
    } 
 
5
CodeRank
This code example shows how to use the following methods:
import com.google.android.testing.mocking.AndroidMock; 
 
public class CheckProxyImplTest extends AbstractTest { 
 
    public void testPostCheck() throws Exception { 
        CallbackAdapter handler = new CallbackAdapter(new MockContext());
        String key = "key1";
        String title = "title1";
        String primaryUrl = "primaryUrl1";
        JSONObject params = new JSONObject();
        params.put("key", key);
        params.put("title", title);
        params.put("primaryUrl", primaryUrl);
         
        MixiContainer mixiContainer = AndroidMock.createMock(MixiContainer.class);
        mixiContainer.send(AndroidMock.eq("/share"), eqJSONObject(params), AndroidMock.same(handler));
        AndroidMock.replay(mixiContainer);
         
        CheckProxyImpl target = new CheckProxyImpl(mixiContainer);
        target.postCheck(key, title, primaryUrl, handler);
5
CodeRank
This code example shows how to use the following methods:
import com.google.android.testing.mocking.AndroidMock; 
 
public class PeopleProxyImplTest extends AbstractTest { 
 
    public void testGetMe() throws Exception { 
        GetPeopleCallbackHandler handler = new GetPeopleCallbackHandler(new MockContext());
         
        MixiContainer mixiContainer = AndroidMock.createMock(MixiContainer.class);
        mixiContainer.send("/people/@me/@self", handler);
        AndroidMock.replay(mixiContainer);
         
        PeopleProxyImpl target = new PeopleProxyImpl(mixiContainer);
        target.getMe(handler);
         
        AndroidMock.verify(mixiContainer);
    } 
     
    public void testGetFriends() throws Exception { 
        GetPeopleCallbackHandler handler = new GetPeopleCallbackHandler(new MockContext());
         
5
CodeRank

Related Android MockContext Questions & Answers:

See Code Examples for Android MockContext Methods: