### Question:
CentralizedManifest implements Manifest { LinkedHashMap<String, CentralizedRule> rebuild(Map<String, CentralizedRule> old, List<SamplingRule> inputs) { List<CentralizedRule> rules = new ArrayList<>(inputs.size() - 1); for (SamplingRule i : inputs) { if (i.getRuleName().equals(CentralizedRule.DEFAULT_RULE_NAME)) { continue; } CentralizedRule r = old.get(i.getRuleName()); if (r == null) { r = new CentralizedRule(i, new RandImpl()); } rules.add(r); } Collections.sort(rules); LinkedHashMap<String, CentralizedRule> current = new LinkedHashMap<>(rules.size()); for (CentralizedRule r: rules) { current.put(r.getName(), r); } return current; } CentralizedManifest(); LinkedHashMap<String, CentralizedRule> getRules(); @Nullable CentralizedRule getDefaultRule(); boolean isExpired(Instant now); int size(); @Override // TODO(anuraaga): It seems like this should never return null, check where defaultRule is guaranteed to be present and remove @Nullable Rule match(SamplingRequest req, Instant now); void putRules(List<SamplingRule> inputs, Instant now); List<SamplingStatisticsDocument> snapshots(Instant now); void putTargets(List<SamplingTargetDocument> targets, Instant now);  }### Answer:
@Test void testRebuild() { Map<String, CentralizedRule> rules = new HashMap<>(); rules.put("r1", new CentralizedRule(rule("r1").withPriority(11), new RandImpl())); rules.put("r2", new CentralizedRule(rule("r2"), new RandImpl())); List<SamplingRule> inputs = new ArrayList<>(); inputs.add(rule("r2")); inputs.add(rule("r1")); inputs.add(rule("r3")); CentralizedManifest m = new CentralizedManifest(); Map<String, CentralizedRule> rebuiltRules = m.rebuild(rules, inputs); Assertions.assertEquals(3, rebuiltRules.size()); String[] orderedList = new String[3]; rebuiltRules.keySet().toArray(orderedList); Assertions.assertEquals("r2", orderedList[0]); Assertions.assertEquals("r3", orderedList[1]); Assertions.assertEquals("r1", orderedList[2]); }