Search in sources :

Example 1 with DownloadActivity

use of net.rdrei.android.scdl2.ui.DownloadActivity in project scdl by passy.

the class DownloadActivityTest method smokeTestOnCreate.

@Test
public void smokeTestOnCreate() {
    final DownloadActivity activity = Robolectric.buildActivity(DownloadActivity.class).attach().create().get();
    assertThat(activity, notNullValue());
}
Also used : DownloadActivity(net.rdrei.android.scdl2.ui.DownloadActivity) Test(org.junit.Test)

Example 2 with DownloadActivity

use of net.rdrei.android.scdl2.ui.DownloadActivity in project scdl by passy.

the class DownloadActivityTest method invalidPurchaseRegression.

@Test
public void invalidPurchaseRegression() {
    final TrackEntity track = new TrackEntity();
    final UserEntity user = new UserEntity();
    // Notice capital H here.
    final String downloadUrl = "Http://not-a-link";
    user.setUsername("awesomesauce");
    track.setDownloadable(false);
    track.setUser(user);
    track.setPurchaseUrl(downloadUrl);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(DownloadActivity.MEDIA_STATE_TAG, MediaState.fromEntity(track));
    final DownloadActivity activity = Robolectric.buildActivity(DownloadActivity.class).attach().create(bundle).start().resume().get();
    final View button = activity.findViewById(R.id.btn_download);
    assertFalse(button.isEnabled());
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) Bundle(android.os.Bundle) View(android.view.View) UserEntity(net.rdrei.android.scdl2.api.entity.UserEntity) DownloadActivity(net.rdrei.android.scdl2.ui.DownloadActivity) Test(org.junit.Test)

Example 3 with DownloadActivity

use of net.rdrei.android.scdl2.ui.DownloadActivity in project scdl by passy.

the class DownloadActivityTest method purchaseFlow.

@Test
public void purchaseFlow() {
    final TrackEntity track = new TrackEntity();
    final UserEntity user = new UserEntity();
    final String downloadUrl = "http://3lau.to/downloadstuff";
    user.setUsername("awesomesauce");
    track.setDownloadable(false);
    track.setUser(user);
    track.setPurchaseUrl(downloadUrl);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(DownloadActivity.MEDIA_STATE_TAG, MediaState.fromEntity(track));
    final DownloadActivity activity = Robolectric.buildActivity(DownloadActivity.class).attach().create(bundle).start().resume().get();
    final View button = activity.findViewById(R.id.btn_download);
    assertTrue(button.isEnabled());
    button.performClick();
    final ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
    final Intent nextIntent = shadowActivity.getNextStartedActivity();
    assertThat(nextIntent.getAction(), equalTo("android.intent.action.VIEW"));
    assertThat(nextIntent.toUri(0), startsWith(downloadUrl));
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) Bundle(android.os.Bundle) ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) View(android.view.View) UserEntity(net.rdrei.android.scdl2.api.entity.UserEntity) DownloadActivity(net.rdrei.android.scdl2.ui.DownloadActivity) Test(org.junit.Test)

Aggregations

DownloadActivity (net.rdrei.android.scdl2.ui.DownloadActivity)3 Test (org.junit.Test)3 Bundle (android.os.Bundle)2 View (android.view.View)2 TrackEntity (net.rdrei.android.scdl2.api.entity.TrackEntity)2 UserEntity (net.rdrei.android.scdl2.api.entity.UserEntity)2 Intent (android.content.Intent)1 ShadowActivity (org.robolectric.shadows.ShadowActivity)1