### Question:
SwitchValidator extends Validator { @Override public void validate(UastNode t) { is(UastNode.Kind.SWITCH); hasKeyword("switch"); } SwitchValidator(); @Override void validate(UastNode t);  }### Answer:
@Test public void expected() throws Exception { UastNode switchNode = node(Sets.newHashSet(UastNode.Kind.SWITCH), keyword("switch")); try { validate(switchNode); } catch (Exception e) { fail("should not have failed", e); } }
@Test public void do_not_have_switch_keyword() throws Exception { UastNode switchNode = node(Sets.newHashSet(UastNode.Kind.SWITCH), keyword("label")); Validator.ValidationException exception = assertThrows(Validator.ValidationException.class, () -> validate(switchNode)); assertThat(exception.getMessage()).isEqualTo("SwitchValidator at line 1: Expected 'switch' as keyword but got 'label'."); }