Switch to `assertThrows` where applicable.
@@ -27,7 +27,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;
import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.fail;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
@@ -2726,15 +2725,15 @@ public final class CompilerTest {
CompilerOptions options = new CompilerOptions();
Compiler compiler = new Compiler();
- try {
- compiler.initModules(ImmutableList.of(), ImmutableList.of(strong, weak), options);
- fail();
- } catch (RuntimeException e) {
+ RuntimeException e =
+ assertThrows(
+ RuntimeException.class,
+ () ->
+ compiler.initModules(ImmutableList.of(), ImmutableList.of(strong, weak), options));
assertThat(e)
.hasMessageThat()
.contains("Found these strong sources in the weak chunk:\n weak_but_actually_strong.js");
}
- }
@Test
public void testPreexistingWeakModuleWithMissingWeakSources() throws Exception {
@@ -2749,17 +2748,17 @@ public final class CompilerTest {
CompilerOptions options = new CompilerOptions();
Compiler compiler = new Compiler();
- try {
- compiler.initModules(ImmutableList.of(), ImmutableList.of(strong, weak), options);
- fail();
- } catch (RuntimeException e) {
+ RuntimeException e =
+ assertThrows(
+ RuntimeException.class,
+ () ->
+ compiler.initModules(ImmutableList.of(), ImmutableList.of(strong, weak), options));
assertThat(e)
.hasMessageThat()
.contains(
"Found these weak sources in other chunks:\n"
+ " strong_but_actually_weak.js (in chunk m)");
}
- }
@Test
public void testPreexistingWeakModuleWithIncorrectDependencies() throws Exception {
@@ -2771,15 +2770,15 @@ public final class CompilerTest {
CompilerOptions options = new CompilerOptions();
Compiler compiler = new Compiler();
- try {
- compiler.initModules(ImmutableList.of(), ImmutableList.of(m1, m2, weak), options);
- fail();
- } catch (RuntimeException e) {
+ RuntimeException e =
+ assertThrows(
+ RuntimeException.class,
+ () ->
+ compiler.initModules(ImmutableList.of(), ImmutableList.of(m1, m2, weak), options));
assertThat(e)
.hasMessageThat()
.isEqualTo("A weak chunk already exists but it does not depend on every other chunk.");
}
- }
@Test
public void testImplicitWeakSourcesWithEntryPoint() throws Exception {
