Simplify junit assertions

This commit is contained in:
TacoTheDank 2020-07-11 19:49:35 -04:00
parent 4857892b05
commit e0e27d442c
8 changed files with 83 additions and 75 deletions

View File

@ -6,6 +6,7 @@ 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
@ -17,8 +18,8 @@ public class FeedFilterTest {
FeedItem item = new FeedItem();
item.setTitle("Hello world");
assertTrue(!filter.excludeOnly());
assertTrue(!filter.includeOnly());
assertFalse(filter.excludeOnly());
assertFalse(filter.includeOnly());
assertEquals("", filter.getExcludeFilter());
assertEquals("", filter.getIncludeFilter());
assertTrue(filter.shouldAutoDownload(item));
@ -34,12 +35,12 @@ public class FeedFilterTest {
FeedItem item2 = new FeedItem();
item2.setTitle("Don't include me");
assertTrue(!filter.excludeOnly());
assertFalse(filter.excludeOnly());
assertTrue(filter.includeOnly());
assertEquals("", filter.getExcludeFilter());
assertEquals(includeFilter, filter.getIncludeFilter());
assertTrue(filter.shouldAutoDownload(item));
assertTrue(!filter.shouldAutoDownload(item2));
assertFalse(filter.shouldAutoDownload(item2));
}
@Test
@ -53,10 +54,10 @@ public class FeedFilterTest {
item2.setTitle("Item2");
assertTrue(filter.excludeOnly());
assertTrue(!filter.includeOnly());
assertFalse(filter.includeOnly());
assertEquals(excludeFilter, filter.getExcludeFilter());
assertEquals("", filter.getIncludeFilter());
assertTrue(!filter.shouldAutoDownload(item));
assertFalse(filter.shouldAutoDownload(item));
assertTrue(filter.shouldAutoDownload(item2));
}
@ -73,12 +74,12 @@ public class FeedFilterTest {
FeedItem item3 = new FeedItem();
item3.setTitle("One two words");
assertTrue(!filter.excludeOnly());
assertFalse(filter.excludeOnly());
assertTrue(filter.includeOnly());
assertEquals("", filter.getExcludeFilter());
assertEquals(includeFilter, filter.getIncludeFilter());
assertTrue(filter.shouldAutoDownload(item));
assertTrue(!filter.shouldAutoDownload(item2));
assertFalse(filter.shouldAutoDownload(item2));
assertTrue(filter.shouldAutoDownload(item3));
}
@ -96,12 +97,12 @@ public class FeedFilterTest {
item3.setTitle("One two words");
assertTrue(filter.excludeOnly());
assertTrue(!filter.includeOnly());
assertFalse(filter.includeOnly());
assertEquals(excludeFilter, filter.getExcludeFilter());
assertEquals("", filter.getIncludeFilter());
assertTrue(!filter.shouldAutoDownload(item));
assertFalse(filter.shouldAutoDownload(item));
assertTrue(filter.shouldAutoDownload(item2));
assertTrue(!filter.shouldAutoDownload(item3));
assertFalse(filter.shouldAutoDownload(item3));
}
@Test
@ -122,8 +123,8 @@ public class FeedFilterTest {
assertTrue(filter.hasExcludeFilter());
assertTrue(filter.hasIncludeFilter());
assertTrue(filter.shouldAutoDownload(download));
assertTrue(!filter.shouldAutoDownload(doNotDownload));
assertTrue(!filter.shouldAutoDownload(doNotDownload2));
assertFalse(filter.shouldAutoDownload(doNotDownload));
assertFalse(filter.shouldAutoDownload(doNotDownload2));
}
}

View File

