Search in sources :

Example 6 with TrackEntity

use of net.rdrei.android.scdl2.api.entity.TrackEntity 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 7 with TrackEntity

use of net.rdrei.android.scdl2.api.entity.TrackEntity 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)

Example 8 with TrackEntity

use of net.rdrei.android.scdl2.api.entity.TrackEntity in project scdl by passy.

the class PurchaseEntityTest method testResolvePurchase.

@Test
public void testResolvePurchase() throws APIException {
    final TrackService service = mServiceManager.trackService();
    TrackEntity entity = service.getTrack("60200642");
    assertThat(entity.isPurchasable(), is(true));
    assertThat(entity.isDownloadable(), is(false));
    assertThat(entity.getPurchaseUrl(), equalTo("http://bit.ly/3LAU_HAUS"));
    assertThat(entity.getPurchaseTitle(), equalTo("Download on Facebook"));
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) TrackService(net.rdrei.android.scdl2.api.service.TrackService) Test(org.junit.Test)

Example 9 with TrackEntity

use of net.rdrei.android.scdl2.api.entity.TrackEntity in project scdl by passy.

the class TrackEntityParcelTest method testNestedTrackMarshallUnmarshall.

@Test
public void testNestedTrackMarshallUnmarshall() {
    final UserEntity user = new UserEntity();
    user.setId(23l);
    user.setUsername("passy");
    final TrackEntity entity = new TrackEntity();
    entity.setId(200l);
    entity.setTitle("Hello, World.");
    entity.setUser(user);
    final byte[] bytes;
    final Parcel parcel = Parcel.obtain();
    try {
        parcel.writeValue(entity);
        bytes = parcel.marshall();
    } finally {
        parcel.recycle();
    }
    final TrackEntity newEntity;
    final Parcel parcel2 = Parcel.obtain();
    try {
        parcel2.unmarshall(bytes, 0, bytes.length);
        parcel2.setDataPosition(0);
        newEntity = (TrackEntity) parcel2.readValue(TrackEntity.class.getClassLoader());
    } finally {
        parcel2.recycle();
    }
    assertThat(newEntity.getId(), equalTo(200l));
    assertThat(newEntity.getTitle(), equalTo("Hello, World."));
    assertThat(newEntity.getUser().getUsername(), equalTo("passy"));
    assertThat(newEntity.getUser().getId(), equalTo(23l));
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) Parcel(android.os.Parcel) UserEntity(net.rdrei.android.scdl2.api.entity.UserEntity) Test(org.junit.Test)

Example 10 with TrackEntity

use of net.rdrei.android.scdl2.api.entity.TrackEntity in project scdl by passy.

the class TrackEntityTest method testFormattedSize.

@Test
public void testFormattedSize() {
    TrackEntity entity = new TrackEntity();
    entity.setOriginalContentSize((long) (5.16 * 1024 * 1024));
    assertThat(entity.getFormattedSize(), equalTo("5.2MB"));
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) Test(org.junit.Test)

Aggregations

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