### Question:
JSONDecoder extends AbstractJSONDecoder { @Override public TEvent decode(String source) throws DecodeException { JSONObject object = parse(source); TEvent event = new TEvent(); decodeToEvent(event, object); return event; }  void init(); @Override TEvent decode(String source); @Override void decode(String source, TEvent event, @Nullable String target); void decodeToTarget(TEvent event, JSONObject object, String target);  }### Answer:
@Test public void testSimpleToTarget() throws DecodeException { TEvent event = new TEvent(); JSONDecoder decoder = new JSONDecoder(); decoder.decode(simpleSource1, event, "tgt"); JSONObject o = (JSONObject)event.get("tgt"); Assert.assertEquals("name1", o.getString("name")); Assert.assertEquals("type1", o.getString("type")); }
@Test public void testSimpleToTargetWithNoise() throws DecodeException { TEvent event = new TEvent(); JSONDecoder decoder = new JSONDecoder(); String source = "20181125 - " + simpleSource1; decoder.decode(source, event, "tgt"); JSONObject o = (JSONObject)event.get("tgt"); Assert.assertEquals("name1", o.getString("name")); Assert.assertEquals("type1", o.getString("type")); source = source + " suffix"; decoder.decode(source, event, "tgt"); o = (JSONObject)event.get("tgt"); Assert.assertEquals("name1", o.getString("name")); Assert.assertEquals("type1", o.getString("type")); source = simpleSource1 + " suffix"; decoder.decode(source, event, "tgt"); o = (JSONObject)event.get("tgt"); Assert.assertEquals("name1", o.getString("name")); Assert.assertEquals("type1", o.getString("type")); }