@ -82,7 +82,7 @@ public class HttpDownloaderTest {
downloader.call();
DownloadStatus status = downloader.getResult();
assertNotNull(status);
assertTrue(status.isSuccessful() == expectedResult);
assertEquals(expectedResult, status.isSuccessful());
assertTrue(status.isDone());
// the file should not exist if the download has failed and deleteExisting was true
assertTrue(!deleteExisting || new File(feedFile.getFile_url()).exists() == expectedResult);

View File

@ -38,6 +38,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -173,7 +174,7 @@ public class PlaybackServiceMediaPlayerTest {
throw assertionError;
assertTrue(res);
assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.INITIALIZED);
assertSame(PlayerStatus.INITIALIZED, psmp.getPSMPInfo().playerStatus);
assertFalse(psmp.isStartWhenPrepared());
callback.cancel();
psmp.shutdown();
@ -214,7 +215,7 @@ public class PlaybackServiceMediaPlayerTest {
throw assertionError;
assertTrue(res);
assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.INITIALIZED);
assertSame(PlayerStatus.INITIALIZED, psmp.getPSMPInfo().playerStatus);
assertTrue(psmp.isStartWhenPrepared());
callback.cancel();
psmp.shutdown();
@ -256,7 +257,7 @@ public class PlaybackServiceMediaPlayerTest {
if (assertionError != null)
throw assertionError;
assertTrue(res);
assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.PREPARED);
assertSame(PlayerStatus.PREPARED, psmp.getPSMPInfo().playerStatus);
callback.cancel();
psmp.shutdown();
@ -301,7 +302,7 @@ public class PlaybackServiceMediaPlayerTest {
if (assertionError != null)
throw assertionError;
assertTrue(res);
assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.PLAYING);
assertSame(PlayerStatus.PLAYING, psmp.getPSMPInfo().playerStatus);
callback.cancel();
psmp.shutdown();
}
@ -339,7 +340,7 @@ public class PlaybackServiceMediaPlayerTest {
if (assertionError != null)
throw assertionError;
assertTrue(res);
assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.INITIALIZED);
assertSame(PlayerStatus.INITIALIZED, psmp.getPSMPInfo().playerStatus);
assertFalse(psmp.isStartWhenPrepared());
callback.cancel();
psmp.shutdown();
@ -378,7 +379,7 @@ public class PlaybackServiceMediaPlayerTest {
if (assertionError != null)
throw assertionError;
assertTrue(res);
assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.INITIALIZED);
assertSame(PlayerStatus.INITIALIZED, psmp.getPSMPInfo().playerStatus);
assertTrue(psmp.isStartWhenPrepared());
callback.cancel();
psmp.shutdown();
@ -420,7 +421,7 @@ public class PlaybackServiceMediaPlayerTest {
if (assertionError != null)
throw assertionError;
assertTrue(res);
assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.PREPARED);
assertSame(PlayerStatus.PREPARED, psmp.getPSMPInfo().playerStatus);
callback.cancel();
psmp.shutdown();
}
@ -465,7 +466,7 @@ public class PlaybackServiceMediaPlayerTest {
if (assertionError != null)
throw assertionError;
assertTrue(res);
assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.PLAYING);
assertSame(PlayerStatus.PLAYING, psmp.getPSMPInfo().playerStatus);
callback.cancel();
psmp.shutdown();
}

View File

@ -29,6 +29,7 @@ import de.danoeh.antennapod.core.storage.PodDBAdapter;
import de.danoeh.antennapod.core.util.playback.Playable;
import static de.test.antennapod.util.event.FeedItemEventListener.withFeedItemEventListener;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@ -92,9 +93,9 @@ public class PlaybackServiceTaskManagerTest {
PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM);
List<FeedItem> testQueue = pstm.getQueue();
assertNotNull(testQueue);
assertTrue(queue.size() == testQueue.size());
assertEquals(testQueue.size(), queue.size());
for (int i = 0; i < queue.size(); i++) {
assertTrue(queue.get(i).getId() == testQueue.get(i).getId());
assertEquals(testQueue.get(i).getId(), queue.get(i).getId());
}
pstm.shutdown();
}
@ -114,9 +115,9 @@ public class PlaybackServiceTaskManagerTest {
assertNotNull(queue);
testQueue = pstm.getQueue();
assertNotNull(testQueue);
assertTrue(queue.size() == testQueue.size());
assertEquals(testQueue.size(), queue.size());
for (int i = 0; i < queue.size(); i++) {
assertTrue(queue.get(i).getId() == testQueue.get(i).getId());
assertEquals(testQueue.get(i).getId(), queue.get(i).getId());
}
pstm.shutdown();
}

View File

