@Test public void getParam_of_missing_parameter_of_unspecified_type() { Request.Param<Object> param = underTest.getParam("a_string", (rqt, key) -> { throw new IllegalStateException("retrieveAndValidate BiConsumer should not be called"); }); assertThat(param.isPresent()).isFalse(); expectSupplierCanNotBeNullNPE(() -> param.or(null)); assertThat(param.or(() -> "foo")).isEqualTo("foo"); expectGetValueFailureWithISE(param::getValue); }
@Test public void getParam_of_existing_parameter_of_unspecified_type_with_empty_string() { underTest.setParam("a_string", "value in fake request actually does not matter"); Request.Param<Object> param = underTest.getParam("a_string", (rqt, key) -> ""); assertThat(param.isPresent()).isTrue(); expectSupplierCanNotBeNullNPE(() -> param.or(null)); assertThat(param.or(() -> "foo")).isEqualTo(""); assertThat(param.getValue()).isEqualTo(""); }
@Test public void getParam_of_existing_parameter_of_unspecified_type_with_object() { underTest.setParam("a_string", "value in fake request actually does not matter"); Object value = new Object(); Request.Param<Object> param = underTest.getParam("a_string", (rqt, key) -> value); assertThat(param.isPresent()).isTrue(); expectSupplierCanNotBeNullNPE(() -> param.or(null)); assertThat(param.or(() -> "foo")).isSameAs(value); assertThat(param.getValue()).isSameAs(value); }
@Test public void getParam_of_existing_parameter_of_unspecified_type_with_null_value() { underTest.setParam("a_string", "value in fake request actually does not matter"); Request.Param<Object> param = underTest.getParam("a_string", (rqt, key) -> null); assertThat(param.isPresent()).isTrue(); expectSupplierCanNotBeNullNPE(() -> param.or(null)); assertThat(param.or(() -> "foo")).isNull(); assertThat(param.getValue()).isNull(); }