diff --git a/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/ExpandableSwitchItemTest.java b/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/ExpandableSwitchItemTest.java index f988563..c43b4ab 100644 --- a/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/ExpandableSwitchItemTest.java +++ b/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/ExpandableSwitchItemTest.java @@ -27,14 +27,14 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.android.setupwizardlib.R; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import com.android.setupwizardlib.view.CheckableLinearLayout; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) public class ExpandableSwitchItemTest { diff --git a/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/SwitchItemTest.java b/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/SwitchItemTest.java index 0acc5fc..422d979 100644 --- a/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/SwitchItemTest.java +++ b/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/SwitchItemTest.java @@ -34,14 +34,14 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.android.setupwizardlib.R; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) public class SwitchItemTest { diff --git a/library/gingerbread/test/robotest/src/com/android/setupwizardlib/util/DimensionConsistencyTest.java b/library/gingerbread/test/robotest/src/com/android/setupwizardlib/util/DimensionConsistencyTest.java index af19905..1f76d35 100644 --- a/library/gingerbread/test/robotest/src/com/android/setupwizardlib/util/DimensionConsistencyTest.java +++ b/library/gingerbread/test/robotest/src/com/android/setupwizardlib/util/DimensionConsistencyTest.java @@ -25,13 +25,13 @@ import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.ContextThemeWrapper; import com.android.setupwizardlib.R; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = Config.ALL_SDKS) public class DimensionConsistencyTest { diff --git a/library/recyclerview/test/robotest/src/com/android/setupwizardlib/template/RecyclerViewScrollHandlingDelegateTest.java b/library/recyclerview/test/robotest/src/com/android/setupwizardlib/template/RecyclerViewScrollHandlingDelegateTest.java index dd262da..bcb51a8 100644 --- a/library/recyclerview/test/robotest/src/com/android/setupwizardlib/template/RecyclerViewScrollHandlingDelegateTest.java +++ b/library/recyclerview/test/robotest/src/com/android/setupwizardlib/template/RecyclerViewScrollHandlingDelegateTest.java @@ -26,17 +26,17 @@ import static org.robolectric.RuntimeEnvironment.application; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.OnScrollListener; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class RecyclerViewScrollHandlingDelegateTest { @Mock private RequireScrollMixin mRequireScrollMixin; diff --git a/library/test/robotest/src/com/android/setupwizardlib/GlifLayoutTest.java b/library/test/robotest/src/com/android/setupwizardlib/GlifLayoutTest.java index ccc6ce7..d77838f 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/GlifLayoutTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/GlifLayoutTest.java @@ -16,14 +16,8 @@ package com.android.setupwizardlib; -import static org.hamcrest.Matchers.instanceOf; -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.assertThat; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static org.robolectric.RuntimeEnvironment.application; import android.content.Context; @@ -40,7 +34,6 @@ import android.view.View; import android.widget.ProgressBar; import android.widget.ScrollView; import android.widget.TextView; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import com.android.setupwizardlib.template.ColoredHeaderMixin; import com.android.setupwizardlib.template.HeaderMixin; import com.android.setupwizardlib.template.IconMixin; @@ -50,16 +43,17 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) public class GlifLayoutTest { private Context context; @Before - public void setUp() throws Exception { + public void setUpContext() { context = new ContextThemeWrapper(application, R.style.SuwThemeGlif_Light); } @@ -72,9 +66,11 @@ public class GlifLayoutTest { @Test public void testSetHeaderText() { GlifLayout layout = new GlifLayout(context); - TextView title = (TextView) layout.findViewById(R.id.suw_layout_title); + TextView title = layout.findViewById(R.id.suw_layout_title); layout.setHeaderText("Abracadabra"); - assertEquals("Header text should be \"Abracadabra\"", "Abracadabra", title.getText()); + assertWithMessage("Header text should be \"Abracadabra\"") + .that(title.getText().toString()) + .isEqualTo("Abracadabra"); } @Test @@ -86,14 +82,15 @@ public class GlifLayoutTest { layout.addView(tv); assertDefaultTemplateInflated(layout); View view = layout.findViewById(testViewId); - assertSame("The view added should be the same text view", tv, view); + assertThat(view).named("Text view added").isSameAs(tv); } @Test public void testGetScrollView() { GlifLayout layout = new GlifLayout(context); - assertNotNull( - "Get scroll view should not be null with default template", layout.getScrollView()); + assertWithMessage("Get scroll view should not be null with default template") + .that(layout.getScrollView()) + .isNotNull(); } @Test @@ -101,19 +98,18 @@ public class GlifLayoutTest { GlifLayout layout = new GlifLayout(context); layout.setProgressBarShown(true); layout.setPrimaryColor(ColorStateList.valueOf(Color.RED)); - assertEquals( - "Primary color should be red", ColorStateList.valueOf(Color.RED), layout.getPrimaryColor()); + assertWithMessage("Primary color should be red") + .that(layout.getPrimaryColor()) + .isEqualTo(ColorStateList.valueOf(Color.RED)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - ProgressBar progressBar = (ProgressBar) layout.findViewById(R.id.suw_layout_progress); - assertEquals( - "Progress bar should be tinted red", - ColorStateList.valueOf(Color.RED), - progressBar.getIndeterminateTintList()); - assertEquals( - "Determinate progress bar should also be tinted red", - ColorStateList.valueOf(Color.RED), - progressBar.getProgressBackgroundTintList()); + ProgressBar progressBar = layout.findViewById(R.id.suw_layout_progress); + assertThat(progressBar.getIndeterminateTintList()) + .named("indeterminate progress bar tint") + .isEqualTo(ColorStateList.valueOf(Color.RED)); + assertThat(progressBar.getProgressBackgroundTintList()) + .named("determinate progress bar tint") + .isEqualTo(ColorStateList.valueOf(Color.RED)); } } @@ -123,22 +119,21 @@ public class GlifLayoutTest { GlifLayout layout = new GlifLayout(context); layout.setProgressBarShown(true); layout.setPrimaryColor(ColorStateList.valueOf(Color.RED)); - assertEquals( - "Primary color should be red", ColorStateList.valueOf(Color.RED), layout.getPrimaryColor()); + assertWithMessage("Primary color should be red") + .that(layout.getPrimaryColor()) + .isEqualTo(ColorStateList.valueOf(Color.RED)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - ProgressBar progressBar = (ProgressBar) layout.findViewById(R.id.suw_layout_progress); - assertEquals( - "Progress bar should be tinted red", - ColorStateList.valueOf(Color.RED), - progressBar.getIndeterminateTintList()); - assertEquals( - "Determinate progress bar should also be tinted red", - ColorStateList.valueOf(Color.RED), - progressBar.getProgressBackgroundTintList()); + ProgressBar progressBar = layout.findViewById(R.id.suw_layout_progress); + assertWithMessage("Progress bar should be tinted red") + .that(progressBar.getIndeterminateTintList()) + .isEqualTo(ColorStateList.valueOf(Color.RED)); + assertWithMessage("Determinate progress bar should also be tinted red") + .that(progressBar.getProgressBackgroundTintList()) + .isEqualTo(ColorStateList.valueOf(Color.RED)); } - assertEquals(Color.RED, ((GlifPatternDrawable) getTabletBackground(layout)).getColor()); + assertThat(((GlifPatternDrawable) getTabletBackground(layout)).getColor()).isEqualTo(Color.RED); } @Test @@ -147,8 +142,8 @@ public class GlifLayoutTest { layout.setPrimaryColor(ColorStateList.valueOf(Color.BLUE)); layout.setBackgroundBaseColor(ColorStateList.valueOf(Color.RED)); - assertEquals(Color.RED, ((GlifPatternDrawable) getPhoneBackground(layout)).getColor()); - assertEquals(Color.RED, layout.getBackgroundBaseColor().getDefaultColor()); + assertThat(((GlifPatternDrawable) getPhoneBackground(layout)).getColor()).isEqualTo(Color.RED); + assertThat(layout.getBackgroundBaseColor().getDefaultColor()).isEqualTo(Color.RED); } @Config(qualifiers = "sw600dp") @@ -158,8 +153,8 @@ public class GlifLayoutTest { layout.setPrimaryColor(ColorStateList.valueOf(Color.BLUE)); layout.setBackgroundBaseColor(ColorStateList.valueOf(Color.RED)); - assertEquals(Color.RED, ((GlifPatternDrawable) getTabletBackground(layout)).getColor()); - assertEquals(Color.RED, layout.getBackgroundBaseColor().getDefaultColor()); + assertThat(((GlifPatternDrawable) getTabletBackground(layout)).getColor()).isEqualTo(Color.RED); + assertThat(layout.getBackgroundBaseColor().getDefaultColor()).isEqualTo(Color.RED); } @Test @@ -167,8 +162,8 @@ public class GlifLayoutTest { GlifLayout layout = new GlifLayout(context); layout.setBackgroundPatterned(true); - assertThat(getPhoneBackground(layout), instanceOf(GlifPatternDrawable.class)); - assertTrue("Background should be patterned", layout.isBackgroundPatterned()); + assertThat(getPhoneBackground(layout)).isInstanceOf(GlifPatternDrawable.class); + assertThat(layout.isBackgroundPatterned()).named("background is patterned").isTrue(); } @Test @@ -176,8 +171,8 @@ public class GlifLayoutTest { GlifLayout layout = new GlifLayout(context); layout.setBackgroundPatterned(false); - assertThat(getPhoneBackground(layout), instanceOf(ColorDrawable.class)); - assertFalse("Background should not be patterned", layout.isBackgroundPatterned()); + assertThat(getPhoneBackground(layout)).isInstanceOf(ColorDrawable.class); + assertThat(layout.isBackgroundPatterned()).named("background is patterned").isFalse(); } @Config(qualifiers = "sw600dp") @@ -186,8 +181,8 @@ public class GlifLayoutTest { GlifLayout layout = new GlifLayout(context); layout.setBackgroundPatterned(true); - assertThat(getTabletBackground(layout), instanceOf(GlifPatternDrawable.class)); - assertTrue("Background should be patterned", layout.isBackgroundPatterned()); + assertThat(getTabletBackground(layout)).isInstanceOf(GlifPatternDrawable.class); + assertThat(layout.isBackgroundPatterned()).named("background is patterned").isTrue(); } @Config(qualifiers = "sw600dp") @@ -196,8 +191,8 @@ public class GlifLayoutTest { GlifLayout layout = new GlifLayout(context); layout.setBackgroundPatterned(false); - assertThat(getTabletBackground(layout), instanceOf(ColorDrawable.class)); - assertFalse("Background should not be patterned", layout.isBackgroundPatterned()); + assertThat(getTabletBackground(layout)).isInstanceOf(ColorDrawable.class); + assertThat(layout.isBackgroundPatterned()).named("background is patterned").isFalse(); } @Test @@ -210,32 +205,32 @@ public class GlifLayoutTest { @Test public void testPeekProgressBarNull() { GlifLayout layout = new GlifLayout(context); - assertNull("PeekProgressBar should return null initially", layout.peekProgressBar()); + assertWithMessage("PeekProgressBar should return null initially") + .that(layout.peekProgressBar()) + .isNull(); } @Test public void testPeekProgressBar() { GlifLayout layout = new GlifLayout(context); layout.setProgressBarShown(true); - assertNotNull( - "Peek progress bar should return the bar after setProgressBarShown(true)", - layout.peekProgressBar()); + assertWithMessage("Peek progress bar should return the bar after setProgressBarShown(true)") + .that(layout.peekProgressBar()) + .isNotNull(); } @Test public void testMixins() { GlifLayout layout = new GlifLayout(context); final HeaderMixin header = layout.getMixin(HeaderMixin.class); - assertTrue( - "Header should be instance of ColoredHeaderMixin. " - + "Found " - + header.getClass() - + " instead.", - header instanceof ColoredHeaderMixin); + assertThat(header).named("header").isInstanceOf(ColoredHeaderMixin.class); - assertNotNull("GlifLayout should have icon mixin", layout.getMixin(IconMixin.class)); - assertNotNull( - "GlifLayout should have progress bar mixin", layout.getMixin(ProgressBarMixin.class)); + assertWithMessage("GlifLayout should have icon mixin") + .that(layout.getMixin(IconMixin.class)) + .isNotNull(); + assertWithMessage("GlifLayout should have progress bar mixin") + .that(layout.getMixin(ProgressBarMixin.class)) + .isNotNull(); } @Test @@ -243,8 +238,8 @@ public class GlifLayoutTest { GlifLayout layout = new GlifLayout(context); final View view = layout.inflateFooter(android.R.layout.simple_list_item_1); - assertEquals(android.R.id.text1, view.getId()); - assertNotNull(layout.findViewById(android.R.id.text1)); + assertThat(view.getId()).isEqualTo(android.R.id.text1); + assertThat((View) layout.findViewById(android.R.id.text1)).isNotNull(); } @Config(qualifiers = "sw600dp") @@ -258,8 +253,8 @@ public class GlifLayoutTest { GlifLayout layout = new GlifLayout(context, R.layout.suw_glif_blank_template); final View view = layout.inflateFooter(android.R.layout.simple_list_item_1); - assertEquals(android.R.id.text1, view.getId()); - assertNotNull(layout.findViewById(android.R.id.text1)); + assertThat(view.getId()).isEqualTo(android.R.id.text1); + assertThat((View) layout.findViewById(android.R.id.text1)).isNotNull(); } @Config(qualifiers = "sw600dp") @@ -277,7 +272,7 @@ public class GlifLayoutTest { .addAttribute(R.attr.suwFooter, "@android:layout/simple_list_item_1") .build()); - assertNotNull(layout.findViewById(android.R.id.text1)); + assertThat((View) layout.findViewById(android.R.id.text1)).isNotNull(); } @Test @@ -285,8 +280,8 @@ public class GlifLayoutTest { GlifLayout layout = new GlifLayout(context); final View view = layout.inflateStickyHeader(android.R.layout.simple_list_item_1); - assertEquals(android.R.id.text1, view.getId()); - assertNotNull(layout.findViewById(android.R.id.text1)); + assertThat(view.getId()).isEqualTo(android.R.id.text1); + assertThat((View) layout.findViewById(android.R.id.text1)).isNotNull(); } @Config(qualifiers = "sw600dp") @@ -304,7 +299,7 @@ public class GlifLayoutTest { .addAttribute(R.attr.suwStickyHeader, "@android:layout/simple_list_item_1") .build()); - assertNotNull(layout.findViewById(android.R.id.text1)); + assertThat((View) layout.findViewById(android.R.id.text1)).isNotNull(); } @Test @@ -312,8 +307,8 @@ public class GlifLayoutTest { GlifLayout layout = new GlifLayout(context, R.layout.suw_glif_blank_template); final View view = layout.inflateStickyHeader(android.R.layout.simple_list_item_1); - assertEquals(android.R.id.text1, view.getId()); - assertNotNull(layout.findViewById(android.R.id.text1)); + assertThat(view.getId()).isEqualTo(android.R.id.text1); + assertThat((View) layout.findViewById(android.R.id.text1)).isNotNull(); } @Config(qualifiers = "sw600dp") @@ -327,9 +322,8 @@ public class GlifLayoutTest { public void createFromXml_shouldSetLayoutFullscreen_whenLayoutFullscreenIsNotSet() { GlifLayout layout = new GlifLayout(context, Robolectric.buildAttributeSet().build()); if (VERSION.SDK_INT >= VERSION_CODES.M) { - assertEquals( - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, - layout.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + assertThat(layout.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) + .isEqualTo(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } } @@ -342,12 +336,11 @@ public class GlifLayoutTest { .addAttribute(R.attr.suwLayoutFullscreen, "false") .build()); - assertEquals(0, layout.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + assertThat(layout.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN).isEqualTo(0); } private Drawable getPhoneBackground(GlifLayout layout) { - final StatusBarBackgroundLayout patternBg = - (StatusBarBackgroundLayout) layout.findManagedViewById(R.id.suw_pattern_bg); + final StatusBarBackgroundLayout patternBg = layout.findManagedViewById(R.id.suw_pattern_bg); return patternBg.getStatusBarBackground(); } @@ -358,12 +351,14 @@ public class GlifLayoutTest { private void assertDefaultTemplateInflated(GlifLayout layout) { View title = layout.findViewById(R.id.suw_layout_title); - assertNotNull("@id/suw_layout_title should not be null", title); + assertWithMessage("@id/suw_layout_title should not be null").that(title).isNotNull(); View icon = layout.findViewById(R.id.suw_layout_icon); - assertNotNull("@id/suw_layout_icon should not be null", icon); + assertWithMessage("@id/suw_layout_icon should not be null").that(icon).isNotNull(); View scrollView = layout.findViewById(R.id.suw_scroll_view); - assertTrue("@id/suw_scroll_view should be a ScrollView", scrollView instanceof ScrollView); + assertWithMessage("@id/suw_scroll_view should be a ScrollView") + .that(scrollView instanceof ScrollView) + .isTrue(); } } diff --git a/library/test/robotest/src/com/android/setupwizardlib/gesture/ConsecutiveTapsGestureDetectorTest.java b/library/test/robotest/src/com/android/setupwizardlib/gesture/ConsecutiveTapsGestureDetectorTest.java index 4b366e3..ba3e2c5 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/gesture/ConsecutiveTapsGestureDetectorTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/gesture/ConsecutiveTapsGestureDetectorTest.java @@ -23,17 +23,17 @@ import static org.robolectric.RuntimeEnvironment.application; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class ConsecutiveTapsGestureDetectorTest { @Mock private ConsecutiveTapsGestureDetector.OnConsecutiveTapsListener listener; diff --git a/library/test/robotest/src/com/android/setupwizardlib/items/ButtonItemTest.java b/library/test/robotest/src/com/android/setupwizardlib/items/ButtonItemTest.java index bfd5270..b51e875 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/items/ButtonItemTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/items/ButtonItemTest.java @@ -16,12 +16,8 @@ package com.android.setupwizardlib.items; -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 com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.same; @@ -31,7 +27,6 @@ import static org.mockito.Mockito.verify; import static org.robolectric.RuntimeEnvironment.application; import android.content.Context; -import android.text.TextUtils; import android.view.ContextThemeWrapper; import android.view.View; import android.view.ViewGroup; @@ -40,13 +35,13 @@ import android.widget.FrameLayout; import android.widget.LinearLayout; import com.android.setupwizardlib.R; import com.android.setupwizardlib.items.ButtonItem.OnClickListener; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) public class ButtonItemTest { @@ -63,12 +58,11 @@ public class ButtonItemTest { public void testDefaultItem() { ButtonItem item = new ButtonItem(); - assertTrue("ButtonItem should be enabled by default", item.isEnabled()); - assertEquals("ButtonItem should return count = 0", 0, item.getCount()); - assertEquals("ButtonItem should return layout resource = 0", 0, item.getLayoutResource()); - assertEquals( - "Default theme should be @style/SuwButtonItem", R.style.SuwButtonItem, item.getTheme()); - assertNull("Default text should be null", item.getText()); + assertThat(item.isEnabled()).named("enabled").isTrue(); + assertThat(item.getCount()).named("count").isEqualTo(0); + assertThat(item.getLayoutResource()).named("layout resource").isEqualTo(0); + assertThat(item.getTheme()).named("theme").isEqualTo(R.style.SuwButtonItem); + assertThat(item.getText()).named("text").isNull(); } @Test @@ -88,8 +82,8 @@ public class ButtonItemTest { TestButtonItem item = new TestButtonItem(); final Button button = item.createButton(parent); - assertTrue("Default button should be enabled", button.isEnabled()); - assertTrue("Default button text should be empty", TextUtils.isEmpty(button.getText())); + assertThat(button.isEnabled()).named("enabled").isTrue(); + assertThat(button.getText().toString()).isEmpty(); } @Test @@ -98,7 +92,9 @@ public class ButtonItemTest { final int id = 12345; item.setId(id); - assertEquals("Button's id should be set", id, item.createButton(parent).getId()); + assertWithMessage("Button's id should be set") + .that(item.createButton(parent).getId()) + .isEqualTo(id); } @Test @@ -110,8 +106,10 @@ public class ButtonItemTest { frameLayout.addView(button); final Button button2 = item.createButton(parent); - assertSame("createButton should be reused", button, button2); - assertNull("Should be removed from parent after createButton", button2.getParent()); + assertWithMessage("createButton should be reused").that(button2).isSameAs(button); + assertWithMessage("Should be removed from parent after createButton") + .that(button2.getParent()) + .isNull(); } @Test @@ -120,8 +118,8 @@ public class ButtonItemTest { item.setEnabled(true); final Button button = item.createButton(parent); - assertTrue("ButtonItem should be enabled", item.isEnabled()); - assertTrue("Button should be enabled", button.isEnabled()); + assertWithMessage("ButtonItem should be enabled").that(item.isEnabled()).isTrue(); + assertWithMessage("Button should be enabled").that(button.isEnabled()).isTrue(); } @Test @@ -130,8 +128,8 @@ public class ButtonItemTest { item.setEnabled(false); final Button button = item.createButton(parent); - assertFalse("ButtonItem should be disabled", item.isEnabled()); - assertFalse("Button should be disabled", button.isEnabled()); + assertWithMessage("ButtonItem should be disabled").that(item.isEnabled()).isFalse(); + assertWithMessage("Button should be disabled").that(button.isEnabled()).isFalse(); } @Test @@ -140,8 +138,12 @@ public class ButtonItemTest { item.setText("lorem ipsum"); final Button button = item.createButton(parent); - assertEquals("ButtonItem text should be \"lorem ipsum\"", "lorem ipsum", item.getText()); - assertEquals("Button text should be \"lorem ipsum\"", "lorem ipsum", button.getText()); + assertWithMessage("ButtonItem text should be \"lorem ipsum\"") + .that(item.getText().toString()) + .isEqualTo("lorem ipsum"); + assertWithMessage("Button text should be \"lorem ipsum\"") + .that(button.getText().toString()) + .isEqualTo("lorem ipsum"); } @Test @@ -150,11 +152,10 @@ public class ButtonItemTest { item.setTheme(R.style.SuwButtonItem_Colored); final Button button = item.createButton(parent); - assertEquals( - "ButtonItem theme should be SuwButtonItem.Colored", - R.style.SuwButtonItem_Colored, - item.getTheme()); - assertNotNull(button.getContext().getTheme()); + assertWithMessage("ButtonItem theme should be SuwButtonItem.Colored") + .that(item.getTheme()) + .isEqualTo(R.style.SuwButtonItem_Colored); + assertThat(button.getContext().getTheme()).isNotNull(); } @Test diff --git a/library/test/robotest/src/com/android/setupwizardlib/items/ItemGroupTest.java b/library/test/robotest/src/com/android/setupwizardlib/items/ItemGroupTest.java index d0c2785..3cbc576 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/items/ItemGroupTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/items/ItemGroupTest.java @@ -16,24 +16,22 @@ package com.android.setupwizardlib.items; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static com.google.common.truth.Truth.assertWithMessage; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) public class ItemGroupTest { @@ -58,9 +56,13 @@ public class ItemGroupTest { itemGroup.addChild(CHILD_1); itemGroup.addChild(CHILD_2); - assertSame("Item at position 0 should be child1", CHILD_1, itemGroup.getItemAt(0)); - assertSame("Item at position 1 should be child2", CHILD_2, itemGroup.getItemAt(1)); - assertEquals("Should have 2 children", 2, itemGroup.getCount()); + assertWithMessage("Item at position 0 should be child1") + .that(itemGroup.getItemAt(0)) + .isSameAs(CHILD_1); + assertWithMessage("Item at position 1 should be child2") + .that(itemGroup.getItemAt(1)) + .isSameAs(CHILD_2); + assertWithMessage("Should have 2 children").that(itemGroup.getCount()).isEqualTo(2); final InOrder inOrder = inOrder(observer); inOrder.verify(observer).onItemRangeInserted(eq(itemGroup), eq(0), eq(1)); @@ -75,9 +77,13 @@ public class ItemGroupTest { itemGroup.removeChild(CHILD_2); - assertSame("Item at position 0 should be child1", CHILD_1, itemGroup.getItemAt(0)); - assertSame("Item at position 1 should be child3", CHILD_3, itemGroup.getItemAt(1)); - assertEquals("Should have 2 children", 2, itemGroup.getCount()); + assertWithMessage("Item at position 0 should be child1") + .that(itemGroup.getItemAt(0)) + .isSameAs(CHILD_1); + assertWithMessage("Item at position 1 should be child3") + .that(itemGroup.getItemAt(1)) + .isSameAs(CHILD_3); + assertWithMessage("Should have 2 children").that(itemGroup.getCount()).isEqualTo(2); verify(observer).onItemRangeRemoved(eq(itemGroup), eq(1), eq(1)); } @@ -89,7 +95,7 @@ public class ItemGroupTest { itemGroup.clear(); - assertEquals("Should have 0 child", 0, itemGroup.getCount()); + assertWithMessage("Should have 0 child").that(itemGroup.getCount()).isEqualTo(0); verify(observer).onItemRangeRemoved(eq(itemGroup), eq(0), eq(2)); } @@ -106,10 +112,18 @@ public class ItemGroupTest { parentGroup.addChild(childGroup); parentGroup.addChild(CHILD_4); - assertSame("Position 0 should be child 1", CHILD_1, parentGroup.getItemAt(0)); - assertSame("Position 1 should be child 2", CHILD_2, parentGroup.getItemAt(1)); - assertSame("Position 2 should be child 3", CHILD_3, parentGroup.getItemAt(2)); - assertSame("Position 3 should be child 4", CHILD_4, parentGroup.getItemAt(3)); + assertWithMessage("Position 0 should be child 1") + .that(parentGroup.getItemAt(0)) + .isSameAs(CHILD_1); + assertWithMessage("Position 1 should be child 2") + .that(parentGroup.getItemAt(1)) + .isSameAs(CHILD_2); + assertWithMessage("Position 2 should be child 3") + .that(parentGroup.getItemAt(2)) + .isSameAs(CHILD_3); + assertWithMessage("Position 3 should be child 4") + .that(parentGroup.getItemAt(3)) + .isSameAs(CHILD_4); final InOrder inOrder = inOrder(observer); inOrder.verify(observer).onItemRangeInserted(eq(parentGroup), eq(0), eq(1)); @@ -246,8 +260,12 @@ public class ItemGroupTest { parentGroup.addChild(childGroup); parentGroup.addChild(CHILD_2); - assertSame("Position 0 should be child 1", CHILD_1, parentGroup.getItemAt(0)); - assertSame("Position 1 should be child 2", CHILD_2, parentGroup.getItemAt(1)); + assertWithMessage("Position 0 should be child 1") + .that(parentGroup.getItemAt(0)) + .isSameAs(CHILD_1); + assertWithMessage("Position 1 should be child 2") + .that(parentGroup.getItemAt(1)) + .isSameAs(CHILD_2); } @Test @@ -258,7 +276,9 @@ public class ItemGroupTest { itemGroup.addChild(CHILD_1); itemGroup.addChild(CHILD_2); - assertSame("Find item 23456 should return child 2", CHILD_2, itemGroup.findItemById(23456)); + assertWithMessage("Find item 23456 should return child 2") + .that(itemGroup.findItemById(23456)) + .isSameAs(CHILD_2); } @Test @@ -269,7 +289,9 @@ public class ItemGroupTest { itemGroup.addChild(CHILD_1); itemGroup.addChild(CHILD_2); - assertNull("ID not found should return null", itemGroup.findItemById(56789)); + assertWithMessage("ID not found should return null") + .that(itemGroup.findItemById(56789)) + .isNull(); } /** diff --git a/library/test/robotest/src/com/android/setupwizardlib/robolectric/SuwLibRobolectricTestRunner.java b/library/test/robotest/src/com/android/setupwizardlib/robolectric/SuwLibRobolectricTestRunner.java deleted file mode 100644 index 25b7207..0000000 --- a/library/test/robotest/src/com/android/setupwizardlib/robolectric/SuwLibRobolectricTestRunner.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.setupwizardlib.robolectric; - -import org.junit.runner.notification.RunNotifier; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.InitializationError; -import org.robolectric.RobolectricTestRunner; - -public class SuwLibRobolectricTestRunner extends RobolectricTestRunner { - - public SuwLibRobolectricTestRunner(Class testClass) throws InitializationError { - super(testClass); - } - - @Override - protected void runChild(FrameworkMethod method, RunNotifier notifier) { - System.out.println("===== Running " + method + " ====="); - super.runChild(method, notifier); - } -} diff --git a/library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java b/library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java index def820e..3bc9fd1 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java @@ -17,7 +17,7 @@ package com.android.setupwizardlib.span; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertSame; +import static com.google.common.truth.Truth.assertWithMessage; import static org.robolectric.RuntimeEnvironment.application; import android.content.Context; @@ -26,11 +26,11 @@ import android.text.Selection; import android.text.SpannableStringBuilder; import android.text.method.LinkMovementMethod; import android.widget.TextView; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class LinkSpanTest { @Test @@ -41,7 +41,9 @@ public class LinkSpanTest { linkSpan.onClick(textView); - assertSame("Clicked LinkSpan should be passed to setup", linkSpan, context.clickedSpan); + assertWithMessage("Clicked LinkSpan should be passed to setup") + .that(context.clickedSpan) + .isSameAs(linkSpan); } @Test @@ -63,7 +65,9 @@ public class LinkSpanTest { final LinkSpan linkSpan = new LinkSpan("test_id"); linkSpan.onClick(textView); - assertSame("Clicked LinkSpan should be passed to setup", linkSpan, context.clickedSpan); + assertWithMessage("Clicked LinkSpan should be passed to setup") + .that(context.clickedSpan) + .isSameAs(linkSpan); } @Test diff --git a/library/test/robotest/src/com/android/setupwizardlib/template/ListViewScrollHandlingDelegateTest.java b/library/test/robotest/src/com/android/setupwizardlib/template/ListViewScrollHandlingDelegateTest.java index 0a82e8b..9b99a68 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/template/ListViewScrollHandlingDelegateTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/template/ListViewScrollHandlingDelegateTest.java @@ -25,24 +25,22 @@ import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListView; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; import org.robolectric.Shadows; import org.robolectric.annotation.Config; -import org.robolectric.shadows.ShadowListView; @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class ListViewScrollHandlingDelegateTest { @Mock private RequireScrollMixin requireScrollMixin; private ListView listView; - private ShadowListView shadowListView; private ListViewScrollHandlingDelegate delegate; @Before @@ -51,7 +49,6 @@ public class ListViewScrollHandlingDelegateTest { listView = new TestListView(application); delegate = new ListViewScrollHandlingDelegate(requireScrollMixin, listView); - shadowListView = Shadows.shadowOf(listView); listView.layout(0, 0, 50, 50); } @@ -69,7 +66,7 @@ public class ListViewScrollHandlingDelegateTest { verify(requireScrollMixin).notifyScrollabilityChange(true); - shadowListView.getOnScrollListener().onScroll(listView, 2, 20, 20); + Shadows.shadowOf(listView).getOnScrollListener().onScroll(listView, 2, 20, 20); verify(requireScrollMixin).notifyScrollabilityChange(false); } @@ -77,7 +74,7 @@ public class ListViewScrollHandlingDelegateTest { @Test public void testPageScrollDown() throws Throwable { delegate.pageScrollDown(); - assertThat(shadowListView.getLastSmoothScrollByDistance()).isEqualTo(50); + assertThat(Shadows.shadowOf(listView).getLastSmoothScrollByDistance()).isEqualTo(50); } private static class TestListView extends ListView { diff --git a/library/test/robotest/src/com/android/setupwizardlib/template/RequireScrollMixinTest.java b/library/test/robotest/src/com/android/setupwizardlib/template/RequireScrollMixinTest.java index ab35eb3..fe45d5f 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/template/RequireScrollMixinTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/template/RequireScrollMixinTest.java @@ -16,10 +16,8 @@ package com.android.setupwizardlib.template; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -34,7 +32,6 @@ import android.view.View.OnClickListener; import android.widget.Button; import com.android.setupwizardlib.GlifLayout; import com.android.setupwizardlib.TemplateLayout; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import com.android.setupwizardlib.template.RequireScrollMixin.OnRequireScrollStateChangedListener; import com.android.setupwizardlib.template.RequireScrollMixin.ScrollHandlingDelegate; import com.android.setupwizardlib.view.NavigationBar; @@ -43,10 +40,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class RequireScrollMixinTest { @Mock private ScrollHandlingDelegate delegate; @@ -73,30 +71,31 @@ public class RequireScrollMixinTest { public void testScrollStateChangedListener() { OnRequireScrollStateChangedListener listener = mock(OnRequireScrollStateChangedListener.class); requireScrollMixin.setOnRequireScrollStateChangedListener(listener); - assertFalse( - "Scrolling should not be required initially", requireScrollMixin.isScrollingRequired()); + assertWithMessage("Scrolling should not be required initially") + .that(requireScrollMixin.isScrollingRequired()) + .isFalse(); requireScrollMixin.notifyScrollabilityChange(true); verify(listener).onRequireScrollStateChanged(true); - assertTrue( - "Scrolling should be required when there is more content below the fold", - requireScrollMixin.isScrollingRequired()); + assertWithMessage("Scrolling should be required when there is more content below the fold") + .that(requireScrollMixin.isScrollingRequired()) + .isTrue(); requireScrollMixin.notifyScrollabilityChange(false); verify(listener).onRequireScrollStateChanged(false); - assertFalse( - "Scrolling should not be required after scrolling to bottom", - requireScrollMixin.isScrollingRequired()); + assertWithMessage("Scrolling should not be required after scrolling to bottom") + .that(requireScrollMixin.isScrollingRequired()) + .isFalse(); // Once the user has scrolled to the bottom, they should not be forced to scroll down again requireScrollMixin.notifyScrollabilityChange(true); verifyNoMoreInteractions(listener); - assertFalse( - "Scrolling should not be required after scrolling to bottom once", - requireScrollMixin.isScrollingRequired()); + assertWithMessage("Scrolling should not be required after scrolling to bottom once") + .that(requireScrollMixin.isScrollingRequired()) + .isFalse(); - assertSame(listener, requireScrollMixin.getOnRequireScrollStateChangedListener()); + assertThat(requireScrollMixin.getOnRequireScrollStateChangedListener()).isSameAs(listener); } @Test @@ -123,23 +122,23 @@ public class RequireScrollMixinTest { requireScrollMixin.requireScrollWithNavigationBar(navigationBar); requireScrollMixin.notifyScrollabilityChange(true); - assertEquals( - "More button should be visible", - View.VISIBLE, - navigationBar.getMoreButton().getVisibility()); - assertEquals( - "Next button should be hidden", View.GONE, navigationBar.getNextButton().getVisibility()); + assertWithMessage("More button should be visible") + .that(navigationBar.getMoreButton().getVisibility()) + .isEqualTo(View.VISIBLE); + assertWithMessage("Next button should be hidden") + .that(navigationBar.getNextButton().getVisibility()) + .isEqualTo(View.GONE); navigationBar.getMoreButton().performClick(); verify(delegate).pageScrollDown(); requireScrollMixin.notifyScrollabilityChange(false); - assertEquals( - "More button should be hidden", View.GONE, navigationBar.getMoreButton().getVisibility()); - assertEquals( - "Next button should be visible", - View.VISIBLE, - navigationBar.getNextButton().getVisibility()); + assertWithMessage("More button should be hidden") + .that(navigationBar.getMoreButton().getVisibility()) + .isEqualTo(View.GONE); + assertWithMessage("Next button should be visible") + .that(navigationBar.getNextButton().getVisibility()) + .isEqualTo(View.VISIBLE); } @SuppressLint("SetTextI18n") // It's OK for testing @@ -150,16 +149,18 @@ public class RequireScrollMixinTest { OnClickListener wrappedListener = mock(OnClickListener.class); requireScrollMixin.requireScrollWithButton(button, "TestMoreLabel", wrappedListener); - assertEquals("Button label should be kept initially", "OriginalLabel", button.getText()); + assertWithMessage("Button label should be kept initially") + .that(button.getText().toString()) + .isEqualTo("OriginalLabel"); requireScrollMixin.notifyScrollabilityChange(true); - assertEquals("TestMoreLabel", button.getText()); + assertThat(button.getText().toString()).isEqualTo("TestMoreLabel"); button.performClick(); verify(wrappedListener, never()).onClick(eq(button)); verify(delegate).pageScrollDown(); requireScrollMixin.notifyScrollabilityChange(false); - assertEquals("OriginalLabel", button.getText()); + assertThat(button.getText().toString()).isEqualTo("OriginalLabel"); button.performClick(); verify(wrappedListener).onClick(eq(button)); } diff --git a/library/test/robotest/src/com/android/setupwizardlib/template/ScrollViewScrollHandlingDelegateTest.java b/library/test/robotest/src/com/android/setupwizardlib/template/ScrollViewScrollHandlingDelegateTest.java index 52411e3..b07e2a3 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/template/ScrollViewScrollHandlingDelegateTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/template/ScrollViewScrollHandlingDelegateTest.java @@ -21,17 +21,17 @@ import static org.mockito.Mockito.verify; import static org.robolectric.RuntimeEnvironment.application; import android.view.View; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import com.android.setupwizardlib.view.BottomScrollView; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class ScrollViewScrollHandlingDelegateTest { @Mock private RequireScrollMixin requireScrollMixin; diff --git a/library/test/robotest/src/com/android/setupwizardlib/util/GlifDimensionTest.java b/library/test/robotest/src/com/android/setupwizardlib/util/GlifDimensionTest.java index f6c23f1..a0c688c 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/util/GlifDimensionTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/util/GlifDimensionTest.java @@ -16,7 +16,7 @@ package com.android.setupwizardlib.util; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertWithMessage; import static org.robolectric.RuntimeEnvironment.application; import android.content.Context; @@ -26,13 +26,13 @@ import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.ContextThemeWrapper; import com.android.setupwizardlib.R; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = Config.ALL_SDKS) public class GlifDimensionTest { @@ -61,17 +61,17 @@ public class GlifDimensionTest { final int marginSides = a.getDimensionPixelSize(0, 0); a.recycle(); - assertEquals( - "Dimensions should satisfy constraint: " - + "?attr/suwMarginSides = suw_items_glif_text_divider_inset", - marginSides, - res.getDimensionPixelSize(R.dimen.suw_items_glif_text_divider_inset)); + assertWithMessage( + "Dimensions should satisfy constraint: " + + "?attr/suwMarginSides = suw_items_glif_text_divider_inset") + .that(res.getDimensionPixelSize(R.dimen.suw_items_glif_text_divider_inset)) + .isEqualTo(marginSides); - assertEquals( - "Dimensions should satisfy constraint: ?attr/suwMarginSides + " - + "suw_items_icon_container_width = suw_items_glif_icon_divider_inset", - marginSides + res.getDimensionPixelSize(R.dimen.suw_items_icon_container_width), - res.getDimensionPixelSize(R.dimen.suw_items_glif_icon_divider_inset)); + assertWithMessage( + "Dimensions should satisfy constraint: ?attr/suwMarginSides + " + + "suw_items_icon_container_width = suw_items_glif_icon_divider_inset") + .that(res.getDimensionPixelSize(R.dimen.suw_items_glif_icon_divider_inset)) + .isEqualTo(marginSides + res.getDimensionPixelSize(R.dimen.suw_items_icon_container_width)); } @Test @@ -92,17 +92,17 @@ public class GlifDimensionTest { final int marginSides = a.getDimensionPixelSize(0, 0); a.recycle(); - assertEquals( - "Dimensions should satisfy constraint: ?attr/suwMarginSides - " - + "4dp (internal padding of button) = suw_glif_button_margin_end", - marginSides - dp2Px(4), - res.getDimensionPixelSize(R.dimen.suw_glif_button_margin_end)); + assertWithMessage( + "Dimensions should satisfy constraint: ?attr/suwMarginSides - " + + "4dp (internal padding of button) = suw_glif_button_margin_end") + .that(res.getDimensionPixelSize(R.dimen.suw_glif_button_margin_end)) + .isEqualTo(marginSides - dp2Px(4)); - assertEquals( - "Dimensions should satisfy constraint: ?attr/suwMarginSides - " - + "suw_glif_button_padding = suw_glif_button_margin_start", - marginSides - res.getDimensionPixelSize(R.dimen.suw_glif_button_padding), - res.getDimensionPixelSize(R.dimen.suw_glif_button_margin_start)); + assertWithMessage( + "Dimensions should satisfy constraint: ?attr/suwMarginSides - " + + "suw_glif_button_padding = suw_glif_button_margin_start") + .that(res.getDimensionPixelSize(R.dimen.suw_glif_button_margin_start)) + .isEqualTo(marginSides - res.getDimensionPixelSize(R.dimen.suw_glif_button_padding)); } private int dp2Px(float dp) { diff --git a/library/test/robotest/src/com/android/setupwizardlib/util/GlifStyleTest.java b/library/test/robotest/src/com/android/setupwizardlib/util/GlifStyleTest.java index bc4ba75..61b84bb 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/util/GlifStyleTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/util/GlifStyleTest.java @@ -17,8 +17,6 @@ package com.android.setupwizardlib.util; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.robolectric.RuntimeEnvironment.application; import android.annotation.TargetApi; @@ -30,18 +28,19 @@ import android.os.Bundle; import androidx.annotation.Nullable; import android.util.AttributeSet; import android.view.ContextThemeWrapper; +import android.view.View; import android.widget.Button; import android.widget.ProgressBar; import com.android.setupwizardlib.R; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.robolectric.util.ReflectionHelpers; import org.robolectric.util.ReflectionHelpers.ClassParameter; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) public class GlifStyleTest { @@ -58,7 +57,8 @@ public class GlifStyleTest { if (VERSION.SDK_INT < VERSION_CODES.M) { // Robolectric resolved the wrong theme attribute on versions >= M // https://github.com/robolectric/robolectric/issues/2940 - assertEquals("ff4285f4", Integer.toHexString(button.getTextColors().getDefaultColor())); + assertThat(Integer.toHexString(button.getTextColors().getDefaultColor())) + .isEqualTo("ff4285f4"); } } @@ -67,7 +67,7 @@ public class GlifStyleTest { @Test public void glifThemeLight_statusBarColorShouldBeTransparent() { GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); - assertEquals(0x00000000, activity.getWindow().getStatusBarColor()); + assertThat(activity.getWindow().getStatusBarColor()).isEqualTo(0x00000000); } @Test @@ -75,9 +75,8 @@ public class GlifStyleTest { GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); activity.setContentView(R.layout.suw_glif_loading_screen); - assertTrue( - "Progress bar should exist", - activity.findViewById(R.id.suw_large_progress_bar) instanceof ProgressBar); + assertThat((View) activity.findViewById(R.id.suw_large_progress_bar)) + .isInstanceOf(ProgressBar.class); } private Button createButton(Context context, AttributeSet attrs) { diff --git a/library/test/robotest/src/com/android/setupwizardlib/util/GlifV3StyleTest.java b/library/test/robotest/src/com/android/setupwizardlib/util/GlifV3StyleTest.java index 1d5276f..13e29f6 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/util/GlifV3StyleTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/util/GlifV3StyleTest.java @@ -17,8 +17,6 @@ package com.android.setupwizardlib.util; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import android.app.Activity; import android.graphics.Color; @@ -30,13 +28,13 @@ import androidx.annotation.Nullable; import android.view.View; import android.widget.Button; import com.android.setupwizardlib.R; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(minSdk = Config.OLDEST_SDK, maxSdk = Config.NEWEST_SDK) public class GlifV3StyleTest { @@ -44,11 +42,11 @@ public class GlifV3StyleTest { public void activityWithGlifV3Theme_shouldUseLightNavBarOnV27OrAbove() { GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); if (VERSION.SDK_INT >= VERSION_CODES.O_MR1) { - assertEquals(Color.WHITE, activity.getWindow().getNavigationBarColor()); + assertThat(activity.getWindow().getNavigationBarColor()).isEqualTo(Color.WHITE); int vis = activity.getWindow().getDecorView().getSystemUiVisibility(); - assertTrue((vis & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) != 0); + assertThat((vis & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) != 0).isTrue(); } else if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { - assertEquals(Color.BLACK, activity.getWindow().getNavigationBarColor()); + assertThat(activity.getWindow().getNavigationBarColor()).isEqualTo(Color.BLACK); } // Nav bar color is not customizable pre-L } diff --git a/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java b/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java index 0aae115..f301e43 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java @@ -29,15 +29,15 @@ import android.os.Build.VERSION_CODES; import com.android.setupwizardlib.R; import com.android.setupwizardlib.robolectric.ExternalResources; import com.android.setupwizardlib.robolectric.ExternalResources.Resources; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import com.android.setupwizardlib.util.Partner.ResourceEntry; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) public class PartnerTest { diff --git a/library/test/robotest/src/com/android/setupwizardlib/util/ThemeResolverTest.java b/library/test/robotest/src/com/android/setupwizardlib/util/ThemeResolverTest.java index 33ea6ad..6489961 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/util/ThemeResolverTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/util/ThemeResolverTest.java @@ -23,14 +23,14 @@ import android.app.Activity; import android.content.Intent; import androidx.annotation.StyleRes; import com.android.setupwizardlib.R; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = Config.NEWEST_SDK) public class ThemeResolverTest { diff --git a/library/test/robotest/src/com/android/setupwizardlib/util/WizardManagerHelperTest.java b/library/test/robotest/src/com/android/setupwizardlib/util/WizardManagerHelperTest.java index 0420f97..e302cab 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/util/WizardManagerHelperTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/util/WizardManagerHelperTest.java @@ -17,9 +17,7 @@ package com.android.setupwizardlib.util; import static com.google.common.truth.Truth.assertThat; -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.assertWithMessage; import static org.robolectric.RuntimeEnvironment.application; import static org.robolectric.Shadows.shadowOf; @@ -33,16 +31,16 @@ import android.provider.Settings.Global; import android.provider.Settings.Secure; import androidx.annotation.StyleRes; import com.android.setupwizardlib.R; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = Config.NEWEST_SDK) public class WizardManagerHelperTest { @@ -58,61 +56,63 @@ public class WizardManagerHelperTest { data.putExtra("extraData", "shazam"); final Intent nextIntent = WizardManagerHelper.getNextIntent(intent, Activity.RESULT_OK, data); - assertEquals( - "Next intent action should be NEXT", "com.android.wizard.NEXT", nextIntent.getAction()); - assertEquals( - "Script URI should be the same as original intent", - "android-resource://test-script", - nextIntent.getStringExtra("scriptUri")); - assertEquals( - "Action ID should be the same as original intent", - "test_action_id", - nextIntent.getStringExtra("actionId")); - assertEquals( - "Theme extra should be the same as original intent", - "test_theme", - nextIntent.getStringExtra("theme")); - assertFalse("ignoreExtra should not be in nextIntent", nextIntent.hasExtra("ignoreExtra")); - assertEquals( - "Result code extra should be RESULT_OK", - Activity.RESULT_OK, - nextIntent.getIntExtra("com.android.setupwizard.ResultCode", 0)); - assertEquals( - "Extra data should surface as extra in nextIntent", - "shazam", - nextIntent.getStringExtra("extraData")); + assertWithMessage("Next intent action should be NEXT") + .that(nextIntent.getAction()) + .isEqualTo("com.android.wizard.NEXT"); + assertWithMessage("Script URI should be the same as original intent") + .that(nextIntent.getStringExtra("scriptUri")) + .isEqualTo("android-resource://test-script"); + assertWithMessage("Action ID should be the same as original intent") + .that(nextIntent.getStringExtra("actionId")) + .isEqualTo("test_action_id"); + assertWithMessage("Theme extra should be the same as original intent") + .that(nextIntent.getStringExtra("theme")) + .isEqualTo("test_theme"); + assertWithMessage("ignoreExtra should not be in nextIntent") + .that(nextIntent.hasExtra("ignoreExtra")) + .isFalse(); + assertWithMessage("Result code extra should be RESULT_OK") + .that(nextIntent.getIntExtra("com.android.setupwizard.ResultCode", 0)) + .isEqualTo(Activity.RESULT_OK); + assertWithMessage("Extra data should surface as extra in nextIntent") + .that(nextIntent.getStringExtra("extraData")) + .isEqualTo("shazam"); } @Test public void testIsSetupWizardTrue() { final Intent intent = new Intent(); intent.putExtra("firstRun", true); - assertTrue("Is setup wizard should be true", WizardManagerHelper.isSetupWizardIntent(intent)); + assertWithMessage("Is setup wizard should be true") + .that(WizardManagerHelper.isSetupWizardIntent(intent)) + .isTrue(); } @Test public void testIsDeferredSetupTrue() { final Intent intent = new Intent(); intent.putExtra("deferredSetup", true); - assertTrue( - "Is deferred setup wizard should be true", - WizardManagerHelper.isDeferredSetupWizard(intent)); + assertWithMessage("Is deferred setup wizard should be true") + .that(WizardManagerHelper.isDeferredSetupWizard(intent)) + .isTrue(); } @Test public void testIsPreDeferredSetupTrue() { final Intent intent = new Intent(); intent.putExtra("preDeferredSetup", true); - assertTrue( - "Is pre-deferred setup wizard should be true", - WizardManagerHelper.isPreDeferredSetupWizard(intent)); + assertWithMessage("Is pre-deferred setup wizard should be true") + .that(WizardManagerHelper.isPreDeferredSetupWizard(intent)) + .isTrue(); } @Test public void testIsSetupWizardFalse() { final Intent intent = new Intent(); intent.putExtra("firstRun", false); - assertFalse("Is setup wizard should be true", WizardManagerHelper.isSetupWizardIntent(intent)); + assertWithMessage("Is setup wizard should be true") + .that(WizardManagerHelper.isSetupWizardIntent(intent)) + .isFalse(); } @Test @@ -132,12 +132,12 @@ public class WizardManagerHelperTest { unexpectedStringThemes.add(theme); } } - assertTrue( - "Intent themes " + unexpectedIntentThemes + " should be light", - unexpectedIntentThemes.isEmpty()); - assertTrue( - "String themes " + unexpectedStringThemes + " should be light", - unexpectedStringThemes.isEmpty()); + assertWithMessage("Intent themes " + unexpectedIntentThemes + " should be light") + .that(unexpectedIntentThemes.isEmpty()) + .isTrue(); + assertWithMessage("String themes " + unexpectedStringThemes + " should be light") + .that(unexpectedStringThemes.isEmpty()) + .isTrue(); } @Test @@ -155,111 +155,114 @@ public class WizardManagerHelperTest { unexpectedStringThemes.add(theme); } } - assertTrue( - "Intent themes " + unexpectedIntentThemes + " should not be light", - unexpectedIntentThemes.isEmpty()); - assertTrue( - "String themes " + unexpectedStringThemes + " should not be light", - unexpectedStringThemes.isEmpty()); + assertWithMessage("Intent themes " + unexpectedIntentThemes + " should not be light") + .that(unexpectedIntentThemes.isEmpty()) + .isTrue(); + assertWithMessage("String themes " + unexpectedStringThemes + " should not be light") + .that(unexpectedStringThemes.isEmpty()) + .isTrue(); } @Test public void getThemeRes_whenOldestSupportedThemeTakeEffect_shouldReturnDefault() { Intent intent = new Intent(); intent.putExtra(WizardManagerHelper.EXTRA_THEME, "material"); - assertEquals(0, WizardManagerHelper.getThemeRes(intent, 0, WizardManagerHelper.THEME_GLIF_V2)); + assertThat(WizardManagerHelper.getThemeRes(intent, 0, WizardManagerHelper.THEME_GLIF_V2)) + .isEqualTo(0); } @Test public void getThemeRes_whenOldestSupportedThemeNotTakeEffect_shouldReturnCurrent() { Intent intent = new Intent(); intent.putExtra(WizardManagerHelper.EXTRA_THEME, "glif_v3"); - assertEquals( - R.style.SuwThemeGlifV3, - WizardManagerHelper.getThemeRes(intent, 0, WizardManagerHelper.THEME_GLIF_V2)); + assertThat(WizardManagerHelper.getThemeRes(intent, 0, WizardManagerHelper.THEME_GLIF_V2)) + .isEqualTo(R.style.SuwThemeGlifV3); } @Test public void testIsLightThemeDefault() { final Intent intent = new Intent(); intent.putExtra("theme", "abracadabra"); - assertTrue( - "isLightTheme should return default value true", - WizardManagerHelper.isLightTheme(intent, true)); - assertFalse( - "isLightTheme should return default value false", - WizardManagerHelper.isLightTheme(intent, false)); + assertWithMessage("isLightTheme should return default value true") + .that(WizardManagerHelper.isLightTheme(intent, true)) + .isTrue(); + assertWithMessage("isLightTheme should return default value false") + .that(WizardManagerHelper.isLightTheme(intent, false)) + .isFalse(); } @Test public void testIsLightThemeUnspecified() { final Intent intent = new Intent(); - assertTrue( - "isLightTheme should return default value true", - WizardManagerHelper.isLightTheme(intent, true)); - assertFalse( - "isLightTheme should return default value false", - WizardManagerHelper.isLightTheme(intent, false)); + assertWithMessage("isLightTheme should return default value true") + .that(WizardManagerHelper.isLightTheme(intent, true)) + .isTrue(); + assertWithMessage("isLightTheme should return default value false") + .that(WizardManagerHelper.isLightTheme(intent, false)) + .isFalse(); } @Test public void testGetThemeResGlifV3Light() { - assertEquals(R.style.SuwThemeGlifV3_Light, WizardManagerHelper.getThemeRes("glif_v3_light", 0)); + assertThat(WizardManagerHelper.getThemeRes("glif_v3_light", 0)) + .isEqualTo(R.style.SuwThemeGlifV3_Light); } @Test public void testGetThemeResGlifV3() { - assertEquals(R.style.SuwThemeGlifV3, WizardManagerHelper.getThemeRes("glif_v3", 0)); + assertThat(WizardManagerHelper.getThemeRes("glif_v3", 0)).isEqualTo(R.style.SuwThemeGlifV3); } @Test public void testGetThemeResGlifV2Light() { - assertEquals(R.style.SuwThemeGlifV2_Light, WizardManagerHelper.getThemeRes("glif_v2_light", 0)); + assertThat(WizardManagerHelper.getThemeRes("glif_v2_light", 0)) + .isEqualTo(R.style.SuwThemeGlifV2_Light); } @Test public void testGetThemeResGlifV2() { - assertEquals(R.style.SuwThemeGlifV2, WizardManagerHelper.getThemeRes("glif_v2", 0)); + assertThat(WizardManagerHelper.getThemeRes("glif_v2", 0)).isEqualTo(R.style.SuwThemeGlifV2); } @Test public void testGetThemeResGlifLight() { - assertEquals(R.style.SuwThemeGlif_Light, WizardManagerHelper.getThemeRes("glif_light", 0)); + assertThat(WizardManagerHelper.getThemeRes("glif_light", 0)) + .isEqualTo(R.style.SuwThemeGlif_Light); } @Test public void testGetThemeResGlif() { - assertEquals(R.style.SuwThemeGlif, WizardManagerHelper.getThemeRes("glif", 0)); + assertThat(WizardManagerHelper.getThemeRes("glif", 0)).isEqualTo(R.style.SuwThemeGlif); } @Test public void testGetThemeResMaterialLight() { - assertEquals( - R.style.SuwThemeMaterial_Light, WizardManagerHelper.getThemeRes("material_light", 0)); + assertThat(WizardManagerHelper.getThemeRes("material_light", 0)) + .isEqualTo(R.style.SuwThemeMaterial_Light); } @Test public void testGetThemeResMaterial() { - assertEquals(R.style.SuwThemeMaterial, WizardManagerHelper.getThemeRes("material", 0)); + assertThat(WizardManagerHelper.getThemeRes("material", 0)).isEqualTo(R.style.SuwThemeMaterial); } @Test public void testGetThemeResDefault() { @StyleRes int def = 123; - assertEquals(def, WizardManagerHelper.getThemeRes("abracadabra", def)); + assertThat(WizardManagerHelper.getThemeRes("abracadabra", def)).isEqualTo(def); } @Test public void testGetThemeResNull() { @StyleRes int def = 123; - assertEquals(def, WizardManagerHelper.getThemeRes((String) null, def)); + assertThat(WizardManagerHelper.getThemeRes((String) null, def)).isEqualTo(def); } @Test public void testGetThemeResFromIntent() { Intent intent = new Intent(); intent.putExtra(WizardManagerHelper.EXTRA_THEME, "material"); - assertEquals(R.style.SuwThemeMaterial, WizardManagerHelper.getThemeRes(intent, 0)); + assertThat(WizardManagerHelper.getThemeRes(intent, 0)).isEqualTo(R.style.SuwThemeMaterial); } @Test @@ -280,34 +283,35 @@ public class WizardManagerHelperTest { Intent intent = new Intent("test.intent.action"); WizardManagerHelper.copyWizardManagerExtras(originalIntent, intent); - assertEquals("Intent action should be kept", "test.intent.action", intent.getAction()); - assertEquals( - "EXTRA_THEME should be copied", - "test_theme", - intent.getStringExtra(WizardManagerHelper.EXTRA_THEME)); + assertWithMessage("Intent action should be kept") + .that(intent.getAction()) + .isEqualTo("test.intent.action"); + assertWithMessage("EXTRA_THEME should be copied") + .that(intent.getStringExtra(WizardManagerHelper.EXTRA_THEME)) + .isEqualTo("test_theme"); Bundle copiedWizardBundle = intent.getParcelableExtra(WizardManagerHelper.EXTRA_WIZARD_BUNDLE); - assertEquals("Wizard bundle should be copied", "bar", copiedWizardBundle.getString("foo")); + assertWithMessage("Wizard bundle should be copied") + .that(copiedWizardBundle.getString("foo")) + .isEqualTo("bar"); - assertTrue( - "EXTRA_IS_FIRST_RUN should be copied", - intent.getBooleanExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, false)); - assertTrue( - "EXTRA_IS_DEFERRED_SETUP should be copied", - intent.getBooleanExtra(WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP, false)); - assertTrue( - "EXTRA_IS_PRE_DEFERRED_SETUP should be copied", - intent.getBooleanExtra(WizardManagerHelper.EXTRA_IS_PRE_DEFERRED_SETUP, false)); + assertWithMessage("EXTRA_IS_FIRST_RUN should be copied") + .that(intent.getBooleanExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, false)) + .isTrue(); + assertWithMessage("EXTRA_IS_DEFERRED_SETUP should be copied") + .that(intent.getBooleanExtra(WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP, false)) + .isTrue(); + assertWithMessage("EXTRA_IS_PRE_DEFERRED_SETUP should be copied") + .that(intent.getBooleanExtra(WizardManagerHelper.EXTRA_IS_PRE_DEFERRED_SETUP, false)) + .isTrue(); // Script URI and Action ID are replaced by Wizard Bundle in M, but are kept for backwards // compatibility - assertEquals( - "EXTRA_SCRIPT_URI should be copied", - "test_script_uri", - intent.getStringExtra(WizardManagerHelper.EXTRA_SCRIPT_URI)); - assertEquals( - "EXTRA_ACTION_ID should be copied", - "test_action_id", - intent.getStringExtra(WizardManagerHelper.EXTRA_ACTION_ID)); + assertWithMessage("EXTRA_SCRIPT_URI should be copied") + .that(intent.getStringExtra(WizardManagerHelper.EXTRA_SCRIPT_URI)) + .isEqualTo("test_script_uri"); + assertWithMessage("EXTRA_ACTION_ID should be copied") + .that(intent.getStringExtra(WizardManagerHelper.EXTRA_ACTION_ID)) + .isEqualTo("test_action_id"); } @TargetApi(VERSION_CODES.JELLY_BEAN_MR1) @@ -315,38 +319,38 @@ public class WizardManagerHelperTest { public void testIsUserSetupComplete() { Settings.Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 1); Settings.Secure.putInt(application.getContentResolver(), "user_setup_complete", 1); - assertTrue(WizardManagerHelper.isUserSetupComplete(application)); + assertThat(WizardManagerHelper.isUserSetupComplete(application)).isTrue(); Settings.Secure.putInt(application.getContentResolver(), "user_setup_complete", 0); - assertFalse(WizardManagerHelper.isUserSetupComplete(application)); + assertThat(WizardManagerHelper.isUserSetupComplete(application)).isFalse(); } @Test @Config(sdk = VERSION_CODES.JELLY_BEAN) public void testIsUserSetupCompleteCompat() { Settings.Secure.putInt(application.getContentResolver(), Secure.DEVICE_PROVISIONED, 1); - assertTrue(WizardManagerHelper.isUserSetupComplete(application)); + assertThat(WizardManagerHelper.isUserSetupComplete(application)).isTrue(); Settings.Secure.putInt(application.getContentResolver(), Secure.DEVICE_PROVISIONED, 0); - assertFalse(WizardManagerHelper.isUserSetupComplete(application)); + assertThat(WizardManagerHelper.isUserSetupComplete(application)).isFalse(); } @TargetApi(VERSION_CODES.JELLY_BEAN_MR1) @Test public void testIsDeviceProvisioned() { Settings.Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 1); - assertTrue(WizardManagerHelper.isDeviceProvisioned(application)); + assertThat(WizardManagerHelper.isDeviceProvisioned(application)).isTrue(); Settings.Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 0); - assertFalse(WizardManagerHelper.isDeviceProvisioned(application)); + assertThat(WizardManagerHelper.isDeviceProvisioned(application)).isFalse(); } @Test @Config(sdk = VERSION_CODES.JELLY_BEAN) public void testIsDeviceProvisionedCompat() { Settings.Secure.putInt(application.getContentResolver(), Secure.DEVICE_PROVISIONED, 1); - assertTrue(WizardManagerHelper.isDeviceProvisioned(application)); + assertThat(WizardManagerHelper.isDeviceProvisioned(application)).isTrue(); Settings.Secure.putInt(application.getContentResolver(), Secure.DEVICE_PROVISIONED, 0); - assertFalse(WizardManagerHelper.isDeviceProvisioned(application)); + assertThat(WizardManagerHelper.isDeviceProvisioned(application)).isFalse(); } @Test diff --git a/library/test/robotest/src/com/android/setupwizardlib/view/FillContentLayoutTest.java b/library/test/robotest/src/com/android/setupwizardlib/view/FillContentLayoutTest.java index af302f0..001f1da 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/view/FillContentLayoutTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/view/FillContentLayoutTest.java @@ -16,18 +16,18 @@ package com.android.setupwizardlib.view; -import static org.junit.Assert.assertEquals; +import static com.google.common.truth.Truth.assertThat; import static org.robolectric.RuntimeEnvironment.application; import android.view.View; import android.view.View.MeasureSpec; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) public class FillContentLayoutTest { @@ -44,8 +44,8 @@ public class FillContentLayoutTest { MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); - assertEquals(123, layout.getMeasuredWidth()); - assertEquals(123, layout.getMeasuredHeight()); + assertThat(layout.getMeasuredWidth()).isEqualTo(123); + assertThat(layout.getMeasuredHeight()).isEqualTo(123); } @Test @@ -63,8 +63,8 @@ public class FillContentLayoutTest { MeasureSpec.makeMeasureSpec(300, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(300, MeasureSpec.EXACTLY)); - assertEquals(123, child.getMeasuredWidth()); - assertEquals(123, child.getMeasuredHeight()); + assertThat(child.getMeasuredWidth()).isEqualTo(123); + assertThat(child.getMeasuredHeight()).isEqualTo(123); } @Test @@ -82,7 +82,7 @@ public class FillContentLayoutTest { MeasureSpec.makeMeasureSpec(88, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(88, MeasureSpec.EXACTLY)); - assertEquals(88, child.getMeasuredWidth()); - assertEquals(88, child.getMeasuredHeight()); + assertThat(child.getMeasuredWidth()).isEqualTo(88); + assertThat(child.getMeasuredHeight()).isEqualTo(88); } } diff --git a/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java b/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java index c2f3f35..e980563 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java @@ -17,7 +17,6 @@ package com.android.setupwizardlib.view; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; import static org.robolectric.RuntimeEnvironment.application; @@ -27,13 +26,13 @@ import android.net.Uri; import androidx.annotation.RawRes; import android.view.View; import com.android.setupwizardlib.R; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; import org.robolectric.Shadows; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowMediaPlayer; @@ -43,7 +42,7 @@ import org.robolectric.shadows.util.DataSource; import org.robolectric.util.ReflectionHelpers; import org.robolectric.util.ReflectionHelpers.ClassParameter; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = Config.NEWEST_SDK) public class IllustrationVideoViewTest { @@ -70,8 +69,8 @@ public class IllustrationVideoViewTest { Robolectric.flushForegroundThreadScheduler(); view.start(); - assertNotNull(view.mMediaPlayer); - assertNotNull(view.surface); + assertThat(view.mMediaPlayer).isNotNull(); + assertThat(view.surface).isNotNull(); view.onWindowFocusChanged(false); assertThat(getShadowMediaPlayer().getState()).isEqualTo(ShadowMediaPlayer.State.PAUSED); @@ -91,8 +90,8 @@ public class IllustrationVideoViewTest { createDefaultView(); view.start(); - assertNotNull(view.mMediaPlayer); - assertNotNull(view.surface); + assertThat(view.mMediaPlayer).isNotNull(); + assertThat(view.surface).isNotNull(); // MediaPlayer is set to null after destroy. Retrieve it first before we call destroy. ShadowMediaPlayer shadowMediaPlayer = getShadowMediaPlayer(); diff --git a/library/test/robotest/src/com/android/setupwizardlib/view/RichTextViewTest.java b/library/test/robotest/src/com/android/setupwizardlib/view/RichTextViewTest.java index 20d1285..477c42a 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/view/RichTextViewTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/view/RichTextViewTest.java @@ -17,10 +17,7 @@ package com.android.setupwizardlib.view; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static com.google.common.truth.Truth.assertWithMessage; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -37,16 +34,15 @@ import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.TextAppearanceSpan; import android.view.MotionEvent; -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import com.android.setupwizardlib.span.LinkSpan; import com.android.setupwizardlib.span.LinkSpan.OnLinkClickListener; import com.android.setupwizardlib.view.TouchableMovementMethod.TouchableLinkMovementMethod; -import java.util.Arrays; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@RunWith(SuwLibRobolectricTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) public class RichTextViewTest { @@ -60,17 +56,19 @@ public class RichTextViewTest { textView.setText(ssb); final CharSequence text = textView.getText(); - assertTrue("Text should be spanned", text instanceof Spanned); + assertThat(text).isInstanceOf(Spanned.class); assertThat(textView.getMovementMethod()).isInstanceOf(TouchableLinkMovementMethod.class); Object[] spans = ((Spanned) text).getSpans(0, text.length(), Annotation.class); - assertEquals("Annotation should be removed " + Arrays.toString(spans), 0, spans.length); + assertThat(spans).isEmpty(); spans = ((Spanned) text).getSpans(0, text.length(), LinkSpan.class); - assertEquals("There should be one span " + Arrays.toString(spans), 1, spans.length); - assertTrue("The span should be a LinkSpan", spans[0] instanceof LinkSpan); - assertEquals("The LinkSpan should have id \"foobar\"", "foobar", ((LinkSpan) spans[0]).getId()); + assertThat(spans).hasLength(1); + assertThat(spans[0]).isInstanceOf(LinkSpan.class); + assertWithMessage("The LinkSpan should have id \"foobar\"") + .that(((LinkSpan) spans[0]).getId()) + .isEqualTo("foobar"); } @Test @@ -85,7 +83,7 @@ public class RichTextViewTest { OnLinkClickListener listener = mock(OnLinkClickListener.class); textView.setOnLinkClickListener(listener); - assertSame(listener, textView.getOnLinkClickListener()); + assertThat(textView.getOnLinkClickListener()).isSameAs(listener); CharSequence text = textView.getText(); LinkSpan[] spans = ((Spanned) text).getSpans(0, text.length(), LinkSpan.class); @@ -159,14 +157,14 @@ public class RichTextViewTest { textView.setText(ssb); final CharSequence text = textView.getText(); - assertTrue("Text should be spanned", text instanceof Spanned); + assertThat(text).isInstanceOf(Spanned.class); Object[] spans = ((Spanned) text).getSpans(0, text.length(), Annotation.class); - assertEquals("Annotation should be removed " + Arrays.toString(spans), 0, spans.length); + assertThat(spans).isEmpty(); spans = ((Spanned) text).getSpans(0, text.length(), TextAppearanceSpan.class); - assertEquals("There should be one span " + Arrays.toString(spans), 1, spans.length); - assertTrue("The span should be a TextAppearanceSpan", spans[0] instanceof TextAppearanceSpan); + assertThat(spans).hasLength(1); + assertThat(spans[0]).isInstanceOf(TextAppearanceSpan.class); } @Test @@ -178,7 +176,7 @@ public class RichTextViewTest { RichTextView view = new RichTextView(application); view.setText(spannableStringBuilder); - assertTrue("TextView should be focusable since it contains spans", view.isFocusable()); + assertThat(view.isFocusable()).named("view focusable").isTrue(); } @SuppressLint("SetTextI18n") // It's OK. This is just a test. @@ -187,9 +185,7 @@ public class RichTextViewTest { RichTextView textView = new RichTextView(application); textView.setText("Thou shall not be focusable!"); - assertFalse( - "TextView should not be focusable since it does not contain any span", - textView.isFocusable()); + assertThat(textView.isFocusable()).named("view focusable").isFalse(); } // Based on the text contents of the text view, the "focusable" property of the element @@ -200,18 +196,18 @@ public class RichTextViewTest { RichTextView textView = new RichTextView(application); textView.setText("Thou shall not be focusable!"); - assertFalse(textView.isFocusable()); - assertFalse(textView.isFocusableInTouchMode()); + assertThat(textView.isFocusable()).isFalse(); + assertThat(textView.isFocusableInTouchMode()).isFalse(); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("I am focusable"); spannableStringBuilder.setSpan(new Annotation("link", "focus:on_me"), 0, 1, 0); textView.setText(spannableStringBuilder); - assertTrue(textView.isFocusable()); + assertThat(textView.isFocusable()).isTrue(); if (VERSION.SDK_INT >= VERSION_CODES.N_MR1) { - assertTrue(textView.isFocusableInTouchMode()); - assertFalse(textView.getRevealOnFocusHint()); + assertThat(textView.isFocusableInTouchMode()).isTrue(); + assertThat(textView.getRevealOnFocusHint()).isFalse(); } else { - assertFalse(textView.isFocusableInTouchMode()); + assertThat(textView.isFocusableInTouchMode()).isFalse(); } }