Migrate from strongly discouraged @Test(expected = ...) to assertThrows(...).

More info: go/lsc-assertthrows and go/assertthrows

NOTE: if the source of truth for this code is _NOT_ `//third_party/`, please ask for this CL to be reverted.

Tested:
    TAP --sample ran all affected tests and none failed
    http://test/OCL:434925976:BASE:434869111:1647399186064:de338189
PiperOrigin-RevId: 435047509
This commit is contained in:
olly 2022-03-16 14:46:13 +00:00 committed by Ian Baker
parent 191629ed7c
commit 845b55d230

View file

@ -22,6 +22,7 @@ import static android.graphics.Color.argb;
import static android.graphics.Color.parseColor;
import static androidx.media3.common.util.ColorParser.parseTtmlColor;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import android.graphics.Color;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@ -34,24 +35,26 @@ public final class ColorParserTest {
// Negative tests.
@Test(expected = IllegalArgumentException.class)
@Test
public void parseUnknownColor() {
ColorParser.parseTtmlColor("colorOfAnElectron");
assertThrows(
IllegalArgumentException.class, () -> ColorParser.parseTtmlColor("colorOfAnElectron"));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void parseNull() {
ColorParser.parseTtmlColor(null);
assertThrows(IllegalArgumentException.class, () -> ColorParser.parseTtmlColor(null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void parseEmpty() {
ColorParser.parseTtmlColor("");
assertThrows(IllegalArgumentException.class, () -> ColorParser.parseTtmlColor(""));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void rgbColorParsingRgbValuesNegative() {
ColorParser.parseTtmlColor("rgb(-4, 55, 209)");
assertThrows(
IllegalArgumentException.class, () -> ColorParser.parseTtmlColor("rgb(-4, 55, 209)"));
}
// Positive tests.