RulesImporter { public void importObject(Reader reader) throws IOException { Rules existingRules = curator.getRules(); Rules newRules = new Rules(StringFromReader.asString(reader)); if (VersionUtil.getRulesVersionCompatibility(existingRules.getVersion(), newRules.getVersion())) { log.info("Importing new rules from manifest, current version: " + existingRules.getVersion() + " new version: " + newRules.getVersion()); curator.update(newRules); sink.emitRulesModified(existingRules, newRules); jsProvider.compileRules(); } else { log.info("Ignoring older rules in manifest, current version: " + existingRules.getVersion() + " new version: " + newRules.getVersion()); } } @Inject  RulesImporter(RulesCurator curator, EventSink sink, JsRunnerProvider jsProvider); void importObject(Reader reader);  }
@Test public void importNewerRulesSameApi() throws IOException { Rules currentRules = new Rules(" when(curator.getRules()).thenReturn(currentRules); importer.importObject(new StringReader(" verify(curator).update(any(Rules.class)); }
@Test public void importSkipsOlderRulesSameApi() throws IOException { Rules currentRules = new Rules(" when(curator.getRules()).thenReturn(currentRules); importer.importObject(new StringReader(" verify(curator, never()).update(any(Rules.class)); }
@Test public void importSkipsOlderRulesDifferentApi() throws IOException { Rules currentRules = new Rules(" when(curator.getRules()).thenReturn(currentRules); importer.importObject(new StringReader(" verify(curator, never()).update(any(Rules.class)); }
@Test public void importSkipsNewerRulesDifferentApi() throws IOException { Rules currentRules = new Rules(" when(curator.getRules()).thenReturn(currentRules); importer.importObject(new StringReader(" verify(curator, never()).update(any(Rules.class)); }