Merge pull request #3077 from bibz/develop
Validate that the item state is only changed when needed
This commit is contained in:
commit
56de034c7c
|
@ -79,6 +79,7 @@ dependencies {
|
|||
}
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'org.mockito:mockito-core:1.10.19'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test:rules:1.0.2'
|
||||
|
|
|
@ -594,7 +594,7 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||
@Override
|
||||
public void setDownloaded(boolean downloaded) {
|
||||
super.setDownloaded(downloaded);
|
||||
if(item != null && downloaded && !item.isPlayed()) {
|
||||
if(item != null && downloaded && item.isNew()) {
|
||||
item.setPlayed(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.junit.Test;
|
|||
|
||||
import static de.danoeh.antennapod.core.feed.FeedItemMother.anyFeedItemWithImage;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class FeedItemTest {
|
||||
|
||||
|
@ -39,6 +40,39 @@ public class FeedItemTest {
|
|||
assertFeedItemImageWasUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a played item loses that state after being marked as new.
|
||||
*/
|
||||
@Test
|
||||
public void testMarkPlayedItemAsNew_itemNotPlayed() {
|
||||
original.setPlayed(true);
|
||||
original.setNew();
|
||||
|
||||
assertFalse(original.isPlayed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a new item loses that state after being marked as played.
|
||||
*/
|
||||
@Test
|
||||
public void testMarkNewItemAsPlayed_itemNotNew() {
|
||||
original.setNew();
|
||||
original.setPlayed(true);
|
||||
|
||||
assertFalse(original.isNew());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a new item loses that state after being marked as not played.
|
||||
*/
|
||||
@Test
|
||||
public void testMarkNewItemAsNotPlayed_itemNotNew() {
|
||||
original.setNew();
|
||||
original.setPlayed(false);
|
||||
|
||||
assertFalse(original.isNew());
|
||||
}
|
||||
|
||||
private void setNewFeedItemImageDownloadUrl() {
|
||||
changedFeedItem.setImageUrl("http://example.com/new_picture");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package de.danoeh.antennapod.core.feed;
|
||||
|
||||
class FeedMediaMother {
|
||||
|
||||
private static final String EPISODE_URL = "http://example.com/episode";
|
||||
private static final long SIZE = 42;
|
||||
private static final String MIME_TYPE = "audio/mp3";
|
||||
|
||||
static FeedMedia anyFeedMedia() {
|
||||
return new FeedMedia(null, EPISODE_URL, SIZE, MIME_TYPE);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package de.danoeh.antennapod.core.feed;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static de.danoeh.antennapod.core.feed.FeedMediaMother.anyFeedMedia;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class FeedMediaTest {
|
||||
|
||||
private FeedMedia media;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
media = anyFeedMedia();
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloading a media from a not new and not played item should not change the item state.
|
||||
*/
|
||||
@Test
|
||||
public void testDownloadMediaOfNotNewAndNotPlayedItem_unchangedItemState() {
|
||||
FeedItem item = mock(FeedItem.class);
|
||||
when(item.isNew()).thenReturn(false);
|
||||
when(item.isPlayed()).thenReturn(false);
|
||||
|
||||
media.setItem(item);
|
||||
media.setDownloaded(true);
|
||||
|
||||
verify(item, never()).setNew();
|
||||
verify(item, never()).setPlayed(true);
|
||||
verify(item, never()).setPlayed(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloading a media from a played item (thus not new) should not change the item state.
|
||||
*/
|
||||
@Test
|
||||
public void testDownloadMediaOfPlayedItem_unchangedItemState() {
|
||||
FeedItem item = mock(FeedItem.class);
|
||||
when(item.isNew()).thenReturn(false);
|
||||
when(item.isPlayed()).thenReturn(true);
|
||||
|
||||
media.setItem(item);
|
||||
media.setDownloaded(true);
|
||||
|
||||
verify(item, never()).setNew();
|
||||
verify(item, never()).setPlayed(true);
|
||||
verify(item, never()).setPlayed(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloading a media from a new item (thus not played) should change the item to not played.
|
||||
*/
|
||||
@Test
|
||||
public void testDownloadMediaOfNewItem_changedToNotPlayedItem() {
|
||||
FeedItem item = mock(FeedItem.class);
|
||||
when(item.isNew()).thenReturn(true);
|
||||
when(item.isPlayed()).thenReturn(false);
|
||||
|
||||
media.setItem(item);
|
||||
media.setDownloaded(true);
|
||||
|
||||
verify(item).setPlayed(false);
|
||||
verify(item, never()).setNew();
|
||||
verify(item, never()).setPlayed(true);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue