Search in sources :

Example 1 with TrackEntity

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

the class PlaylistEntityTest method testParcel.

@Test
public void testParcel() {
    final TrackEntity track0 = new TrackEntity();
    track0.setId(200l);
    track0.setTitle("Hello, World.");
    final TrackEntity track1 = new TrackEntity();
    track1.setId(201l);
    track1.setTitle("Yet another track");
    final PlaylistEntity playlist = new PlaylistEntity();
    playlist.setId(23l);
    playlist.setDescription("new stuff");
    playlist.setTracks(Arrays.asList(new TrackEntity[] { track0, track1 }));
    final byte[] bytes;
    final Parcel parcel0 = Parcel.obtain();
    try {
        parcel0.writeValue(playlist);
        bytes = parcel0.marshall();
    } finally {
        parcel0.recycle();
    }
    final PlaylistEntity newPlaylist;
    final Parcel parcel1 = Parcel.obtain();
    try {
        parcel1.unmarshall(bytes, 0, bytes.length);
        parcel1.setDataPosition(0);
        newPlaylist = (PlaylistEntity) parcel1.readValue(PlaylistEntity.class.getClassLoader());
    } finally {
        parcel1.recycle();
    }
    assertThat(newPlaylist.getId(), equalTo(23l));
    assertThat(newPlaylist.getDescription(), equalTo("new stuff"));
    assertThat(newPlaylist.getTracks().size(), equalTo(2));
    assertThat(newPlaylist.getTracks().get(0).getId(), equalTo(200l));
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) PlaylistEntity(net.rdrei.android.scdl2.api.entity.PlaylistEntity) Parcel(android.os.Parcel) Test(org.junit.Test)

Example 2 with TrackEntity

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

the class MediaStateTest method testTrackType.

@Test
public void testTrackType() {
    final TrackEntity track = new TrackEntity();
    final MediaState mediaState = MediaState.fromEntity(track);
    assertThat(mediaState.getType()).isEqualTo(MediaDownloadType.TRACK);
    assertThat(mediaState.getTrackOption().isEmpty()).isFalse();
    assertThat(mediaState.getPlaylistOption().isEmpty()).isTrue();
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) MediaState(net.rdrei.android.scdl2.api.MediaState) Test(org.junit.Test)

Example 3 with TrackEntity

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

the class MediaStateTest method testTrackParcel.

@Test
public void testTrackParcel() {
    final TrackEntity track = new TrackEntity();
    track.setTitle("My track");
    track.setUser(new UserEntity());
    final MediaState entity = MediaState.fromEntity(track);
    final byte[] bytes;
    final Parcel parcel = Parcel.obtain();
    try {
        parcel.writeValue(entity);
        bytes = parcel.marshall();
    } finally {
        parcel.recycle();
    }
    final MediaState newEntity;
    final Parcel parcel2 = Parcel.obtain();
    try {
        parcel2.unmarshall(bytes, 0, bytes.length);
        parcel2.setDataPosition(0);
        newEntity = (MediaState) parcel2.readValue(MediaState.class.getClassLoader());
    } finally {
        parcel2.recycle();
    }
    assertThat(newEntity.getType()).isEqualTo(MediaDownloadType.TRACK);
    assertThat(newEntity.getTrackOption().get().getTitle()).isEqualTo("My track");
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) MediaState(net.rdrei.android.scdl2.api.MediaState) Parcel(android.os.Parcel) UserEntity(net.rdrei.android.scdl2.api.entity.UserEntity) Test(org.junit.Test)

Example 4 with TrackEntity

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

the class TrackEntityTest method testFormattedDuration.

@Test
public void testFormattedDuration() {
    TrackEntity entity = new TrackEntity();
    entity.setDuration(121000);
    assertThat(entity.getFormattedDuration(), equalTo("2:01"));
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) Test(org.junit.Test)

Example 5 with TrackEntity

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

the class TrackServiceTest method testResolveTrack.

@Test
public void testResolveTrack() throws APIException {
    final TrackService service = mServiceManager.trackService();
    TrackEntity entity = service.getTrack("44276907");
    assertThat(entity.getTitle(), equalTo("Newklear - Contaminated Selection *SPECIAL GUEST SHOW BOUNFM RADIO APRIL. 24TH*"));
}
Also used : TrackEntity(net.rdrei.android.scdl2.api.entity.TrackEntity) TrackService(net.rdrei.android.scdl2.api.service.TrackService) 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