Automatically refactor more exception testing to use new JUnit rules

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179072309
This commit is contained in:
mcilwain 2017-12-14 11:40:04 -08:00 committed by Ben McIlwain
parent d5d29959b4
commit 9157930983
100 changed files with 3900 additions and 3192 deletions

View file

@ -14,7 +14,9 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.request.JsonResponse.JSON_SAFETY_PREFIX;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.ResourceUtils.readResourceUtf8;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyMapOf;
@ -92,16 +94,16 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
any(byte[].class)))
.thenReturn(
JSON_SAFETY_PREFIX + "{\"status\":\"error\",\"error\":\"foo already exists\"}");
thrown.expect(VerifyException.class);
thrown.expectMessage("Server error:");
runCommandForced("-i=" + premiumTermsPath, "-n=foo");
VerifyException thrown =
expectThrows(
VerifyException.class, () -> runCommandForced("-i=" + premiumTermsPath, "-n=foo"));
assertThat(thrown).hasMessageThat().contains("Server error:");
}
@Test
public void testRun_noInputFileSpecified_throwsException() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("The following option is required");
runCommand();
ParameterException thrown = expectThrows(ParameterException.class, () -> runCommand());
assertThat(thrown).hasMessageThat().contains("The following option is required");
}
@Test
@ -110,8 +112,10 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
"tmp_file2",
readResourceUtf8(
CreatePremiumListCommandTest.class, "testdata/example_invalid_premium_terms.csv"));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Could not parse line in premium list");
runCommandForced("-i=" + premiumTermsPath, "-n=foo");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("-i=" + premiumTermsPath, "-n=foo"));
assertThat(thrown).hasMessageThat().contains("Could not parse line in premium list");
}
}