@ -52,7 +52,7 @@ public class DBReaderTest {
assertNotNull(savedFeeds);
assertEquals(feeds.size(), savedFeeds.size());
for (int i = 0; i < feeds.size(); i++) {
assertTrue(savedFeeds.get(i).getId() == feeds.get(i).getId());
assertEquals(feeds.get(i).getId(), savedFeeds.get(i).getId());
}
}
@ -91,7 +91,7 @@ public class DBReaderTest {
List<Feed> feeds = saveFeedlist(10, 0, false);
List<String> urls = DBReader.getFeedListDownloadUrls();
assertNotNull(urls);
assertTrue(urls.size() == feeds.size());
assertEquals(feeds.size(), urls.size());
for (int i = 0; i < urls.size(); i++) {
assertEquals(urls.get(i), feeds.get(i).getDownload_url());
}
@ -115,8 +115,8 @@ public class DBReaderTest {
for (int j = 0; j < numItems; j++) {
FeedItem item = feeds.get(i).getItems().get(j);
assertNotNull(item.getFeed());
assertTrue(item.getFeed().getId() == feeds.get(i).getId());
assertTrue(item.getFeedId() == item.getFeed().getId());
assertEquals(feeds.get(i).getId(), item.getFeed().getId());
assertEquals(item.getFeed().getId(), item.getFeedId());
}
}
}
@ -130,9 +130,9 @@ public class DBReaderTest {
feed.setItems(null);
List<FeedItem> savedItems = DBReader.getFeedItemList(feed);
assertNotNull(savedItems);
assertTrue(savedItems.size() == items.size());
assertEquals(items.size(), savedItems.size());
for (int i = 0; i < savedItems.size(); i++) {
assertTrue(items.get(i).getId() == savedItems.get(i).getId());
assertEquals(savedItems.get(i).getId(), items.get(i).getId());
}
}
@ -167,10 +167,10 @@ public class DBReaderTest {
List<FeedItem> queue = saveQueue(numItems);
LongList ids = DBReader.getQueueIDList();
assertNotNull(ids);
assertTrue(queue.size() == ids.size());
assertEquals(ids.size(), queue.size());
for (int i = 0; i < queue.size(); i++) {
assertTrue(ids.get(i) != 0);
assertTrue(queue.get(i).getId() == ids.get(i));
assertEquals(ids.get(i), queue.get(i).getId());
}
}
@ -180,10 +180,10 @@ public class DBReaderTest {
List<FeedItem> queue = saveQueue(numItems);
List<FeedItem> savedQueue = DBReader.getQueue();
assertNotNull(savedQueue);
assertTrue(queue.size() == savedQueue.size());
assertEquals(savedQueue.size(), queue.size());
for (int i = 0; i < queue.size(); i++) {
assertTrue(savedQueue.get(i).getId() != 0);
assertTrue(queue.get(i).getId() == savedQueue.get(i).getId());
assertEquals(savedQueue.get(i).getId(), queue.get(i).getId());
}
}
@ -221,7 +221,7 @@ public class DBReaderTest {
List<FeedItem> downloaded = saveDownloadedItems(numItems);
List<FeedItem> downloaded_saved = DBReader.getDownloadedItems();
assertNotNull(downloaded_saved);
assertTrue(downloaded_saved.size() == downloaded.size());
assertEquals(downloaded.size(), downloaded_saved.size());
for (FeedItem item : downloaded_saved) {
assertNotNull(item.getMedia());
assertTrue(item.getMedia().isDownloaded());
@ -264,7 +264,7 @@ public class DBReaderTest {
}
List<FeedItem> newItemsSaved = DBReader.getNewItemsList(0, Integer.MAX_VALUE);
assertNotNull(newItemsSaved);
assertTrue(newItems.size() == newItemsSaved.size());
assertEquals(newItemsSaved.size(), newItems.size());
for (FeedItem feedItem : newItemsSaved) {
long savedId = feedItem.getId();
boolean found = false;

View File

@ -29,6 +29,8 @@ import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
@ -68,7 +70,7 @@ public class DBTasksTest {
}
Feed newFeed = DBTasks.updateFeed(context, feed)[0];
assertTrue(newFeed == feed);
assertSame(feed, newFeed);
assertTrue(feed.getId() != 0);
for (FeedItem item : feed.getItems()) {
assertFalse(item.isPlayed());
@ -123,13 +125,13 @@ public class DBTasksTest {
}
final Feed newFeed = DBTasks.updateFeed(context, feed)[0];
assertTrue(feed != newFeed);
assertNotSame(newFeed, feed);
updatedFeedTest(newFeed, feedID, itemIDs, NUM_ITEMS_OLD, NUM_ITEMS_NEW);
final Feed feedFromDB = DBReader.getFeed(newFeed.getId());
assertNotNull(feedFromDB);
assertTrue(feedFromDB.getId() == newFeed.getId());
assertEquals(newFeed.getId(), feedFromDB.getId());
updatedFeedTest(feedFromDB, feedID, itemIDs, NUM_ITEMS_OLD, NUM_ITEMS_NEW);
}
@ -155,7 +157,7 @@ public class DBTasksTest {
feed.setItems(list);
final Feed newFeed = DBTasks.updateFeed(context, feed)[0];
assertTrue(feed != newFeed);
assertNotSame(newFeed, feed);
final Feed feedFromDB = DBReader.getFeed(newFeed.getId());
final FeedItem feedItemFromDB = feedFromDB.getItems().get(0);
@ -163,21 +165,21 @@ public class DBTasksTest {
}
private void updatedFeedTest(final Feed newFeed, long feedID, List<Long> itemIDs, final int NUM_ITEMS_OLD, final int NUM_ITEMS_NEW) {
assertTrue(newFeed.getId() == feedID);
assertTrue(newFeed.getItems().size() == NUM_ITEMS_NEW + NUM_ITEMS_OLD);
assertEquals(feedID, newFeed.getId());
assertEquals(NUM_ITEMS_NEW + NUM_ITEMS_OLD, newFeed.getItems().size());
Collections.reverse(newFeed.getItems());
Date lastDate = new Date(0);
for (int i = 0; i < NUM_ITEMS_OLD; i++) {
FeedItem item = newFeed.getItems().get(i);
assertTrue(item.getFeed() == newFeed);
assertTrue(item.getId() == itemIDs.get(i));
assertSame(newFeed, item.getFeed());
assertEquals((long) itemIDs.get(i), item.getId());
assertTrue(item.isPlayed());
assertTrue(item.getPubDate().getTime() >= lastDate.getTime());
lastDate = item.getPubDate();
}
for (int i = NUM_ITEMS_OLD; i < NUM_ITEMS_NEW + NUM_ITEMS_OLD; i++) {
FeedItem item = newFeed.getItems().get(i);
assertTrue(item.getFeed() == newFeed);
assertSame(newFeed, item.getFeed());
assertTrue(item.getId() != 0);
assertFalse(item.isPlayed());
assertTrue(item.getPubDate().getTime() >= lastDate.getTime());

View File

@ -38,6 +38,7 @@ import de.danoeh.antennapod.core.util.FeedItemUtil;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@ -185,7 +186,7 @@ public class DBWriterTest {
assertFalse(media.isDownloaded());
assertNull(media.getFile_url());
queue = DBReader.getQueue();
assertTrue(queue.size() == 0);
assertEquals(0, queue.size());
}
@Test
@ -231,14 +232,14 @@ public class DBWriterTest {
adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor c = adapter.getFeedCursor(feed.getId());
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
for (FeedItem item : feed.getItems()) {
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
}
adapter.close();
@ -265,7 +266,7 @@ public class DBWriterTest {
adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor c = adapter.getFeedCursor(feed.getId());
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
adapter.close();
}
@ -303,11 +304,11 @@ public class DBWriterTest {
adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor c = adapter.getFeedCursor(feed.getId());
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
for (FeedItem item : feed.getItems()) {
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
}
adapter.close();
@ -350,7 +351,7 @@ public class DBWriterTest {
adapter.setQueue(queue);
Cursor queueCursor = adapter.getQueueIDCursor();
assertTrue(queueCursor.getCount() == queue.size());
assertEquals(queue.size(), queueCursor.getCount());
queueCursor.close();
adapter.close();
@ -358,18 +359,18 @@ public class DBWriterTest {
adapter.open();
Cursor c = adapter.getFeedCursor(feed.getId());
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
for (FeedItem item : feed.getItems()) {
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
}
c = adapter.getQueueCursor();
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
adapter.close();
}
@ -409,14 +410,14 @@ public class DBWriterTest {
adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor c = adapter.getFeedCursor(feed.getId());
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
for (FeedItem item : feed.getItems()) {
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
assertTrue(c.getCount() == 0);
assertEquals(0, c.getCount());
c.close();
}
adapter.close();
@ -465,7 +466,7 @@ public class DBWriterTest {
assertNotNull(media);
assertNotNull(media.getPlaybackCompletionDate());
assertFalse(OLD_DATE == media.getPlaybackCompletionDate().getTime());
assertNotEquals(media.getPlaybackCompletionDate().getTime(), OLD_DATE);
}
private Feed queueTestSetupMultipleItems(final int numItems) throws InterruptedException, ExecutionException, TimeoutException {
@ -516,7 +517,7 @@ public class DBWriterTest {
adapter.open();
Cursor cursor = adapter.getQueueIDCursor();
assertTrue(cursor.moveToFirst());
assertTrue(cursor.getLong(0) == item.getId());
assertEquals(item.getId(), cursor.getLong(0));
cursor.close();
adapter.close();
}
@ -541,7 +542,7 @@ public class DBWriterTest {
adapter.open();
Cursor cursor = adapter.getQueueIDCursor();
assertTrue(cursor.moveToFirst());
assertTrue(cursor.getLong(0) == item.getId());
assertEquals(item.getId(), cursor.getLong(0));
cursor.close();
adapter.close();
@ -550,8 +551,8 @@ public class DBWriterTest {
adapter.open();
cursor = adapter.getQueueIDCursor();
assertTrue(cursor.moveToFirst());
assertTrue(cursor.getLong(0) == item.getId());
assertTrue(cursor.getCount() == 1);
assertEquals(item.getId(), cursor.getLong(0));
assertEquals(1, cursor.getCount());
cursor.close();
adapter.close();
}
@ -565,7 +566,7 @@ public class DBWriterTest {
adapter.open();
Cursor cursor = adapter.getQueueIDCursor();
assertTrue(cursor.moveToFirst());
assertTrue(cursor.getCount() == NUM_ITEMS);
assertEquals(NUM_ITEMS, cursor.getCount());
List<Long> expectedIds = FeedItemUtil.getIdList(feed.getItems());
List<Long> actualIds = new ArrayList<>();
for (int i = 0; i < NUM_ITEMS; i++) {
@ -609,7 +610,7 @@ public class DBWriterTest {
adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor queue = adapter.getQueueIDCursor();
assertTrue(queue.getCount() == NUM_ITEMS - 1);
assertEquals(NUM_ITEMS - 1, queue.getCount());
for (int i = 0; i < queue.getCount(); i++) {
assertTrue(queue.moveToPosition(i));
final long queueID = queue.getLong(0);
@ -698,11 +699,11 @@ public class DBWriterTest {
adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor queue = adapter.getQueueIDCursor();
assertTrue(queue.getCount() == NUM_ITEMS);
assertEquals(NUM_ITEMS, queue.getCount());
assertTrue(queue.moveToPosition(from));
assertFalse(queue.getLong(0) == fromID);
assertNotEquals(fromID, queue.getLong(0));
assertTrue(queue.moveToPosition(to));
assertTrue(queue.getLong(0) == fromID);
assertEquals(fromID, queue.getLong(0));
queue.close();
adapter.close();

View File

@ -3,6 +3,8 @@ package de.danoeh.antennapod.core.util;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class LongLongMapTest {
@ -13,7 +15,7 @@ public class LongLongMapTest {
assertEquals("LongLongMap{}", map.toString());
assertEquals(0, map.get(42));
assertEquals(-1, map.get(42, -1));
assertEquals(false, map.delete(42));
assertFalse(map.delete(42));
assertEquals(-1, map.indexOfKey(42));
assertEquals(-1, map.indexOfValue(42));
assertEquals(1, map.hashCode());
@ -29,7 +31,7 @@ public class LongLongMapTest {
assertEquals(42, map.get(17, -1));
assertEquals(0, map.indexOfKey(17));
assertEquals(0, map.indexOfValue(42));
assertEquals(true, map.delete(17));
assertTrue(map.delete(17));
}
@Test
@ -45,7 +47,7 @@ public class LongLongMapTest {
assertEquals(1, map.indexOfKey(17));
assertEquals(1, map.indexOfValue(42));
for(int i=0; i < 100; i++) {
assertEquals(true, map.delete(i * 17));
assertTrue(map.delete(i * 17));
}
}