JSONTranslatorBolt extends BaseRichBolt { @SuppressWarnings("rawtypes") @Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { this.logger = Logger.getLogger(JSONTranslatorBolt.class.getName()); this.collector = collector; gson = new GsonBuilder().create(); type = new TypeToken<HashMap<String, Object>>() { }.getType(); factory = new UnifiedFactory(); if (stormConf.get(TRANSLATOR_TIMESTAMP_KEY) != null) { this.timestampKey = stormConf.get(TRANSLATOR_TIMESTAMP_KEY).toString(); } else { timestampKey = DEFAULT_TIMESTAMP; } if (stormConf.get(TRANSLATOR_TENAN_ID_KEY) != null) { this.timestampKey = stormConf.get(TRANSLATOR_TENAN_ID_KEY).toString(); } else { tenantIdKey = DEFAULT_TENANT_ID; } sucessMetric = new CountMetric(); failMetric = new CountMetric(); if (context != null) { context.registerMetric(_METRIC_TRANSLATOR_SUCCESS, sucessMetric, Constants.METRICS_FREQUENCY); context.registerMetric(_METRIC_TRANSLATOR_FAIL, failMetric, Constants.METRICS_FREQUENCY); } logger.info("Translator bolt initialized"); }  @SuppressWarnings("rawtypes") @Override void prepare(Map stormConf, TopologyContext context, OutputCollector collector); @SuppressWarnings("unchecked") @Override void execute(Tuple input); @Override void declareOutputFields(OutputFieldsDeclarer declarer);  }
@Test public void testPrepare() { JSONTranslatorBolt bolt = new JSONTranslatorBolt(); bolt.prepare(new HashMap<>(), null, mockCollector); assertNotNull(bolt.getFactory()); assertNotNull(bolt.getGson()); assertNotNull(bolt.getType()); assertNotNull(bolt.getCollector()); assertEquals(mockCollector, bolt.getCollector()); }