### Question:
YoutubeTypeConverter implements StreamsProcessor { @Override public List<StreamsDatum> process(StreamsDatum streamsDatum) { StreamsDatum result = null; try { Object item = streamsDatum.getDocument(); LOGGER.debug("{} processing {}", STREAMS_ID, item.getClass()); Activity activity; if (item instanceof String) { item = deserializeItem(item); } if (item instanceof Video) { activity = new Activity(); YoutubeActivityUtil.updateActivity((Video)item, activity, streamsDatum.getId()); } else if (item instanceof Channel) { activity = new Activity(); YoutubeActivityUtil.updateActivity((Channel)item, activity, null); } else { throw new NotImplementedException("Type conversion not implement for type : " + item.getClass().getName()); } if (activity != null) { result = new StreamsDatum(activity); count++; } } catch (Exception ex) { LOGGER.error("Exception while converting Video to Activity: {}", ex); } if (result != null) { List<StreamsDatum> streamsDatumList = new ArrayList<>(); streamsDatumList.add(result); return streamsDatumList; } else { return new ArrayList<>(); } } YoutubeTypeConverter(); @Override String getId(); @Override List<StreamsDatum> process(StreamsDatum streamsDatum); @Override void prepare(Object configurationObject); @Override void cleanUp(); static final String STREAMS_ID; }### Answer:
@Test public void testVideoConversion() { try { LOGGER.info("raw: {}", testVideo); Activity activity = new Activity(); Video video = objectMapper.readValue(testVideo, Video.class); StreamsDatum streamsDatum = new StreamsDatum(video); assertNotNull(streamsDatum.getDocument()); List<StreamsDatum> retList = youtubeTypeConverter.process(streamsDatum); YoutubeActivityUtil.updateActivity(video, activity, "testChannelId"); assertEquals(retList.size(), 1); assert (retList.get(0).getDocument() instanceof Activity); assertEquals(activity, retList.get(0).getDocument()); } catch (Exception ex) { LOGGER.error("Exception while trying to convert video to activity: {}", ex); } }
@Test public void testStringVideoConversion() { try { LOGGER.info("raw: {}", testVideo); Activity activity = new Activity(); Video video = objectMapper.readValue(testVideo, Video.class); StreamsDatum streamsDatum = new StreamsDatum(testVideo); assertNotNull(streamsDatum.getDocument()); List<StreamsDatum> retList = youtubeTypeConverter.process(streamsDatum); YoutubeActivityUtil.updateActivity(video, activity, "testChannelId"); assertEquals(retList.size(), 1); assert (retList.get(0).getDocument() instanceof Activity); assertEquals(activity, retList.get(0).getDocument()); } catch (Exception ex) { LOGGER.error("Exception while trying to convert video to activity: {}", ex); } }