### Question:
RuleOutputList { public RuleOutput applySingle(HitPolicy hitPolicy) { if (hitPolicy == null) { hitPolicy = HitPolicy.UNIQUE; } if (hitPolicy == HitPolicy.UNIQUE) { if (this.matchedRuleResults.size() == 1) { return this.matchedRuleResults.get(0); } else { return null; } } else if (hitPolicy == HitPolicy.ANY) { if (this.matchedRuleResults.size() > 0) { Set<RuleOutput> distinctResults = new HashSet<>(this.matchedRuleResults); if (distinctResults.size() == 1) { return distinctResults.iterator().next(); } else { return null; } } else { return null; } } else if (hitPolicy == HitPolicy.FIRST) { if (this.matchedRuleResults.size() > 0) { return this.matchedRuleResults.get(0); } else { return null; } } else if (hitPolicy == HitPolicy.PRIORITY) { if (this.matchedRuleResults.size() > 0) { List<RuleOutput> sortedRuleOutputs = sort(this.matchedRuleResults); return sortedRuleOutputs.get(0); } else { return null; } } else { throw new UnsupportedOperationException(String.format("Not supported single hit policy %s.", hitPolicy.name())); } }  void add(RuleOutput result); List<RuleOutput> getMatchedRuleResults(); boolean noMatchedRules(); RuleOutput applySingle(HitPolicy hitPolicy); List<? extends RuleOutput> applyMultiple(HitPolicy hitPolicy);  }### Answer:
@Test public void testApplyUnique() { assertEquals(STRING_1, makeRuleResultList(STRING_1).applySingle(UNIQUE)); assertEquals(null, makeRuleResultList(STRING_1, STRING_1).applySingle(UNIQUE)); assertEquals(null, makeRuleResultList(STRING_LIST_1, STRING_LIST_1).applySingle(UNIQUE)); assertEquals(null, makeRuleResultList().applySingle(UNIQUE)); }
@Test public void testApplyFirst() { assertEquals(STRING_1, makeRuleResultList(STRING_1, STRING_1).applySingle(FIRST)); assertEquals(STRING_2, makeRuleResultList(STRING_2, STRING_1).applySingle(FIRST)); assertEquals(STRING_LIST_2, makeRuleResultList(STRING_LIST_2, STRING_LIST_1).applySingle(FIRST)); assertEquals(null, makeRuleResultList().applySingle(FIRST)); }
@Test public void testApplyPriority() { assertEquals(STRING_1.getOutput(), ((DefaultSimpleOutput)makeRuleResultList(STRING_2, STRING_1).applySingle(PRIORITY)).getOutput()); assertEquals(null, makeRuleResultList().applySingle(PRIORITY)); }
@Test public void testApplyAny() { assertEquals(STRING_1, makeRuleResultList(STRING_1, STRING_1).applySingle(ANY)); assertEquals(null, makeRuleResultList().applySingle(ANY)); }