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 org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@SmallTest
|
|
||||||
public class FeedFilterTest {
|
public class FeedFilterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullFilter() throws Exception {
|
public void testNullFilter() {
|
||||||
FeedFilter filter = new FeedFilter();
|
FeedFilter filter = new FeedFilter();
|
||||||
FeedItem item = new FeedItem();
|
FeedItem item = new FeedItem();
|
||||||
item.setTitle("Hello world");
|
item.setTitle("Hello world");
|
||||||
|
@ -26,7 +22,7 @@ public class FeedFilterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicIncludeFilter() throws Exception {
|
public void testBasicIncludeFilter() {
|
||||||
String includeFilter = "Hello";
|
String includeFilter = "Hello";
|
||||||
FeedFilter filter = new FeedFilter(includeFilter, "");
|
FeedFilter filter = new FeedFilter(includeFilter, "");
|
||||||
FeedItem item = new FeedItem();
|
FeedItem item = new FeedItem();
|
||||||
|
@ -44,7 +40,7 @@ public class FeedFilterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicExcludeFilter() throws Exception {
|
public void testBasicExcludeFilter() {
|
||||||
String excludeFilter = "Hello";
|
String excludeFilter = "Hello";
|
||||||
FeedFilter filter = new FeedFilter("", excludeFilter);
|
FeedFilter filter = new FeedFilter("", excludeFilter);
|
||||||
FeedItem item = new FeedItem();
|
FeedItem item = new FeedItem();
|
||||||
|
@ -62,7 +58,7 @@ public class FeedFilterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComplexIncludeFilter() throws Exception {
|
public void testComplexIncludeFilter() {
|
||||||
String includeFilter = "Hello \n\"Two words\"";
|
String includeFilter = "Hello \n\"Two words\"";
|
||||||
FeedFilter filter = new FeedFilter(includeFilter, "");
|
FeedFilter filter = new FeedFilter(includeFilter, "");
|
||||||
FeedItem item = new FeedItem();
|
FeedItem item = new FeedItem();
|
||||||
|
@ -84,7 +80,7 @@ public class FeedFilterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComplexExcludeFilter() throws Exception {
|
public void testComplexExcludeFilter() {
|
||||||
String excludeFilter = "Hello \"Two words\"";
|
String excludeFilter = "Hello \"Two words\"";
|
||||||
FeedFilter filter = new FeedFilter("", excludeFilter);
|
FeedFilter filter = new FeedFilter("", excludeFilter);
|
||||||
FeedItem item = new FeedItem();
|
FeedItem item = new FeedItem();
|
||||||
|
@ -106,7 +102,7 @@ public class FeedFilterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComboFilter() throws Exception {
|
public void testComboFilter() {
|
||||||
String includeFilter = "Hello world";
|
String includeFilter = "Hello world";
|
||||||
String excludeFilter = "dislike";
|
String excludeFilter = "dislike";
|
||||||
FeedFilter filter = new FeedFilter(includeFilter, excludeFilter);
|
FeedFilter filter = new FeedFilter(includeFilter, excludeFilter);
|
|
@ -2,16 +2,23 @@ package de.danoeh.antennapod.core.feed;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.MockedStatic;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
|
|
||||||
import static de.danoeh.antennapod.core.feed.FeedItemMother.anyFeedItemWithImage;
|
import static de.danoeh.antennapod.core.feed.FeedItemMother.anyFeedItemWithImage;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
public class FeedItemTest {
|
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 original;
|
||||||
private FeedItem changedFeedItem;
|
private FeedItem changedFeedItem;
|
||||||
|
|
||||||
|
@ -22,21 +29,21 @@ public class FeedItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateFromOther_feedItemImageDownloadUrlChanged() throws Exception {
|
public void testUpdateFromOther_feedItemImageDownloadUrlChanged() {
|
||||||
setNewFeedItemImageDownloadUrl();
|
setNewFeedItemImageDownloadUrl();
|
||||||
original.updateFromOther(changedFeedItem);
|
original.updateFromOther(changedFeedItem);
|
||||||
assertFeedItemImageWasUpdated();
|
assertFeedItemImageWasUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateFromOther_feedItemImageRemoved() throws Exception {
|
public void testUpdateFromOther_feedItemImageRemoved() {
|
||||||
feedItemImageRemoved();
|
feedItemImageRemoved();
|
||||||
original.updateFromOther(changedFeedItem);
|
original.updateFromOther(changedFeedItem);
|
||||||
assertFeedItemImageWasNotUpdated();
|
assertFeedItemImageWasNotUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateFromOther_feedItemImageAdded() throws Exception {
|
public void testUpdateFromOther_feedItemImageAdded() {
|
||||||
original.setImageUrl(null);
|
original.setImageUrl(null);
|
||||||
setNewFeedItemImageDownloadUrl();
|
setNewFeedItemImageDownloadUrl();
|
||||||
original.updateFromOther(changedFeedItem);
|
original.updateFromOther(changedFeedItem);
|
||||||
|
@ -102,4 +109,36 @@ public class FeedItemTest {
|
||||||
assertEquals(anyFeedItemWithImage().getImageUrl(), original.getImageUrl());
|
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