Search in sources :

Example 6 with TeamCityApplication

use of com.github.vase4kin.teamcityapp.TeamCityApplication in project TeamCityApp by vase4kin.

the class DrawerTest method setUp.

@Before
public void setUp() {
    TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
    app.getRestApiInjector().sharedUserStorage().clearAll();
    app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
    mActivityRule.launchActivity(null);
}
Also used : TeamCityApplication(com.github.vase4kin.teamcityapp.TeamCityApplication) Before(org.junit.Before)

Example 7 with TeamCityApplication

use of com.github.vase4kin.teamcityapp.TeamCityApplication in project TeamCityApp by vase4kin.

the class SplashActivityTest method testUserNavigatesToRootProjectsActivityIgnored.

/**
 * Espresso can't record intents in case if there's no UI interactions
 */
@Ignore
@Test
public void testUserNavigatesToRootProjectsActivityIgnored() throws Exception {
    // Prepate data
    TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
    app.getAppInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
    // Launch activity
    mActivityRule.launchActivity(null);
    // Check launched intent
    intended(allOf(hasComponent(RootProjectsActivity.class.getName()), toPackage("com.github.vase4kin.teamcityapp.mock.debug")));
}
Also used : RootProjectsActivity(com.github.vase4kin.teamcityapp.root.view.RootProjectsActivity) TeamCityApplication(com.github.vase4kin.teamcityapp.TeamCityApplication) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with TeamCityApplication

use of com.github.vase4kin.teamcityapp.TeamCityApplication in project TeamCityApp by vase4kin.

the class LoginActivityTest method testUserCanCreateAccountWithCorrectUrlByImeButton.

/**
 * Verifies that user can be logged in as guest with correct account url
 */
@Test
public void testUserCanCreateAccountWithCorrectUrlByImeButton() throws Throwable {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mCallbackArgumentCaptor.getValue().onResponse(mCall, new Response.Builder().request(new Request.Builder().url(URL).build()).protocol(Protocol.HTTP_1_0).message(MESSAGE_EMPTY).code(200).build());
            return null;
        }
    }).when(mCall).enqueue(mCallbackArgumentCaptor.capture());
    onView(withId(R.id.guest_user_switch)).perform(click());
    onView(withId(R.id.teamcity_url)).perform(typeText(INPUT_URL), pressImeActionButton());
    intended(allOf(hasComponent(RootProjectsActivity.class.getName()), hasExtras(hasEntry(equalTo(BundleExtractorValues.IS_NEW_ACCOUNT_CREATED), equalTo(true)))));
    TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
    SharedUserStorage storageUtils = app.getRestApiInjector().sharedUserStorage();
    assertThat(storageUtils.hasGuestAccountWithUrl(URL), is(true));
    assertThat(storageUtils.getActiveUser().getTeamcityUrl(), is(URL));
}
Also used : Response(okhttp3.Response) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) RootProjectsActivity(com.github.vase4kin.teamcityapp.root.view.RootProjectsActivity) SharedUserStorage(com.github.vase4kin.teamcityapp.storage.SharedUserStorage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Request(okhttp3.Request) TeamCityApplication(com.github.vase4kin.teamcityapp.TeamCityApplication) Test(org.junit.Test)

Example 9 with TeamCityApplication

use of com.github.vase4kin.teamcityapp.TeamCityApplication in project TeamCityApp by vase4kin.

the class LoginActivityTest method testUserCanCreateGuestUserAccountWithCorrectUrl.

/**
 * Verifies that user can be logged in as guest user with correct account url
 */
@Test
public void testUserCanCreateGuestUserAccountWithCorrectUrl() throws Throwable {
    final String urlWithPath = "https://teamcity.com/server";
    String savedUrl = urlWithPath.concat("/");
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mCallbackArgumentCaptor.getValue().onResponse(mCall, new Response.Builder().request(new Request.Builder().url(urlWithPath).build()).protocol(Protocol.HTTP_1_0).message(MESSAGE_EMPTY).code(200).build());
            return null;
        }
    }).when(mCall).enqueue(mCallbackArgumentCaptor.capture());
    onView(withId(R.id.teamcity_url)).perform(typeText(urlWithPath.replace("https://", "")), closeSoftKeyboard());
    onView(withId(R.id.guest_user_switch)).perform(click());
    onView(withId(R.id.btn_login)).perform(click());
    intended(allOf(hasComponent(RootProjectsActivity.class.getName()), hasExtras(hasEntry(equalTo(BundleExtractorValues.IS_NEW_ACCOUNT_CREATED), equalTo(true)))));
    TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
    SharedUserStorage storageUtils = app.getRestApiInjector().sharedUserStorage();
    assertThat(storageUtils.hasGuestAccountWithUrl(savedUrl), is(true));
    assertThat(storageUtils.getActiveUser().getTeamcityUrl(), is(savedUrl));
}
Also used : SharedUserStorage(com.github.vase4kin.teamcityapp.storage.SharedUserStorage) Request(okhttp3.Request) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Response(okhttp3.Response) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) RootProjectsActivity(com.github.vase4kin.teamcityapp.root.view.RootProjectsActivity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TeamCityApplication(com.github.vase4kin.teamcityapp.TeamCityApplication) Test(org.junit.Test)

Example 10 with TeamCityApplication

use of com.github.vase4kin.teamcityapp.TeamCityApplication in project TeamCityApp by vase4kin.

the class RootProjectsActivityTest method setUp.

@Before
public void setUp() {
    TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
    app.getAppInjector().sharedUserStorage().clearAll();
    app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
}
Also used : TeamCityApplication(com.github.vase4kin.teamcityapp.TeamCityApplication) Before(org.junit.Before)

Aggregations

TeamCityApplication (com.github.vase4kin.teamcityapp.TeamCityApplication)18 Before (org.junit.Before)10 Test (org.junit.Test)7 RootProjectsActivity (com.github.vase4kin.teamcityapp.root.view.RootProjectsActivity)6 SharedUserStorage (com.github.vase4kin.teamcityapp.storage.SharedUserStorage)5 Request (okhttp3.Request)5 Mockito.doAnswer (org.mockito.Mockito.doAnswer)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Answer (org.mockito.stubbing.Answer)5 Response (okhttp3.Response)3 Ignore (org.junit.Ignore)3 Builds (com.github.vase4kin.teamcityapp.buildlist.api.Builds)1 FilterBuildsModule (com.github.vase4kin.teamcityapp.filter_builds.dagger.FilterBuildsModule)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1