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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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);
    } 
} 
Full Snippet Info
5
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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);
         
Full Snippet Info
5
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android MockContext Questions & Answers:

See Code Examples for Android MockContext Methods: