PartAUtils { public static void addPartAFromLog(Log src, CommonSchemaLog dest, String transmissionTarget) { Device device = src.getDevice(); dest.setVer("3.0"); dest.setTimestamp(src.getTimestamp()); dest.setIKey("o" + COMMON_SCHEMA_PREFIX_SEPARATOR + getTargetKey(transmissionTarget)); dest.addTransmissionTarget(transmissionTarget); if (dest.getExt() == null) { dest.setExt(new Extensions()); } dest.getExt().setProtocol(new ProtocolExtension()); dest.getExt().getProtocol().setDevModel(device.getModel()); dest.getExt().getProtocol().setDevMake(device.getOemName()); dest.getExt().setUser(new UserExtension()); dest.getExt().getUser().setLocalId(UserIdContext.getPrefixedUserId(src.getUserId())); dest.getExt().getUser().setLocale(device.getLocale().replace("_", "-")); dest.getExt().setOs(new OsExtension()); dest.getExt().getOs().setName(device.getOsName()); dest.getExt().getOs().setVer(device.getOsVersion() + "-" + device.getOsBuild() + "-" + device.getOsApiLevel()); dest.getExt().setApp(new AppExtension()); dest.getExt().getApp().setVer(device.getAppVersion()); dest.getExt().getApp().setId("a" + COMMON_SCHEMA_PREFIX_SEPARATOR + device.getAppNamespace()); dest.getExt().setNet(new NetExtension()); dest.getExt().getNet().setProvider(device.getCarrierName()); dest.getExt().setSdk(new SdkExtension()); dest.getExt().getSdk().setLibVer(device.getSdkName() + "-" + device.getSdkVersion()); dest.getExt().setLoc(new LocExtension()); String timezoneOffset = String.format(Locale.US, "%s%02d:%02d", device.getTimeZoneOffset() >= 0 ? "+" : "-", Math.abs(device.getTimeZoneOffset() / 60), Math.abs(device.getTimeZoneOffset() % 60)); dest.getExt().getLoc().setTz(timezoneOffset); dest.getExt().setDevice(new DeviceExtension()); }  static String getTargetKey(String targetToken); static void setName(CommonSchemaLog log, String name); static void addPartAFromLog(Log src, CommonSchemaLog dest, String transmissionTarget);  }
@Test public void checkPartAConversionDoesNotInstantiateExtensionObjectAgain() { Log log = mock(Log.class); when(log.getDevice()).thenReturn(getDevice(0)); MockCommonSchemaLog commonSchemaLog = new MockCommonSchemaLog(); Extensions extensions = new Extensions(); commonSchemaLog.setExt(extensions); PartAUtils.addPartAFromLog(log, commonSchemaLog, "T1UUID1-T2UUID2"); assertEquals(extensions, commonSchemaLog.getExt()); }