Example usage for android.test.mock MockContext MockContext

List of usage examples for android.test.mock MockContext MockContext

Introduction

In this page you can find the example usage for android.test.mock MockContext MockContext.

Prototype

MockContext

Source Link

Usage

From source file:com.socialize.test.blackbox.HttpUtilsTest.java

@UsesMocks({ ResourceLocator.class, SocializeLogger.class })
public void testHttpUtilsInitFail() throws IOException {
    ResourceLocator locator = AndroidMock.createMock(ResourceLocator.class);
    SocializeLogger logger = AndroidMock.createMock(SocializeLogger.class);
    MockContext context = new MockContext();

    // Mock an inputStream from a fail string
    String failString = "NaN=OK";
    ByteArrayInputStream bin = new ByteArrayInputStream(failString.getBytes());

    AndroidMock.expect(locator.locate(context, SocializeConfig.SOCIALIZE_ERRORS_PATH)).andReturn(bin);
    AndroidMock.expect(logger.isWarnEnabled()).andReturn(true);

    logger.warn("NaN is not an integer");

    AndroidMock.replay(locator);//from ww w .j  a  v  a 2  s .  c  om
    AndroidMock.replay(logger);

    HttpUtils utils = new HttpUtils();
    utils.setLogger(logger);
    utils.setResourceLocator(locator);
    utils.init(context);

    AndroidMock.verify(locator);
    AndroidMock.verify(logger);
}

From source file:com.socialize.test.unit.DefaultSocializeProviderTest.java

@SuppressWarnings("unchecked")
@Override//from   w ww  .  j  ava2 s. c om
protected void setUp() throws Exception {
    super.setUp();

    sessionPersister = AndroidMock.createMock(SocializeSessionPersister.class);
    objectFactory = AndroidMock.createMock(SocializeObjectFactory.class);
    requestFactory = AndroidMock.createMock(SocializeRequestFactory.class);
    authProviderDataFactory = AndroidMock.createMock(IBeanFactory.class);
    authProviderData = AndroidMock.createMock(AuthProviderData.class);
    userFactory = AndroidMock.createMock(UserFactory.class);
    sessionFactory = AndroidMock.createMock(SocializeSessionFactory.class);
    clientFactory = AndroidMock.createMock(HttpClientFactory.class);
    session = AndroidMock.createMock(WritableSession.class);
    client = AndroidMock.createMock(HttpClient.class);
    request = AndroidMock.createMock(HttpUriRequest.class);
    response = AndroidMock.createMock(HttpResponse.class);
    jsonParser = AndroidMock.createMock(JSONParser.class);
    json = AndroidMock.createMock(JSONObject.class);
    user = AndroidMock.createMock(User.class);
    entity = AndroidMock.createMock(HttpEntity.class);
    httpUtils = AndroidMock.createMock(HttpUtils.class);
    ioUtils = AndroidMock.createMock(IOUtils.class);
    jsonArray = AndroidMock.createMock(JSONArray.class);
    mockContext = new MockContext();
    config = AndroidMock.createMock(SocializeConfig.class);
    authProviderInfoBuilder = AndroidMock.createMock(AuthProviderInfoBuilder.class);
    authProviderInfoFactory = AndroidMock.createMock(AuthProviderInfoFactory.class);
    authProviderInfo = AndroidMock.createMock(AuthProviderInfo.class);
}

From source file:com.android.emailcommon.provider.HostAuthTests.java

public void testParceling() {
    final HostAuth orig = new HostAuth();
    // Fill in some data
    orig.mPort = 993;//from  w  w  w . j a va 2s. co m
    orig.mProtocol = "imap";
    orig.mAddress = "example.com";
    orig.mLogin = "user";
    orig.mPassword = "supersecret";
    orig.mDomain = "domain";
    orig.mClientCertAlias = "certalias";

    final Parcel p1 = Parcel.obtain();
    orig.writeToParcel(p1, 0);
    p1.setDataPosition(0);
    final HostAuth unparceled1 = new HostAuth(p1);
    p1.recycle();
    assertEquals(orig, unparceled1);
    assertEquals(orig.mCredentialKey, unparceled1.mCredentialKey);
    assertEquals(orig.mCredential, unparceled1.mCredential);

    orig.getOrCreateCredential(new MockContext());

    final Parcel p2 = Parcel.obtain();
    orig.writeToParcel(p2, 0);
    p2.setDataPosition(0);
    final HostAuth unparceled2 = new HostAuth(p2);
    p2.recycle();
    assertEquals(orig, unparceled2);
    assertEquals(orig.mCredentialKey, unparceled2.mCredentialKey);
    assertEquals(orig.mCredential, unparceled2.mCredential);
}