@Test(expected = IllegalStateException.class) public void whenAccessingVariablesAndUrlIsInvalidThenExceptionIsThrown() { RestParser parser = parser("/countries/{}", strVar("countryId")); RestUrl url = parser.parse("http: assertThat(url, isInvalid()); url.variable("countryId"); }
public <T> T variable(String variableId) { checkArgumentNotNullOrEmpty(variableId); checkState(isValid(), "Variables are not accessible for invalid URLs"); for (int i = 0; i < types.length; i++) { if (types[i].getId().equals(variableId)) { return (T) values[i]; } } throw new IllegalArgumentException("Variable id '" + variableId + "' is not declared in the pattern"); }
RestUrl { public <T> T variable(String variableId) { checkArgumentNotNullOrEmpty(variableId); checkState(isValid(), "Variables are not accessible for invalid URLs"); for (int i = 0; i < types.length; i++) { if (types[i].getId().equals(variableId)) { return (T) values[i]; } } throw new IllegalArgumentException("Variable id '" + variableId + "' is not declared in the pattern"); } }
RestUrl { public <T> T variable(String variableId) { checkArgumentNotNullOrEmpty(variableId); checkState(isValid(), "Variables are not accessible for invalid URLs"); for (int i = 0; i < types.length; i++) { if (types[i].getId().equals(variableId)) { return (T) values[i]; } } throw new IllegalArgumentException("Variable id '" + variableId + "' is not declared in the pattern"); } private  RestUrl(VarType[] types, Object[] values, String errorMsg); }
RestUrl { public <T> T variable(String variableId) { checkArgumentNotNullOrEmpty(variableId); checkState(isValid(), "Variables are not accessible for invalid URLs"); for (int i = 0; i < types.length; i++) { if (types[i].getId().equals(variableId)) { return (T) values[i]; } } throw new IllegalArgumentException("Variable id '" + variableId + "' is not declared in the pattern"); } private  RestUrl(VarType[] types, Object[] values, String errorMsg); boolean isValid(); String errorMessage(); T variable(String variableId); }
RestUrl { public <T> T variable(String variableId) { checkArgumentNotNullOrEmpty(variableId); checkState(isValid(), "Variables are not accessible for invalid URLs"); for (int i = 0; i < types.length; i++) { if (types[i].getId().equals(variableId)) { return (T) values[i]; } } throw new IllegalArgumentException("Variable id '" + variableId + "' is not declared in the pattern"); } private  RestUrl(VarType[] types, Object[] values, String errorMsg); boolean isValid(); String errorMessage(); T variable(String variableId);  }