### Question:
Spec { public List<Rule> getRules() { return rules; } Spec(); String getName(); Spec setName(String name); Map<String, DeclaredType> getTypes(); Map<String, Input> getInputs(); List<Rule> getRules(); Spec setRules(List<Rule> rules); String getOutput(); void setOutput(String output); void validateType(String type); boolean isValidType(String type); boolean mustParse(String input, String field); static final String FIELD_NAME; static final String FIELD_TYPES; static final String FIELD_INPUTS; static final String FIELD_RULES; static final String FIELD_OUTPUT; }### Answer:
@Test public void testParseRules() throws IOException { JsonArray rules = buildRules(); JsonObject json = Json.createObjectBuilder() .add(Spec.FIELD_INPUTS, buildInputs()) .add(Spec.FIELD_TYPES, buildTypes()) .add(Spec.FIELD_RULES, rules) .add(Spec.FIELD_OUTPUT, FieldType.STRING.getValue()) .build(); Spec spec = parseSpec(json); assertNotNull(spec); assertEquals(3, spec.getRules().size()); assertEquals(2, spec.getRules().get(0).getWhen().size()); assertEquals("manager.name != Joe", spec.getRules().get(0).getWhen().get(0)); assertEquals("nice == false", spec.getRules().get(0).getWhen().get(1)); assertEquals("$manager.name is not nice", ((Map<String, String>)spec.getRules().get(0).getThen().getMultipleOutput()).get("message")); assertEquals(2, spec.getRules().get(1).getWhen().size()); assertEquals("manager.name != Joe", spec.getRules().get(1).getWhen().get(0)); assertEquals("nice == true", spec.getRules().get(1).getWhen().get(1)); assertEquals("$manager.name is nice", ((Map<String, String>)spec.getRules().get(1).getThen().getMultipleOutput()).get("message")); assertEquals(1, spec.getRules().get(2).getWhen().size()); assertEquals("manager.name == Joe", spec.getRules().get(2).getWhen().get(0)); assertEquals("$manager.name is always nice", ((Map<String, String>)spec.getRules().get(2).getThen().getMultipleOutput()).get("message")); }