@Test public void testCheckTypes_referencedQuestionDoesNotExistInQLIsInvalid() { String questionLabel = "thisQuestionDoesNotExistInQL"; Questionnaire questionnaire = aQuestionnaire().build(); List<Page> pages = new ArrayList<>(); List<Section> sections = new ArrayList<>(); Question question = new Question(aTextLocation().build(), questionLabel, null); List<Question> questionNames = Arrays.asList(question); sections.add(SectionBuilder.aSection().withQuestions(questionNames).build()); pages.add(PageBuilder.aPage().withSections(sections).build()); Stylesheet stylesheet = aStylesheet().withPages(pages).build(); TypeChecker typeChecker = new TypeChecker(stylesheet, questionnaire); List<TypeValidation> validations = typeChecker.checkTypes(); assertThat(validations.toString(), validations.size(), is(1)); ValidationMessage validationMessage = validations.get(0); assertThat(validationMessage.getValidationMessage(), is("Question 'thisQuestionDoesNotExistInQL' does not exist in questionnaire")); }
public List<TypeValidation> checkTypes() { List<TypeValidation> validations = new ArrayList<>(); List<Page> pages = stylesheet.getPages(); for (Page page : pages) { List<Section> sections = page.getSections(); for (Section section : sections) { validations.addAll(section.accept(this)); } } return validations; }
TypeChecker implements AstVisitor<List<TypeValidation>> { public List<TypeValidation> checkTypes() { List<TypeValidation> validations = new ArrayList<>(); List<Page> pages = stylesheet.getPages(); for (Page page : pages) { List<Section> sections = page.getSections(); for (Section section : sections) { validations.addAll(section.accept(this)); } } return validations; } }
TypeChecker implements AstVisitor<List<TypeValidation>> { public List<TypeValidation> checkTypes() { List<TypeValidation> validations = new ArrayList<>(); List<Page> pages = stylesheet.getPages(); for (Page page : pages) { List<Section> sections = page.getSections(); for (Section section : sections) { validations.addAll(section.accept(this)); } } return validations; } TypeChecker(Stylesheet stylesheet, Questionnaire questionnaire); }
TypeChecker implements AstVisitor<List<TypeValidation>> { public List<TypeValidation> checkTypes() { List<TypeValidation> validations = new ArrayList<>(); List<Page> pages = stylesheet.getPages(); for (Page page : pages) { List<Section> sections = page.getSections(); for (Section section : sections) { validations.addAll(section.accept(this)); } } return validations; } TypeChecker(Stylesheet stylesheet, Questionnaire questionnaire); List<TypeValidation> checkTypes(); @Override List<TypeValidation> visit(Section section); @Override List<TypeValidation> visit(Question question); }
TypeChecker implements AstVisitor<List<TypeValidation>> { public List<TypeValidation> checkTypes() { List<TypeValidation> validations = new ArrayList<>(); List<Page> pages = stylesheet.getPages(); for (Page page : pages) { List<Section> sections = page.getSections(); for (Section section : sections) { validations.addAll(section.accept(this)); } } return validations; } TypeChecker(Stylesheet stylesheet, Questionnaire questionnaire); List<TypeValidation> checkTypes(); @Override List<TypeValidation> visit(Section section); @Override List<TypeValidation> visit(Question question);  }