diff options
author | nchalko <nchalko@google.com> | 2018-02-23 15:15:37 -0800 |
---|---|---|
committer | Nick Chalko <nchalko@google.com> | 2018-02-26 15:42:35 -0800 |
commit | 9d283c91d496eac51237ced05d649081bb08d3e1 (patch) | |
tree | 4c668713ab3f304af1e2cbd4492856218c9ab2cc | |
parent | adcef7667a2fb24d830a37dc0356865f7618f5cd (diff) | |
download | TV-9d283c91d496eac51237ced05d649081bb08d3e1.tar.gz |
Cleanup change generated by Refaster (go/refaster) to directories //third_party/java_src/android_app/live_channels/tests/unit/src/...:all with template java/com/google/devtools/javatools/refactory/refaster/cleanups:TruthMigration
Also added some javadoc and stopped using MoreAsserts
PiperOrigin-RevId: 186830589
Change-Id: I277cf771e3eb7b2f1656810655fe68ac30811cca
11 files changed, 174 insertions, 167 deletions
diff --git a/tests/unit/src/com/android/tv/dvr/recorder/DvrRecordingServiceTest.java b/tests/unit/src/com/android/tv/dvr/recorder/DvrRecordingServiceTest.java index 3183d92e..d510da32 100644 --- a/tests/unit/src/com/android/tv/dvr/recorder/DvrRecordingServiceTest.java +++ b/tests/unit/src/com/android/tv/dvr/recorder/DvrRecordingServiceTest.java @@ -16,6 +16,8 @@ package com.android.tv.dvr.recorder; +import static com.google.common.truth.Truth.assertThat; + import android.content.Intent; import android.os.Build; import android.support.test.filters.SdkSuppress; @@ -53,13 +55,13 @@ public class DvrRecordingServiceTest public void testStartService_null() throws Exception { // Not recording startService(null); - assertFalse(getService().mInForeground); + assertThat(getService().mInForeground).isFalse(); // Recording getService().startRecording(); startService(null); - assertTrue(getService().mInForeground); - assertTrue(getService().mIsRecording); + assertThat(getService().mInForeground).isTrue(); + assertThat(getService().mIsRecording).isTrue(); getService().reset(); } @@ -69,38 +71,38 @@ public class DvrRecordingServiceTest // Not recording startService(intent); - assertTrue(getService().mInForeground); - assertFalse(getService().mForegroundForUpcomingRecording); + assertThat(getService().mInForeground).isTrue(); + assertThat(getService().mForegroundForUpcomingRecording).isFalse(); getService().stopForegroundIfNotRecordingInternal(); - assertFalse(getService().mInForeground); + assertThat(getService().mInForeground).isFalse(); // Recording, ended quickly getService().startRecording(); startService(intent); - assertTrue(getService().mInForeground); - assertTrue(getService().mForegroundForUpcomingRecording); - assertTrue(getService().mIsRecording); + assertThat(getService().mInForeground).isTrue(); + assertThat(getService().mForegroundForUpcomingRecording).isTrue(); + assertThat(getService().mIsRecording).isTrue(); getService().stopRecording(); - assertFalse(getService().mInForeground); - assertFalse(getService().mIsRecording); + assertThat(getService().mInForeground).isFalse(); + assertThat(getService().mIsRecording).isFalse(); getService().stopForegroundIfNotRecordingInternal(); - assertFalse(getService().mInForeground); - assertFalse(getService().mIsRecording); + assertThat(getService().mInForeground).isFalse(); + assertThat(getService().mIsRecording).isFalse(); getService().reset(); // Recording, ended later getService().startRecording(); startService(intent); - assertTrue(getService().mInForeground); - assertTrue(getService().mForegroundForUpcomingRecording); - assertTrue(getService().mIsRecording); + assertThat(getService().mInForeground).isTrue(); + assertThat(getService().mForegroundForUpcomingRecording).isTrue(); + assertThat(getService().mIsRecording).isTrue(); getService().stopForegroundIfNotRecordingInternal(); - assertTrue(getService().mInForeground); - assertTrue(getService().mForegroundForUpcomingRecording); - assertTrue(getService().mIsRecording); + assertThat(getService().mInForeground).isTrue(); + assertThat(getService().mForegroundForUpcomingRecording).isTrue(); + assertThat(getService().mIsRecording).isTrue(); getService().stopRecording(); - assertFalse(getService().mInForeground); - assertFalse(getService().mIsRecording); + assertThat(getService().mInForeground).isFalse(); + assertThat(getService().mIsRecording).isFalse(); getService().reset(); } @@ -110,38 +112,39 @@ public class DvrRecordingServiceTest // Not recording startService(intent); - assertTrue(getService().mInForeground); - assertTrue(getService().mForegroundForUpcomingRecording); - assertFalse(getService().mIsRecording); + assertThat(getService().mInForeground).isTrue(); + assertThat(getService().mForegroundForUpcomingRecording).isTrue(); + assertThat(getService().mIsRecording).isFalse(); getService().startRecording(); - assertTrue(getService().mInForeground); - assertTrue(getService().mForegroundForUpcomingRecording); - assertTrue(getService().mIsRecording); + assertThat(getService().mInForeground).isTrue(); + assertThat(getService().mForegroundForUpcomingRecording).isTrue(); + assertThat(getService().mIsRecording).isTrue(); getService().stopRecording(); - assertFalse(getService().mInForeground); - assertFalse(getService().mIsRecording); + assertThat(getService().mInForeground).isFalse(); + assertThat(getService().mIsRecording).isFalse(); getService().reset(); // Recording getService().startRecording(); startService(intent); - assertTrue(getService().mInForeground); - assertTrue(getService().mForegroundForUpcomingRecording); - assertTrue(getService().mIsRecording); + assertThat(getService().mInForeground).isTrue(); + assertThat(getService().mForegroundForUpcomingRecording).isTrue(); + assertThat(getService().mIsRecording).isTrue(); getService().startRecording(); - assertTrue(getService().mInForeground); - assertTrue(getService().mForegroundForUpcomingRecording); - assertTrue(getService().mIsRecording); + assertThat(getService().mInForeground).isTrue(); + assertThat(getService().mForegroundForUpcomingRecording).isTrue(); + assertThat(getService().mIsRecording).isTrue(); getService().stopRecording(); - assertTrue(getService().mInForeground); - assertTrue(getService().mForegroundForUpcomingRecording); - assertTrue(getService().mIsRecording); + assertThat(getService().mInForeground).isTrue(); + assertThat(getService().mForegroundForUpcomingRecording).isTrue(); + assertThat(getService().mIsRecording).isTrue(); getService().stopRecording(); - assertFalse(getService().mInForeground); - assertFalse(getService().mIsRecording); + assertThat(getService().mInForeground).isFalse(); + assertThat(getService().mIsRecording).isFalse(); getService().reset(); } + /** Mock {@link DvrRecordingService}. */ public static class MockDvrRecordingService extends DvrRecordingService { private int mRecordingCount = 0; private boolean mInForeground; diff --git a/tests/unit/src/com/android/tv/menu/MenuTest.java b/tests/unit/src/com/android/tv/menu/MenuTest.java index 494fbad0..028a185d 100644 --- a/tests/unit/src/com/android/tv/menu/MenuTest.java +++ b/tests/unit/src/com/android/tv/menu/MenuTest.java @@ -16,8 +16,7 @@ package com.android.tv.menu; import static android.support.test.InstrumentationRegistry.getTargetContext; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertWithMessage; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -55,22 +54,22 @@ public class MenuTest { public void testScheduleHide() { mMenu.show(Menu.REASON_NONE); setMenuVisible(true); - assertTrue("Hide is not scheduled", mMenu.isHideScheduled()); + assertWithMessage("Hide is not scheduled").that(mMenu.isHideScheduled()).isTrue(); mMenu.hide(false); setMenuVisible(false); - assertFalse("Hide is scheduled", mMenu.isHideScheduled()); + assertWithMessage("Hide is scheduled").that(mMenu.isHideScheduled()).isFalse(); mMenu.setKeepVisible(true); mMenu.show(Menu.REASON_NONE); setMenuVisible(true); - assertFalse("Hide is scheduled", mMenu.isHideScheduled()); + assertWithMessage("Hide is scheduled").that(mMenu.isHideScheduled()).isFalse(); mMenu.setKeepVisible(false); - assertTrue("Hide is not scheduled", mMenu.isHideScheduled()); + assertWithMessage("Hide is not scheduled").that(mMenu.isHideScheduled()).isTrue(); mMenu.setKeepVisible(true); - assertFalse("Hide is scheduled", mMenu.isHideScheduled()); + assertWithMessage("Hide is scheduled").that(mMenu.isHideScheduled()).isFalse(); mMenu.hide(false); setMenuVisible(false); - assertFalse("Hide is scheduled", mMenu.isHideScheduled()); + assertWithMessage("Hide is scheduled").that(mMenu.isHideScheduled()).isFalse(); } @Test diff --git a/tests/unit/src/com/android/tv/menu/TvOptionsRowAdapterTest.java b/tests/unit/src/com/android/tv/menu/TvOptionsRowAdapterTest.java index 7086e344..0f815a7a 100644 --- a/tests/unit/src/com/android/tv/menu/TvOptionsRowAdapterTest.java +++ b/tests/unit/src/com/android/tv/menu/TvOptionsRowAdapterTest.java @@ -16,7 +16,7 @@ package com.android.tv.menu; import static android.support.test.InstrumentationRegistry.getInstrumentation; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.fail; import android.media.tv.TvTrackInfo; @@ -73,9 +73,10 @@ public class TvOptionsRowAdapterTest extends BaseMainActivityTestCase { waitUntilAudioTrackSelected(Constants.EN_STEREO_AUDIO_TRACK.getId()); boolean result = mTvOptionsRowAdapter.updateMultiAudioAction(); - assertEquals("update Action had change", true, result); - assertEquals( - "Multi Audio enabled", true, MenuAction.SELECT_AUDIO_LANGUAGE_ACTION.isEnabled()); + assertWithMessage("update Action had change").that(result).isTrue(); + assertWithMessage("Multi Audio enabled") + .that(MenuAction.SELECT_AUDIO_LANGUAGE_ACTION.isEnabled()) + .isTrue(); } @Test @@ -90,9 +91,10 @@ public class TvOptionsRowAdapterTest extends BaseMainActivityTestCase { waitUntilAudioTrackSelected(Constants.GENERIC_AUDIO_TRACK.getId()); boolean result = mTvOptionsRowAdapter.updateMultiAudioAction(); - assertEquals("update Action had change", true, result); - assertEquals( - "Multi Audio enabled", false, MenuAction.SELECT_AUDIO_LANGUAGE_ACTION.isEnabled()); + assertWithMessage("update Action had change").that(result).isTrue(); + assertWithMessage("Multi Audio enabled") + .that(MenuAction.SELECT_AUDIO_LANGUAGE_ACTION.isEnabled()) + .isFalse(); } @Test @@ -108,9 +110,10 @@ public class TvOptionsRowAdapterTest extends BaseMainActivityTestCase { waitUntilVideoTrackSelected(data.mSelectedVideoTrackId); boolean result = mTvOptionsRowAdapter.updateMultiAudioAction(); - assertEquals("update Action had change", true, result); - assertEquals( - "Multi Audio enabled", false, MenuAction.SELECT_AUDIO_LANGUAGE_ACTION.isEnabled()); + assertWithMessage("update Action had change").that(result).isTrue(); + assertWithMessage("Multi Audio enabled") + .that(MenuAction.SELECT_AUDIO_LANGUAGE_ACTION.isEnabled()) + .isFalse(); } private void waitUntilAudioTracksHaveSize(int expected) { diff --git a/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java b/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java index ac0e0cac..e63bdc3a 100644 --- a/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java +++ b/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java @@ -17,7 +17,7 @@ package com.android.tv.recommendation; import static android.support.test.InstrumentationRegistry.getContext; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertThat; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -47,14 +47,14 @@ public class ChannelRecordTest { @Test public void testGetLastWatchEndTime_noHistory() { - assertEquals(0, mChannelRecord.getLastWatchEndTimeMs()); + assertThat(mChannelRecord.getLastWatchEndTimeMs()).isEqualTo(0); } @Test public void testGetLastWatchEndTime_oneHistory() { addWatchLog(); - assertEquals(mLatestWatchEndTimeMs, mChannelRecord.getLastWatchEndTimeMs()); + assertThat(mChannelRecord.getLastWatchEndTimeMs()).isEqualTo(mLatestWatchEndTimeMs); } @Test @@ -63,7 +63,7 @@ public class ChannelRecordTest { addWatchLog(); } - assertEquals(mLatestWatchEndTimeMs, mChannelRecord.getLastWatchEndTimeMs()); + assertThat(mChannelRecord.getLastWatchEndTimeMs()).isEqualTo(mLatestWatchEndTimeMs); } @Test @@ -72,19 +72,19 @@ public class ChannelRecordTest { addWatchLog(); } - assertEquals(mLatestWatchEndTimeMs, mChannelRecord.getLastWatchEndTimeMs()); + assertThat(mChannelRecord.getLastWatchEndTimeMs()).isEqualTo(mLatestWatchEndTimeMs); } @Test public void testGetTotalWatchDuration_noHistory() { - assertEquals(0, mChannelRecord.getTotalWatchDurationMs()); + assertThat(mChannelRecord.getTotalWatchDurationMs()).isEqualTo(0); } @Test public void testGetTotalWatchDuration_oneHistory() { long durationMs = addWatchLog(); - assertEquals(durationMs, mChannelRecord.getTotalWatchDurationMs()); + assertThat(mChannelRecord.getTotalWatchDurationMs()).isEqualTo(durationMs); } @Test @@ -95,7 +95,7 @@ public class ChannelRecordTest { totalWatchTimeMs += durationMs; } - assertEquals(totalWatchTimeMs, mChannelRecord.getTotalWatchDurationMs()); + assertThat(mChannelRecord.getTotalWatchDurationMs()).isEqualTo(totalWatchTimeMs); } @Test @@ -110,8 +110,9 @@ public class ChannelRecordTest { } } - // Only latest CHANNEL_RECORD_MAX_HISTORY_SIZE logs are remained. - assertEquals(totalWatchTimeMs - firstDurationMs, mChannelRecord.getTotalWatchDurationMs()); + // Only latest CHANNEL_RECORD_MAX_HISTORY_SIZE logs are remained. + assertThat(mChannelRecord.getTotalWatchDurationMs()) + .isEqualTo(totalWatchTimeMs - firstDurationMs); } /** diff --git a/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java b/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java index e3560467..e14320f0 100644 --- a/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java +++ b/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java @@ -16,7 +16,7 @@ package com.android.tv.recommendation; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -106,7 +106,7 @@ public class FavoriteChannelEvaluatorTest extends EvaluatorTestCase<FavoriteChan double previousScore = Recommender.Evaluator.NOT_RECOMMENDED; for (long channelId : channelIdList) { double score = mEvaluator.evaluateChannel(channelId); - assertTrue(previousScore <= score); + assertThat(previousScore).isAtMost(score); previousScore = score; } } @@ -125,8 +125,8 @@ public class FavoriteChannelEvaluatorTest extends EvaluatorTestCase<FavoriteChan TimeUnit.MINUTES.toMillis(30)); notifyChannelAndWatchLogLoaded(); - assertTrue( - mEvaluator.evaluateChannel(channelOne) == mEvaluator.evaluateChannel(channelTwo)); + assertThat(mEvaluator.evaluateChannel(channelOne) == mEvaluator.evaluateChannel(channelTwo)) + .isTrue(); } @Test @@ -143,16 +143,18 @@ public class FavoriteChannelEvaluatorTest extends EvaluatorTestCase<FavoriteChan TimeUnit.HOURS.toMillis(1)); notifyChannelAndWatchLogLoaded(); - // Channel two was watched longer than channel one, so it's score is bigger. - assertTrue(mEvaluator.evaluateChannel(channelOne) < mEvaluator.evaluateChannel(channelTwo)); + // Channel two was watched longer than channel one, so it's score is bigger. + assertThat(mEvaluator.evaluateChannel(channelOne)) + .isLessThan(mEvaluator.evaluateChannel(channelTwo)); addWatchLog( channelOne, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1), TimeUnit.HOURS.toMillis(1)); - // Now, channel one was watched longer than channel two, so it's score is bigger. - assertTrue(mEvaluator.evaluateChannel(channelOne) > mEvaluator.evaluateChannel(channelTwo)); + // Now, channel one was watched longer than channel two, so it's score is bigger. + assertThat(mEvaluator.evaluateChannel(channelOne)) + .isGreaterThan(mEvaluator.evaluateChannel(channelTwo)); } @Test @@ -169,7 +171,7 @@ public class FavoriteChannelEvaluatorTest extends EvaluatorTestCase<FavoriteChan addWatchLog(channelId, latestWatchEndTimeMs, TimeUnit.MINUTES.toMillis(10)); - // Score must be increased because total watch duration of the channel increases. - assertTrue(previousScore <= mEvaluator.evaluateChannel(channelId)); + // Score must be increased because total watch duration of the channel increases. + assertThat(previousScore).isAtMost(mEvaluator.evaluateChannel(channelId)); } } diff --git a/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java b/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java index 7fa09b7a..f8d6b220 100644 --- a/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java +++ b/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java @@ -16,7 +16,7 @@ package com.android.tv.recommendation; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -106,7 +106,7 @@ public class RecentChannelEvaluatorTest extends EvaluatorTestCase<RecentChannelE double previousScore = Recommender.Evaluator.NOT_RECOMMENDED; for (long channelId : channelIdList) { double score = mEvaluator.evaluateChannel(channelId); - assertTrue(previousScore <= score); + assertThat(previousScore).isAtMost(score); previousScore = score; } } @@ -129,8 +129,8 @@ public class RecentChannelEvaluatorTest extends EvaluatorTestCase<RecentChannelE addWatchLog(channelId, latestWatchEndTimeMs, durationMs); latestWatchEndTimeMs += durationMs; - // Score must be increased because recentness of the log increases. - assertTrue(previousScore <= mEvaluator.evaluateChannel(channelId)); + // Score must be increased because recentness of the log increases. + assertThat(previousScore).isAtMost(mEvaluator.evaluateChannel(channelId)); } } @@ -155,8 +155,8 @@ public class RecentChannelEvaluatorTest extends EvaluatorTestCase<RecentChannelE addWatchLog(newChannelId, latestWatchedEndTimeMs, TimeUnit.MINUTES.toMillis(10)); for (long channelId : channelIdList) { - // Score must be decreased because LastWatchLogUpdateTime increases by new log. - assertTrue(mEvaluator.evaluateChannel(channelId) <= scores.get(channelId)); + // Score must be decreased because LastWatchLogUpdateTime increases by new log. + assertThat(mEvaluator.evaluateChannel(channelId)).isAtMost(scores.get(channelId)); } } } diff --git a/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java b/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java index f70c8e26..812a3eb1 100644 --- a/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java +++ b/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java @@ -17,9 +17,7 @@ package com.android.tv.recommendation; import static android.support.test.InstrumentationRegistry.getContext; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -94,26 +92,26 @@ public class RecommenderTest { public void testRecommendChannels_includeRecommendedOnly_allChannelsHaveNoScore() { createRecommender(true, mStartDatamanagerRunnableAddFourChannels); - // Recommender doesn't recommend any channels because all channels are not recommended. - assertEquals(0, mRecommender.recommendChannels().size()); - assertEquals(0, mRecommender.recommendChannels(-5).size()); - assertEquals(0, mRecommender.recommendChannels(0).size()); - assertEquals(0, mRecommender.recommendChannels(3).size()); - assertEquals(0, mRecommender.recommendChannels(4).size()); - assertEquals(0, mRecommender.recommendChannels(5).size()); + // Recommender doesn't recommend any channels because all channels are not recommended. + assertThat(mRecommender.recommendChannels()).isEmpty(); + assertThat(mRecommender.recommendChannels(-5)).isEmpty(); + assertThat(mRecommender.recommendChannels(0)).isEmpty(); + assertThat(mRecommender.recommendChannels(3)).isEmpty(); + assertThat(mRecommender.recommendChannels(4)).isEmpty(); + assertThat(mRecommender.recommendChannels(5)).isEmpty(); } @Test public void testRecommendChannels_notIncludeRecommendedOnly_allChannelsHaveNoScore() { createRecommender(false, mStartDatamanagerRunnableAddFourChannels); - // Recommender recommends every channel because it recommends not-recommended channels too. - assertEquals(4, mRecommender.recommendChannels().size()); - assertEquals(0, mRecommender.recommendChannels(-5).size()); - assertEquals(0, mRecommender.recommendChannels(0).size()); - assertEquals(3, mRecommender.recommendChannels(3).size()); - assertEquals(4, mRecommender.recommendChannels(4).size()); - assertEquals(4, mRecommender.recommendChannels(5).size()); + // Recommender recommends every channel because it recommends not-recommended channels too. + assertThat(mRecommender.recommendChannels()).hasSize(4); + assertThat(mRecommender.recommendChannels(-5)).isEmpty(); + assertThat(mRecommender.recommendChannels(0)).isEmpty(); + assertThat(mRecommender.recommendChannels(3)).hasSize(3); + assertThat(mRecommender.recommendChannels(4)).hasSize(4); + assertThat(mRecommender.recommendChannels(5)).hasSize(4); } @Test @@ -126,8 +124,8 @@ public class RecommenderTest { // (i.e. sorted by channel ID in decreasing order in this case) MoreAsserts.assertContentsInOrder( mRecommender.recommendChannels(), mChannel_4, mChannel_3, mChannel_2, mChannel_1); - assertEquals(0, mRecommender.recommendChannels(-5).size()); - assertEquals(0, mRecommender.recommendChannels(0).size()); + assertThat(mRecommender.recommendChannels(-5)).isEmpty(); + assertThat(mRecommender.recommendChannels(0)).isEmpty(); MoreAsserts.assertContentsInOrder( mRecommender.recommendChannels(3), mChannel_4, mChannel_3, mChannel_2); MoreAsserts.assertContentsInOrder( @@ -146,8 +144,8 @@ public class RecommenderTest { // (i.e. sorted by channel ID in decreasing order in this case) MoreAsserts.assertContentsInOrder( mRecommender.recommendChannels(), mChannel_4, mChannel_3, mChannel_2, mChannel_1); - assertEquals(0, mRecommender.recommendChannels(-5).size()); - assertEquals(0, mRecommender.recommendChannels(0).size()); + assertThat(mRecommender.recommendChannels(-5)).isEmpty(); + assertThat(mRecommender.recommendChannels(0)).isEmpty(); MoreAsserts.assertContentsInOrder( mRecommender.recommendChannels(3), mChannel_4, mChannel_3, mChannel_2); MoreAsserts.assertContentsInOrder( @@ -166,8 +164,8 @@ public class RecommenderTest { // Only two channels are recommended because recommender doesn't recommend other channels. MoreAsserts.assertContentsInAnyOrder( mRecommender.recommendChannels(), mChannel_1, mChannel_2); - assertEquals(0, mRecommender.recommendChannels(-5).size()); - assertEquals(0, mRecommender.recommendChannels(0).size()); + assertThat(mRecommender.recommendChannels(-5)).isEmpty(); + assertThat(mRecommender.recommendChannels(0)).isEmpty(); MoreAsserts.assertContentsInAnyOrder( mRecommender.recommendChannels(3), mChannel_1, mChannel_2); MoreAsserts.assertContentsInAnyOrder( @@ -183,22 +181,22 @@ public class RecommenderTest { mEvaluator.setChannelScore(mChannel_1.getId(), 1.0); mEvaluator.setChannelScore(mChannel_2.getId(), 1.0); - assertEquals(4, mRecommender.recommendChannels().size()); + assertThat(mRecommender.recommendChannels()).hasSize(4); MoreAsserts.assertContentsInAnyOrder( mRecommender.recommendChannels().subList(0, 2), mChannel_1, mChannel_2); - assertEquals(0, mRecommender.recommendChannels(-5).size()); - assertEquals(0, mRecommender.recommendChannels(0).size()); + assertThat(mRecommender.recommendChannels(-5)).isEmpty(); + assertThat(mRecommender.recommendChannels(0)).isEmpty(); - assertEquals(3, mRecommender.recommendChannels(3).size()); + assertThat(mRecommender.recommendChannels(3)).hasSize(3); MoreAsserts.assertContentsInAnyOrder( mRecommender.recommendChannels(3).subList(0, 2), mChannel_1, mChannel_2); - assertEquals(4, mRecommender.recommendChannels(4).size()); + assertThat(mRecommender.recommendChannels(4)).hasSize(4); MoreAsserts.assertContentsInAnyOrder( mRecommender.recommendChannels(4).subList(0, 2), mChannel_1, mChannel_2); - assertEquals(4, mRecommender.recommendChannels(5).size()); + assertThat(mRecommender.recommendChannels(5)).hasSize(4); MoreAsserts.assertContentsInAnyOrder( mRecommender.recommendChannels(5).subList(0, 2), mChannel_1, mChannel_2); } @@ -226,10 +224,9 @@ public class RecommenderTest { setChannelScores_scoreIncreasesAsChannelIdIncreases(); List<Channel> expectedChannelList = mRecommender.recommendChannels(3); - // A channel which is not recommended by the recommender has to get an invalid sort key. - assertEquals( - Recommender.INVALID_CHANNEL_SORT_KEY, - mRecommender.getChannelSortKey(mChannel_1.getId())); + // A channel which is not recommended by the recommender has to get an invalid sort key. + assertThat(mRecommender.getChannelSortKey(mChannel_1.getId())) + .isEqualTo(Recommender.INVALID_CHANNEL_SORT_KEY); List<Channel> channelList = Arrays.asList(mChannel_2, mChannel_3, mChannel_4); Collections.sort(channelList, mChannelSortKeyComparator); @@ -241,9 +238,9 @@ public class RecommenderTest { @Test public void testListener_onRecommendationChanged() { createRecommender(true, mStartDatamanagerRunnableAddFourChannels); - // FakeEvaluator doesn't recommend a channel with empty watch log. As every channel - // doesn't have a watch log, nothing is recommended and recommendation isn't changed. - assertFalse(mOnRecommendationChanged); + // FakeEvaluator doesn't recommend a channel with empty watch log. As every channel + // doesn't have a watch log, nothing is recommended and recommendation isn't changed. + assertThat(mOnRecommendationChanged).isFalse(); // Set lastRecommendationUpdatedTimeUtcMs to check recommendation changed because, // recommender has a minimum recommendation update period. @@ -252,16 +249,17 @@ public class RecommenderTest { long latestWatchEndTimeMs = DEFAULT_WATCH_START_TIME_MS; for (long channelId : mChannelRecordSortedMap.keySet()) { mEvaluator.setChannelScore(channelId, 1.0); - // Add a log to recalculate the recommendation score. - assertTrue( - mChannelRecordSortedMap.addWatchLog( - channelId, latestWatchEndTimeMs, TimeUnit.MINUTES.toMillis(10))); + // Add a log to recalculate the recommendation score. + assertThat( + mChannelRecordSortedMap.addWatchLog( + channelId, latestWatchEndTimeMs, TimeUnit.MINUTES.toMillis(10))) + .isTrue(); latestWatchEndTimeMs += TimeUnit.MINUTES.toMillis(10); } - // onRecommendationChanged must be called, because recommend channels are not empty, - // by setting score to each channel. - assertTrue(mOnRecommendationChanged); + // onRecommendationChanged must be called, because recommend channels are not empty, + // by setting score to each channel. + assertThat(mOnRecommendationChanged).isTrue(); } @Test @@ -279,8 +277,8 @@ public class RecommenderTest { } }); - // After loading channels and watch logs are finished, recommender must be available to use. - assertTrue(mOnRecommenderReady); + // After loading channels and watch logs are finished, recommender must be available to use. + assertThat(mOnRecommenderReady).isTrue(); } private void assertSortKeyNotInvalid(List<Channel> channelList) { diff --git a/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java b/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java index 91d61c06..9af5fd06 100644 --- a/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java +++ b/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java @@ -16,21 +16,20 @@ package com.android.tv.recommendation; +import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; -import android.test.MoreAsserts; import com.android.tv.data.Program; import com.android.tv.recommendation.RoutineWatchEvaluator.ProgramTime; -import java.util.Arrays; import java.util.Calendar; import java.util.List; -import java.util.TreeSet; import java.util.concurrent.TimeUnit; import org.junit.Test; import org.junit.runner.RunWith; +/**Tests for {@link RoutineWatchEvaluator}. */ @SmallTest @RunWith(AndroidJUnit4.class) public class RoutineWatchEvaluatorTest extends EvaluatorTestCase<RoutineWatchEvaluator> { @@ -112,11 +111,15 @@ public class RoutineWatchEvaluatorTest extends EvaluatorTestCase<RoutineWatchEva @Test public void testCalculateTitleMatchScore_longerMatchIsBetter() { String base = "foo bar baz"; - assertInOrder( - score(base, ""), - score(base, "bar"), - score(base, "foo bar"), - score(base, "foo bar baz")); + assertThat( + new ScoredItem[] { + score(base, ""), + score(base, "bar"), + score(base, "foo bar"), + score(base, "foo bar baz") + }) + .asList() + .isOrdered(); } @Test @@ -231,7 +234,7 @@ public class RoutineWatchEvaluatorTest extends EvaluatorTestCase<RoutineWatchEva private void assertSplitTextToWords(String text, String... words) { List<String> wordList = RoutineWatchEvaluator.splitTextToWords(text); - MoreAsserts.assertContentsInOrder(wordList, words); + assertThat(wordList).containsExactly((Object) words).inOrder(); } private void assertMaximumMatchedWordSequenceLength( @@ -317,9 +320,4 @@ public class RoutineWatchEvaluatorTest extends EvaluatorTestCase<RoutineWatchEva .setEndTimeUtcMillis(startTimeMs + programDurationMs) .build(); } - - private static <T> void assertInOrder(T... items) { - TreeSet<T> copy = new TreeSet<>(Arrays.asList(items)); - MoreAsserts.assertContentsInOrder(copy, items); - } } diff --git a/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java b/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java index c4623bc7..d84a90d4 100644 --- a/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java +++ b/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java @@ -16,7 +16,7 @@ package com.android.tv.util; import static com.android.tv.util.TvTrackInfoUtils.getBestTrackInfo; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertWithMessage; import android.media.tv.TvTrackInfo; import android.support.test.filters.SmallTest; @@ -60,49 +60,49 @@ public class TvTrackInfoUtilsTest { @Test public void testGetBestTrackInfo_empty() { TvTrackInfo result = getBestTrackInfo(Collections.emptyList(), UN_MATCHED_ID, "en", 1); - assertEquals("best track ", null, result); + assertWithMessage("best track ").that(result).isEqualTo(null); } @Test public void testGetBestTrackInfo_exactMatch() { TvTrackInfo result = getBestTrackInfo(ALL, "1", "en", 1); - assertEquals("best track ", INFO_1_EN_1, result); + assertWithMessage("best track ").that(result).isEqualTo(INFO_1_EN_1); } @Test public void testGetBestTrackInfo_langAndChannelCountMatch() { TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "en", 5); - assertEquals("best track ", INFO_2_EN_5, result); + assertWithMessage("best track ").that(result).isEqualTo(INFO_2_EN_5); } @Test public void testGetBestTrackInfo_languageOnlyMatch() { TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "fr", 1); - assertEquals("best track ", INFO_3_FR_8, result); + assertWithMessage("best track ").that(result).isEqualTo(INFO_3_FR_8); } @Test public void testGetBestTrackInfo_channelCountOnlyMatchWithNullLanguage() { TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, null, 8); - assertEquals("best track ", INFO_3_FR_8, result); + assertWithMessage("best track ").that(result).isEqualTo(INFO_3_FR_8); } @Test public void testGetBestTrackInfo_noMatches() { TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "kr", 1); - assertEquals("best track ", INFO_1_EN_1, result); + assertWithMessage("best track ").that(result).isEqualTo(INFO_1_EN_1); } @Test public void testGetBestTrackInfo_noMatchesWithNullLanguage() { TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, null, 0); - assertEquals("best track ", INFO_1_EN_1, result); + assertWithMessage("best track ").that(result).isEqualTo(INFO_1_EN_1); } @Test public void testGetBestTrackInfo_channelCountAndIdMatch() { TvTrackInfo result = getBestTrackInfo(NULL_LANGUAGE_TRACKS, "5", null, 6); - assertEquals("best track ", INFO_5_NULL_6, result); + assertWithMessage("best track ").that(result).isEqualTo(INFO_5_NULL_6); } @Test diff --git a/tests/unit/src/com/android/tv/util/images/ImageCacheTest.java b/tests/unit/src/com/android/tv/util/images/ImageCacheTest.java index b094adc3..b7715c4a 100644 --- a/tests/unit/src/com/android/tv/util/images/ImageCacheTest.java +++ b/tests/unit/src/com/android/tv/util/images/ImageCacheTest.java @@ -17,7 +17,7 @@ package com.android.tv.util.images; import static com.android.tv.util.images.BitmapUtils.createScaledBitmapInfo; -import static org.junit.Assert.assertSame; +import static com.google.common.truth.Truth.assertWithMessage; import android.graphics.Bitmap; import android.support.test.filters.MediumTest; @@ -52,28 +52,28 @@ public class ImageCacheTest { public void testPutIfLarger_smaller() throws Exception { mImageCache.putIfNeeded(INFO_50); - assertSame("before", INFO_50, mImageCache.get(KEY)); + assertWithMessage("before").that(mImageCache.get(KEY)).isSameAs(INFO_50); mImageCache.putIfNeeded(INFO_25); - assertSame("after", INFO_50, mImageCache.get(KEY)); + assertWithMessage("after").that(mImageCache.get(KEY)).isSameAs(INFO_50); } @Test public void testPutIfLarger_larger() throws Exception { mImageCache.putIfNeeded(INFO_50); - assertSame("before", INFO_50, mImageCache.get(KEY)); + assertWithMessage("before").that(mImageCache.get(KEY)).isSameAs(INFO_50); mImageCache.putIfNeeded(INFO_100); - assertSame("after", INFO_100, mImageCache.get(KEY)); + assertWithMessage("after").that(mImageCache.get(KEY)).isSameAs(INFO_100); } @Test public void testPutIfLarger_alreadyMax() throws Exception { mImageCache.putIfNeeded(INFO_100); - assertSame("before", INFO_100, mImageCache.get(KEY)); + assertWithMessage("before").that(mImageCache.get(KEY)).isSameAs(INFO_100); mImageCache.putIfNeeded(INFO_200); - assertSame("after", INFO_100, mImageCache.get(KEY)); + assertWithMessage("after").that(mImageCache.get(KEY)).isSameAs(INFO_100); } } diff --git a/tests/unit/src/com/android/tv/util/images/ScaledBitmapInfoTest.java b/tests/unit/src/com/android/tv/util/images/ScaledBitmapInfoTest.java index 0bde0981..005775b6 100644 --- a/tests/unit/src/com/android/tv/util/images/ScaledBitmapInfoTest.java +++ b/tests/unit/src/com/android/tv/util/images/ScaledBitmapInfoTest.java @@ -15,7 +15,7 @@ */ package com.android.tv.util.images; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertWithMessage; import android.graphics.Bitmap; import android.support.test.filters.SmallTest; @@ -58,10 +58,9 @@ public class ScaledBitmapInfoTest { private static void assertNeedsToReload( boolean expected, ScaledBitmapInfo scaledBitmap, int reqWidth, int reqHeight) { - assertEquals( - scaledBitmap.id + " needToReload(" + reqWidth + "," + reqHeight + ")", - expected, - scaledBitmap.needToReload(reqWidth, reqHeight)); + assertWithMessage(scaledBitmap.id + " needToReload(" + reqWidth + "," + reqHeight + ")") + .that(scaledBitmap.needToReload(reqWidth, reqHeight)) + .isEqualTo(expected); } private static void assertScaledBitmapSize( @@ -69,8 +68,12 @@ public class ScaledBitmapInfoTest { int expectedWidth, int expectedHeight, ScaledBitmapInfo actual) { - assertEquals(actual.id + " inSampleSize", expectedInSampleSize, actual.inSampleSize); - assertEquals(actual.id + " width", expectedWidth, actual.bitmap.getWidth()); - assertEquals(actual.id + " height", expectedHeight, actual.bitmap.getHeight()); + assertWithMessage(actual.id + " inSampleSize") + .that(actual.inSampleSize) + .isEqualTo(expectedInSampleSize); + assertWithMessage(actual.id + " width").that(actual.bitmap.getWidth()).isEqualTo(expectedWidth); + assertWithMessage(actual.id + " height") + .that(actual.bitmap.getHeight()) + .isEqualTo(expectedHeight); } } |