EventLogFactory extends AbstractLogFactory { @Override public Collection<CommonSchemaLog> toCommonSchemaLogs(Log log) { Collection<CommonSchemaLog> commonSchemaLogs = new LinkedList<>(); for (String transmissionTarget : log.getTransmissionTargetTokens()) { CommonSchemaEventLog commonSchemaEventLog = new CommonSchemaEventLog(); EventLog eventLog = (EventLog) log; PartAUtils.setName(commonSchemaEventLog, eventLog.getName()); PartAUtils.addPartAFromLog(log, commonSchemaEventLog, transmissionTarget); CommonSchemaDataUtils.addCommonSchemaData(eventLog.getTypedProperties(), commonSchemaEventLog); commonSchemaLogs.add(commonSchemaEventLog); commonSchemaEventLog.setTag(log.getTag()); } return commonSchemaLogs; }  @Override EventLog create(); @Override Collection<CommonSchemaLog> toCommonSchemaLogs(Log log);  }
@Test public void dontConvertEventWithoutTargetTokens() { EventLog log = new EventLog(); log.setName("test"); Collection<CommonSchemaLog> convertedLogs = new CommonSchemaEventLogFactory().toCommonSchemaLogs(log); assertNotNull(convertedLogs); assertEquals(0, convertedLogs.size()); }
@Test @PrepareForTest({PartAUtils.class, CommonSchemaDataUtils.class}) public void convertEventWithoutProperties() { mockStatic(PartAUtils.class); mockStatic(CommonSchemaDataUtils.class); EventLog log = new EventLog(); log.setName("test"); Map<String, String> oldProperties = new HashMap<>(); oldProperties.put("ignored", "ignored"); log.setProperties(oldProperties); List<TypedProperty> properties = new ArrayList<>(); StringTypedProperty stringTypedProperty = new StringTypedProperty(); stringTypedProperty.setName("a"); stringTypedProperty.setValue("b"); properties.add(stringTypedProperty); log.setTypedProperties(properties); log.addTransmissionTarget("t1"); log.addTransmissionTarget("t2"); Object tag = new Object(); log.setTag(tag); Collection<CommonSchemaLog> convertedLogs = new EventLogFactory().toCommonSchemaLogs(log); assertNotNull(convertedLogs); assertEquals(2, convertedLogs.size()); for (CommonSchemaLog commonSchemaLog : convertedLogs) { verifyStatic(); PartAUtils.setName(same(commonSchemaLog), eq("test")); assertSame(tag, commonSchemaLog.getTag()); } verifyStatic(); PartAUtils.addPartAFromLog(eq(log), notNull(CommonSchemaLog.class), eq("t1")); verifyStatic(); PartAUtils.addPartAFromLog(eq(log), notNull(CommonSchemaLog.class), eq("t2")); verifyStatic(times(2)); CommonSchemaDataUtils.addCommonSchemaData(eq(properties), notNull(CommonSchemaLog.class)); }