### Question:
DefaultCaseValidator extends Validator { @Override public void validate(UastNode node) { is(UastNode.Kind.DEFAULT_CASE); hasKeyword("default"); noChild(UastNode.Kind.CONDITION); } DefaultCaseValidator(); @Override void validate(UastNode node);  }### Answer:
@Test public void expected() throws Exception { UastNode caseNode = node(Sets.newHashSet(UastNode.Kind.DEFAULT_CASE, UastNode.Kind.CASE), keyword("default"), token(":")); UastNode node = node(UastNode.Kind.SWITCH, caseNode); try { validate(node); } catch (Exception e) { fail("should not have failed", e); } }
@Test public void wrong_keyword() throws Exception { UastNode caseNode = node(Sets.newHashSet(UastNode.Kind.DEFAULT_CASE, UastNode.Kind.CASE), keyword("case"), token(":")); UastNode node = node(UastNode.Kind.SWITCH, caseNode); Validator.ValidationException exception = assertThrows(Validator.ValidationException.class, () -> validate(node)); assertThat(exception.getMessage()).isEqualTo("DefaultCaseValidator at line 1: Expected 'default' as keyword but got 'case'."); }
@Test public void should_not_have_condition() throws Exception { UastNode caseNode = node(Sets.newHashSet(UastNode.Kind.DEFAULT_CASE, UastNode.Kind.CASE), keyword("default"), node(UastNode.Kind.CONDITION), token(":")); UastNode node = node(UastNode.Kind.SWITCH, caseNode); Validator.ValidationException exception = assertThrows(Validator.ValidationException.class, () -> validate(node)); assertThat(exception.getMessage()).isEqualTo("DefaultCaseValidator at line 1: Should not have any child of kind 'CONDITION'."); }