### Question:
PredicateContext implements ProcessingContext { @Override public Object resolve(String identifier) { return reservedIdentifiers.getOrDefault(identifier, attributes.getOrDefault(identifier, facts.get(identifier))); } PredicateContext(String ruleId, Object result, Map<String, Object> facts, Map<String, Object> attributes, EngineController engineController); @Override String getRuleId(); @Override Object getResult(); @Override Object resolve(String identifier); @SuppressWarnings("unchecked") @Override T resolve(String identifier, T defaultValue); PredicateContext copy(String ruleId);  }### Answer:
@Test void shouldResolveCtxToResult() { Object expected = new Object(); PredicateContext predicateContext = new PredicateContext(null, expected, Collections.emptyMap(), Collections.emptyMap(), null); String identifier = PredicateContext.CTX; Object resolved = predicateContext.resolve(identifier); assertThat(resolved).isEqualTo(expected); }
@Test void shouldResolveRuleNameToRuleId() { String ruleId = "testRuleId"; PredicateContext predicateContext = new PredicateContext(ruleId, null, Collections.emptyMap(), Collections.emptyMap(), null); String identifier = PredicateContext.RULE_NAME; Object resolved = predicateContext.resolve(identifier); assertThat(resolved).isEqualTo(ruleId); }
@Test void shouldResolveEngineControllerToEngineController() { EngineController engineController = new DefaultEngineController(Collections.emptyMap()); PredicateContext predicateContext = new PredicateContext(null, null, Collections.emptyMap(), Collections.emptyMap(), engineController); String identifier = PredicateContext.ENGINE_CONTROLLER; Object resolved = predicateContext.resolve(identifier); assertThat(resolved).isEqualTo(engineController); }
@Test void shouldResolveToAttributeValue() { Map<String, Object> attributes = Collections.singletonMap("key", "attributeValue"); Map<String, Object> facts = Collections.singletonMap("key", "factValue"); PredicateContext predicateContext = new PredicateContext(null, null, facts, attributes, null); String identifier = "key"; Object resolved = predicateContext.resolve(identifier); assertThat(resolved).isEqualTo("attributeValue"); }
@Test void shouldResolveToFactValue() { Map<String, Object> attributes = Collections.singletonMap("attributeKey", "attributeValue"); Map<String, Object> facts = Collections.singletonMap("factKey", "factValue"); PredicateContext predicateContext = new PredicateContext(null, null, facts, attributes, null); String identifier = "factKey"; Object resolved = predicateContext.resolve(identifier); assertThat(resolved).isEqualTo("factValue"); }
@Test void shouldResolveToNullWhenUnknownIdentifier() { Map<String, Object> attributes = Collections.singletonMap("attributeKey", "attributeValue"); Map<String, Object> facts = Collections.singletonMap("factKey", "factValue"); PredicateContext predicateContext = new PredicateContext("ruleId", "result", facts, attributes, new DefaultEngineController(Collections.emptyMap())); String identifier = "unknownIdentifier"; Object resolved = predicateContext.resolve(identifier); assertThat(resolved).isNull(); }