ParserRunnerImpl implements ParserRunner<JSONObject>, Serializable { @Override public void init(Supplier<ParserConfigurations> parserConfigSupplier, Context stellarContext) { if (parserConfigSupplier == null) { throw new IllegalStateException("A parser config supplier must be set before initializing the ParserRunner."); } if (stellarContext == null) { throw new IllegalStateException("A stellar context must be set before initializing the ParserRunner."); } this.stellarContext = stellarContext; initializeParsers(parserConfigSupplier); } ParserRunnerImpl(HashSet<String> sensorTypes); Map<String, ParserComponent> getSensorToParserComponentMap(); void setSensorToParserComponentMap(Map<String, ParserComponent> sensorToParserComponentMap); Context getStellarContext(); @Override Set<String> getSensorTypes(); @Override void init(Supplier<ParserConfigurations> parserConfigSupplier, Context stellarContext); @Override ParserRunnerResults<JSONObject> execute(String sensorType, RawMessage rawMessage, ParserConfigurations parserConfigurations);  }
@Test public void shouldThrowExceptionOnEmptyParserSupplier() { IllegalStateException e = assertThrows(IllegalStateException.class, () -> parserRunner.init(null, null)); assertEquals("A parser config supplier must be set before initializing the ParserRunner.", e.getMessage()); }
@Test public void shouldThrowExceptionOnEmptyStellarContext() { IllegalStateException e = assertThrows(IllegalStateException.class, () -> parserRunner.init(() -> parserConfigurations, null)); assertEquals("A stellar context must be set before initializing the ParserRunner.", e.getMessage()); }
@Test public void initShouldThrowExceptionOnMissingSensorParserConfig() { parserRunner = new ParserRunnerImpl(new HashSet<String>() {{ add("test"); }}); IllegalStateException e = assertThrows(IllegalStateException.class, () -> parserRunner.init(() -> parserConfigurations, mock(Context.class))); assertEquals("Could not initialize parsers. Cannot find configuration for sensor test.", e.getMessage()); }