@Test public void shouldNotPassForNullValue() { // given expectedException.expect(WebSuitesException.class); // then sut.validateParam(null); }
private void expectValidationException(String requiredParams, String optionalParams) { expectedException .expect(WebSuitesException.class) .hasMessageStartingWith("Given parameters") .hasMessageContaining("don't match command allowed parameters") .hasMessageContaining(requiredParams) .hasMessageContaining(optionalParams); }
@Parameters({"", "f", "t", "yes", "no", "TRUEe", "FALSEE"}) @Test public void shouldNotPassBooleanParamValidation(String param) { // given expectedException .expect(WebSuitesException.class) .hasMessageContaining("must be proper BOOLEAN value") .hasMessageContaining("testParam") .hasMessageContaining(param); // then sut.validateParam(param); }
@Parameters({"-12,0,-13", "-1,3,4", "100,200,2000000", "100,200,99", "100,200,-100"}) @Test public void shouldNotPassValidationParamNumericValueBetween(int a, int b, int value) { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); sut = new CommandSchemaValidator(rule); sut.addParameterValueValidator(new IntegerNumberParamValidator("topElem", a, b)); // and Map<String, String> params = new HashMap<String, String>(); params.put("topElem", value + ""); // and expectedException .expect(WebSuitesException.class) .hasMessage("Integer value for param topElem must be between " + a + " and " + b); // then sut.validateCommandSchema(params); }
@Parameters({"", "not numeric", "--2", "dd2", "34sfe"}) @Test public void shouldNotPassValidationInvalidParamNumericValueNotNumber(String paramValue) { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); sut = new CommandSchemaValidator(rule); sut.addParameterValueValidator(new IntegerNumberParamValidator("topElem")); // and Map<String, String> params = new HashMap<String, String>(); params.put("topElem", paramValue); // and expectedException .expect(WebSuitesException.class) .hasMessageStartingWith("Parameter topElem") .hasMessageContaining("must be proper integer value"); // then sut.validateCommandSchema(params); }