Commit 845b55d2 by olly Committed by Ian Baker

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
parent 191629ed
...@@ -22,6 +22,7 @@ import static android.graphics.Color.argb; ...@@ -22,6 +22,7 @@ import static android.graphics.Color.argb;
import static android.graphics.Color.parseColor; import static android.graphics.Color.parseColor;
import static androidx.media3.common.util.ColorParser.parseTtmlColor; import static androidx.media3.common.util.ColorParser.parseTtmlColor;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import android.graphics.Color; import android.graphics.Color;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
...@@ -34,24 +35,26 @@ public final class ColorParserTest { ...@@ -34,24 +35,26 @@ public final class ColorParserTest {
// Negative tests. // Negative tests.
@Test(expected = IllegalArgumentException.class) @Test
public void parseUnknownColor() { public void parseUnknownColor() {
ColorParser.parseTtmlColor("colorOfAnElectron"); assertThrows(
IllegalArgumentException.class, () -> ColorParser.parseTtmlColor("colorOfAnElectron"));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void parseNull() { public void parseNull() {
ColorParser.parseTtmlColor(null); assertThrows(IllegalArgumentException.class, () -> ColorParser.parseTtmlColor(null));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void parseEmpty() { public void parseEmpty() {
ColorParser.parseTtmlColor(""); assertThrows(IllegalArgumentException.class, () -> ColorParser.parseTtmlColor(""));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void rgbColorParsingRgbValuesNegative() { public void rgbColorParsingRgbValuesNegative() {
ColorParser.parseTtmlColor("rgb(-4, 55, 209)"); assertThrows(
IllegalArgumentException.class, () -> ColorParser.parseTtmlColor("rgb(-4, 55, 209)"));
} }
// Positive tests. // Positive tests.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment