@Rule
public ExpectedException expectedException = ExpectedException.none();
- FakeRequest underTest = new FakeRequest();
+ private FakeRequest underTest = new FakeRequest();
@Before
public void before() {
underTest.setParam(param, "11").param(param);
}
+ @Test
+ public void paramAsInt_throws_IAE_if_maximum_defined_and_value_not_a_number() {
+ String param = "maximum_value_param";
+ defineParameterTestAction(newParam -> newParam.setMaximumValue(10), param);
+
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("'maximum_value_param' value 'foo' cannot be parsed as an integer");
+
+ underTest.setParam(param, "foo").paramAsInt(param);
+ }
+
@Test
public void required_param_as_strings() {
underTest.setParam("a_required_string", "foo,bar");
}
@Test
- public void param_as_int() {
+ public void paramAsInt() {
assertThat(underTest.setParam("a_number", "123").paramAsInt("a_number")).isEqualTo(123);
assertThat(underTest.setParam("a_number", "123").paramAsInt("a_number", 42)).isEqualTo(123);
assertThat(underTest.setParam("a_number", null).paramAsInt("a_number", 42)).isEqualTo(123);
}
@Test
- public void param_as_part() throws Exception {
+ public void param_as_part() {
InputStream inputStream = mock(InputStream.class);
underTest.setPart("key", inputStream, "filename");
}
@Test
- public void mandatory_param_as_part() throws Exception {
+ public void mandatory_param_as_part() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The 'required_param' parameter is missing");