Run FeedFilterTest and FeedItemTest without Android emulator (#4807)
This commit is contained in:
parent
0b715d5494
commit
a52beda1f1
|
@ -1,43 +0,0 @@
|
|||
package de.test.antennapod.feed;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@SmallTest
|
||||
public class FeedItemTest {
|
||||
private static final String TEXT_LONG = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
||||
private static final String TEXT_SHORT = "Lorem ipsum";
|
||||
|
||||
/**
|
||||
* If one of `description` or `content:encoded` is null, use the other one.
|
||||
*/
|
||||
@Test
|
||||
public void testShownotesNullValues() throws Exception {
|
||||
testShownotes(null, TEXT_LONG);
|
||||
testShownotes(TEXT_LONG, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* If `description` is reasonably longer than `content:encoded`, use `description`.
|
||||
*/
|
||||
@Test
|
||||
public void testShownotesLength() throws Exception {
|
||||
testShownotes(TEXT_SHORT, TEXT_LONG);
|
||||
testShownotes(TEXT_LONG, TEXT_SHORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the shownotes equal TEXT_LONG, using the given `description` and `content:encoded`
|
||||
* @param description Description of the feed item
|
||||
* @param contentEncoded `content:encoded` of the feed item
|
||||
*/
|
||||
private void testShownotes(String description, String contentEncoded) throws Exception {
|
||||
FeedItem item = new FeedItem();
|
||||
item.setDescription(description);
|
||||
item.setContentEncoded(contentEncoded);
|
||||
assertEquals(TEXT_LONG, item.loadShownotes().call());
|
||||
}
|
||||
}
|
|
@ -1,19 +1,15 @@
|
|||
package de.test.antennapod.feed;
|
||||
package de.danoeh.antennapod.core.feed;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import de.danoeh.antennapod.core.feed.FeedFilter;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@SmallTest
|
||||
public class FeedFilterTest {
|
||||
|
||||
@Test
|
||||
public void testNullFilter() throws Exception {
|
||||
public void testNullFilter() {
|
||||
FeedFilter filter = new FeedFilter();
|
||||
FeedItem item = new FeedItem();
|
||||
item.setTitle("Hello world");
|
||||
|
@ -26,7 +22,7 @@ public class FeedFilterTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBasicIncludeFilter() throws Exception {
|
||||
public void testBasicIncludeFilter() {
|
||||
String includeFilter = "Hello";
|
||||
FeedFilter filter = new FeedFilter(includeFilter, "");
|
||||
FeedItem item = new FeedItem();
|
||||
|
@ -44,7 +40,7 @@ public class FeedFilterTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBasicExcludeFilter() throws Exception {
|
||||
public void testBasicExcludeFilter() {
|
||||
String excludeFilter = "Hello";
|
||||
FeedFilter filter = new FeedFilter("", excludeFilter);
|
||||
FeedItem item = new FeedItem();
|
||||
|
@ -62,7 +58,7 @@ public class FeedFilterTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testComplexIncludeFilter() throws Exception {
|
||||
public void testComplexIncludeFilter() {
|
||||
String includeFilter = "Hello \n\"Two words\"";
|
||||
FeedFilter filter = new FeedFilter(includeFilter, "");
|
||||
FeedItem item = new FeedItem();
|
||||
|
@ -84,7 +80,7 @@ public class FeedFilterTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testComplexExcludeFilter() throws Exception {
|
||||
public void testComplexExcludeFilter() {
|
||||
String excludeFilter = "Hello \"Two words\"";
|
||||
FeedFilter filter = new FeedFilter("", excludeFilter);
|
||||
FeedItem item = new FeedItem();
|
||||
|
@ -106,7 +102,7 @@ public class FeedFilterTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testComboFilter() throws Exception {
|
||||
public void testComboFilter() {
|
||||
String includeFilter = "Hello world";
|
||||
String excludeFilter = "dislike";
|
||||
FeedFilter filter = new FeedFilter(includeFilter, excludeFilter);
|
|
@ -2,16 +2,23 @@ package de.danoeh.antennapod.core.feed;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
|
||||
import static de.danoeh.antennapod.core.feed.FeedItemMother.anyFeedItemWithImage;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class FeedItemTest {
|
||||
|
||||
private static final String TEXT_LONG = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
||||
private static final String TEXT_SHORT = "Lorem ipsum";
|
||||
|
||||
private FeedItem original;
|
||||
private FeedItem changedFeedItem;
|
||||
|
||||
|
@ -22,21 +29,21 @@ public class FeedItemTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateFromOther_feedItemImageDownloadUrlChanged() throws Exception {
|
||||
public void testUpdateFromOther_feedItemImageDownloadUrlChanged() {
|
||||
setNewFeedItemImageDownloadUrl();
|
||||
original.updateFromOther(changedFeedItem);
|
||||
assertFeedItemImageWasUpdated();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateFromOther_feedItemImageRemoved() throws Exception {
|
||||
public void testUpdateFromOther_feedItemImageRemoved() {
|
||||
feedItemImageRemoved();
|
||||
original.updateFromOther(changedFeedItem);
|
||||
assertFeedItemImageWasNotUpdated();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateFromOther_feedItemImageAdded() throws Exception {
|
||||
public void testUpdateFromOther_feedItemImageAdded() {
|
||||
original.setImageUrl(null);
|
||||
setNewFeedItemImageDownloadUrl();
|
||||
original.updateFromOther(changedFeedItem);
|
||||
|
@ -102,4 +109,36 @@ public class FeedItemTest {
|
|||
assertEquals(anyFeedItemWithImage().getImageUrl(), original.getImageUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* If one of `description` or `content:encoded` is null, use the other one.
|
||||
*/
|
||||
@Test
|
||||
public void testShownotesNullValues() throws Exception {
|
||||
testShownotes(null, TEXT_LONG);
|
||||
testShownotes(TEXT_LONG, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* If `description` is reasonably longer than `content:encoded`, use `description`.
|
||||
*/
|
||||
@Test
|
||||
public void testShownotesLength() throws Exception {
|
||||
testShownotes(TEXT_SHORT, TEXT_LONG);
|
||||
testShownotes(TEXT_LONG, TEXT_SHORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the shownotes equal TEXT_LONG, using the given `description` and `content:encoded`.
|
||||
*
|
||||
* @param description Description of the feed item
|
||||
* @param contentEncoded `content:encoded` of the feed item
|
||||
*/
|
||||
private void testShownotes(String description, String contentEncoded) throws Exception {
|
||||
try (MockedStatic<DBReader> ignore = Mockito.mockStatic(DBReader.class)) {
|
||||
FeedItem item = new FeedItem();
|
||||
item.setDescription(description);
|
||||
item.setContentEncoded(contentEncoded);
|
||||
assertEquals(TEXT_LONG, item.loadShownotes().call());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue