Automatically refactor more exception testing to use new JUnit rules

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178911894
This commit is contained in:
mcilwain 2017-08-14 09:20:03 -04:00 committed by Ben McIlwain
parent 36ad38e5df
commit 7dc224627f
125 changed files with 1970 additions and 1982 deletions

View file

@ -15,22 +15,18 @@
package google.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.beust.jcommander.ParameterException;
import org.joda.money.Money;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link MoneyParameter}. */
@RunWith(JUnit4.class)
public class MoneyParameterTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private final MoneyParameter instance = new MoneyParameter();
@Test
@ -55,33 +51,29 @@ public class MoneyParameterTest {
@Test
public void testConvert_badCurrency_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("FOO 1337");
assertThrows(IllegalArgumentException.class, () -> instance.convert("FOO 1337"));
}
@Test
public void testConvert_null_throws() throws Exception {
thrown.expect(NullPointerException.class);
instance.convert(null);
assertThrows(NullPointerException.class, () -> instance.convert(null));
}
@Test
public void testConvert_empty_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("");
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
}
@Test
public void testConvert_sillyString_throws() throws Exception {
thrown.expect(IllegalArgumentException.class);
instance.convert("foo");
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
}
@Test
public void testValidate_sillyString_throws() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--money=foo not valid");
instance.validate("--money", "foo");
ParameterException thrown =
expectThrows(ParameterException.class, () -> instance.validate("--money", "foo"));
assertThat(thrown).hasMessageThat().contains("--money=foo not valid");
}
@Test