From f6c76edeff56ad7c8b1f3370dfd881d14cba0bbe Mon Sep 17 00:00:00 2001 From: isabellekim Date: Thu, 20 Jun 2019 11:42:45 -0400 Subject: [PATCH] Update tests for RippleUtils.shouldDrawRippleCompat to use parameters. PiperOrigin-RevId: 254204375 --- ...RippleUtilsShouldDrawRippleCompatTest.java | 85 +++++++++++++++++++ .../material/ripple/RippleUtilsTest.java | 81 ------------------ 2 files changed, 85 insertions(+), 81 deletions(-) create mode 100644 lib/javatests/com/google/android/material/ripple/RippleUtilsShouldDrawRippleCompatTest.java delete mode 100644 lib/javatests/com/google/android/material/ripple/RippleUtilsTest.java diff --git a/lib/javatests/com/google/android/material/ripple/RippleUtilsShouldDrawRippleCompatTest.java b/lib/javatests/com/google/android/material/ripple/RippleUtilsShouldDrawRippleCompatTest.java new file mode 100644 index 000000000..bea6788da --- /dev/null +++ b/lib/javatests/com/google/android/material/ripple/RippleUtilsShouldDrawRippleCompatTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2019 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.google.android.material.ripple; + +import static com.google.common.truth.Truth.assertThat; + +import java.util.Arrays; +import java.util.List; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.ParameterizedRobolectricTestRunner; + +/** Unit tests for {@link RippleUtils#shouldDrawRippleCompat}. */ +@RunWith(ParameterizedRobolectricTestRunner.class) +public class RippleUtilsShouldDrawRippleCompatTest { + + @ParameterizedRobolectricTestRunner.Parameter(0) + public String stateDescription; + + @ParameterizedRobolectricTestRunner.Parameter(1) + public int[] stateSet; + + @ParameterizedRobolectricTestRunner.Parameter(2) + public boolean shouldDrawRippleCompat; + + /** + * Parameterized test data for this class. Returns a {@link List} of {@link Object} arrays that + * include: + *
  • Description of the states set (used for the test name since int[] toString is not very + * descriptive) + *
  • The int[] of states to pass to shouldDrawRippleCompat + *
  • The expected value of shouldDrawRippleCompat + */ + @ParameterizedRobolectricTestRunner.Parameters(name = "States: {0} Result: {2}") + public static List getTestData() { + Object[][] data = { + {"disabled", new int[] {}, false}, + {"disabled, pressed", new int[] {android.R.attr.state_pressed}, false}, + {"enabled", new int[] {android.R.attr.state_enabled}, false}, + { + "enabled, pressed", + new int[] {android.R.attr.state_enabled, android.R.attr.state_pressed}, + true + }, + { + "enabled, focused", + new int[] {android.R.attr.state_enabled, android.R.attr.state_focused}, + true + }, + { + "enabled, pressed, focused", + new int[] { + android.R.attr.state_enabled, android.R.attr.state_pressed, android.R.attr.state_focused + }, + true + }, + { + "enabled, hovered", + new int[] {android.R.attr.state_enabled, android.R.attr.state_hovered}, + true + }, + }; + return Arrays.asList(data); + } + + /** Tests shouldDrawRippleCompat for the sets of states defined in {@link #getTestData}. */ + @Test + public void testShouldDrawRippleCompat() { + assertThat(RippleUtils.shouldDrawRippleCompat(stateSet)).isEqualTo(shouldDrawRippleCompat); + } +} diff --git a/lib/javatests/com/google/android/material/ripple/RippleUtilsTest.java b/lib/javatests/com/google/android/material/ripple/RippleUtilsTest.java deleted file mode 100644 index 77d9a1158..000000000 --- a/lib/javatests/com/google/android/material/ripple/RippleUtilsTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2019 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.google.android.material.ripple; - -import static com.google.common.truth.Truth.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -/** Unit tests for {@link RippleUtils}. */ -@RunWith(RobolectricTestRunner.class) -public class RippleUtilsTest { - - @Test - public void testShouldDrawRippleCompat_disabled_returnsFalse() { - assertThat(RippleUtils.shouldDrawRippleCompat(new int[] {})).isFalse(); - } - - @Test - public void testShouldDrawRippleCompat_disabledAndPressed_returnsFalse() { - assertThat(RippleUtils.shouldDrawRippleCompat(new int[] {android.R.attr.state_pressed})) - .isFalse(); - } - - @Test - public void testShouldDrawRippleCompat_enabled_returnsFalse() { - assertThat(RippleUtils.shouldDrawRippleCompat(new int[] {android.R.attr.state_enabled})) - .isFalse(); - } - - @Test - public void testShouldDrawRippleCompat_enabledAndPressed_returnsTrue() { - assertThat( - RippleUtils.shouldDrawRippleCompat( - new int[] {android.R.attr.state_enabled, android.R.attr.state_pressed})) - .isTrue(); - } - - @Test - public void testShouldDrawRippleCompat_enabledAndFocused_returnsTrue() { - assertThat( - RippleUtils.shouldDrawRippleCompat( - new int[] {android.R.attr.state_enabled, android.R.attr.state_focused})) - .isTrue(); - } - - @Test - public void testShouldDrawRippleCompat_enabledPressedAndFocused_returnsTrue() { - assertThat( - RippleUtils.shouldDrawRippleCompat( - new int[] { - android.R.attr.state_enabled, - android.R.attr.state_pressed, - android.R.attr.state_focused - })) - .isTrue(); - } - - @Test - public void testShouldDrawRippleCompat_enabledAndHovered_returnsTrue() { - assertThat( - RippleUtils.shouldDrawRippleCompat( - new int[] {android.R.attr.state_enabled, android.R.attr.state_hovered})) - .isTrue(); - } -}