@Test public void testEmptyBuilder() throws JSONException { ChannelRegistrationPayload payload = new ChannelRegistrationPayload.Builder().build(); JsonMap body = payload.toJsonValue().getMap(); assertTrue("Channel should be present in payload.", body.containsKey(ChannelRegistrationPayload.CHANNEL_KEY)); assertFalse("Identity hints should not be present in payload.", body.containsKey(ChannelRegistrationPayload.IDENTITY_HINTS_KEY)); JsonMap channel = body.get(ChannelRegistrationPayload.CHANNEL_KEY).getMap(); assertTrue("Opt in should be present in payload.", channel.containsKey(ChannelRegistrationPayload.OPT_IN_KEY)); assertEquals("Opt in should be false.", channel.get(ChannelRegistrationPayload.OPT_IN_KEY).getBoolean(true), false); assertTrue("Background flag should be present in payload.", channel.containsKey(ChannelRegistrationPayload.BACKGROUND_ENABLED_KEY)); assertEquals("Background flag should be false.", channel.get(ChannelRegistrationPayload.BACKGROUND_ENABLED_KEY).getBoolean(true), false); assertFalse("Push address should not be present in payload.", channel.containsKey(ChannelRegistrationPayload.PUSH_ADDRESS_KEY)); assertTrue("Set tags should be present in payload.", channel.containsKey(ChannelRegistrationPayload.SET_TAGS_KEY)); assertEquals("Set tags should be false.", channel.get(ChannelRegistrationPayload.SET_TAGS_KEY).getBoolean(true), false); assertFalse("Tags should not be present in payload.", channel.containsKey(ChannelRegistrationPayload.TAGS_KEY)); }
@NonNull @Override public JsonValue toJsonValue() { JsonMap.Builder channel = JsonMap.newBuilder() .put(DEVICE_TYPE_KEY, deviceType) .put(SET_TAGS_KEY, setTags) .put(OPT_IN_KEY, optIn) .put(PUSH_ADDRESS_KEY, pushAddress) .put(BACKGROUND_ENABLED_KEY, backgroundEnabled) .put(TIMEZONE_KEY, timezone) .put(LANGUAGE_KEY, language) .put(COUNTRY_KEY, country) .put(APP_VERSION_KEY, appVersion) .put(SDK_VERSION_KEY, sdkVersion) .put(DEVICE_MODEL_KEY, deviceModel) .put(CARRIER_KEY, carrier) .put(NAMED_USER_ID_KEY, namedUserId); if (ANDROID_DEVICE_TYPE.equals(deviceType) && deliveryType != null) { channel.put(ANDROID_EXTRAS_KEY, JsonMap.newBuilder() .put(ANDROID_DELIVERY_TYPE, deliveryType) .build()); } if (locationSettings != null) { channel.put(LOCATION_SETTINGS_KEY, locationSettings); } if (apiVersion != null) { channel.put(API_VERSION_KEY, apiVersion); } if (setTags && tags != null) { channel.put(TAGS_KEY, JsonValue.wrapOpt(tags).getList()); } JsonMap.Builder identityHints = JsonMap.newBuilder() .put(USER_ID_KEY, userId) .put(APID_KEY, apid) .put(ACCENGAGE_DEVICE_ID, accengageDeviceId); JsonMap.Builder data = JsonMap.newBuilder() .put(CHANNEL_KEY, channel.build()); JsonMap identityHintsMap = identityHints.build(); if (!identityHintsMap.isEmpty()) { data.put(IDENTITY_HINTS_KEY, identityHintsMap); } return data.build().toJsonValue(); }
ChannelRegistrationPayload implements JsonSerializable { @NonNull @Override public JsonValue toJsonValue() { JsonMap.Builder channel = JsonMap.newBuilder() .put(DEVICE_TYPE_KEY, deviceType) .put(SET_TAGS_KEY, setTags) .put(OPT_IN_KEY, optIn) .put(PUSH_ADDRESS_KEY, pushAddress) .put(BACKGROUND_ENABLED_KEY, backgroundEnabled) .put(TIMEZONE_KEY, timezone) .put(LANGUAGE_KEY, language) .put(COUNTRY_KEY, country) .put(APP_VERSION_KEY, appVersion) .put(SDK_VERSION_KEY, sdkVersion) .put(DEVICE_MODEL_KEY, deviceModel) .put(CARRIER_KEY, carrier) .put(NAMED_USER_ID_KEY, namedUserId); if (ANDROID_DEVICE_TYPE.equals(deviceType) && deliveryType != null) { channel.put(ANDROID_EXTRAS_KEY, JsonMap.newBuilder() .put(ANDROID_DELIVERY_TYPE, deliveryType) .build()); } if (locationSettings != null) { channel.put(LOCATION_SETTINGS_KEY, locationSettings); } if (apiVersion != null) { channel.put(API_VERSION_KEY, apiVersion); } if (setTags && tags != null) { channel.put(TAGS_KEY, JsonValue.wrapOpt(tags).getList()); } JsonMap.Builder identityHints = JsonMap.newBuilder() .put(USER_ID_KEY, userId) .put(APID_KEY, apid) .put(ACCENGAGE_DEVICE_ID, accengageDeviceId); JsonMap.Builder data = JsonMap.newBuilder() .put(CHANNEL_KEY, channel.build()); JsonMap identityHintsMap = identityHints.build(); if (!identityHintsMap.isEmpty()) { data.put(IDENTITY_HINTS_KEY, identityHintsMap); } return data.build().toJsonValue(); } }
ChannelRegistrationPayload implements JsonSerializable { @NonNull @Override public JsonValue toJsonValue() { JsonMap.Builder channel = JsonMap.newBuilder() .put(DEVICE_TYPE_KEY, deviceType) .put(SET_TAGS_KEY, setTags) .put(OPT_IN_KEY, optIn) .put(PUSH_ADDRESS_KEY, pushAddress) .put(BACKGROUND_ENABLED_KEY, backgroundEnabled) .put(TIMEZONE_KEY, timezone) .put(LANGUAGE_KEY, language) .put(COUNTRY_KEY, country) .put(APP_VERSION_KEY, appVersion) .put(SDK_VERSION_KEY, sdkVersion) .put(DEVICE_MODEL_KEY, deviceModel) .put(CARRIER_KEY, carrier) .put(NAMED_USER_ID_KEY, namedUserId); if (ANDROID_DEVICE_TYPE.equals(deviceType) && deliveryType != null) { channel.put(ANDROID_EXTRAS_KEY, JsonMap.newBuilder() .put(ANDROID_DELIVERY_TYPE, deliveryType) .build()); } if (locationSettings != null) { channel.put(LOCATION_SETTINGS_KEY, locationSettings); } if (apiVersion != null) { channel.put(API_VERSION_KEY, apiVersion); } if (setTags && tags != null) { channel.put(TAGS_KEY, JsonValue.wrapOpt(tags).getList()); } JsonMap.Builder identityHints = JsonMap.newBuilder() .put(USER_ID_KEY, userId) .put(APID_KEY, apid) .put(ACCENGAGE_DEVICE_ID, accengageDeviceId); JsonMap.Builder data = JsonMap.newBuilder() .put(CHANNEL_KEY, channel.build()); JsonMap identityHintsMap = identityHints.build(); if (!identityHintsMap.isEmpty()) { data.put(IDENTITY_HINTS_KEY, identityHintsMap); } return data.build().toJsonValue(); } private  ChannelRegistrationPayload(Builder builder); }
ChannelRegistrationPayload implements JsonSerializable { @NonNull @Override public JsonValue toJsonValue() { JsonMap.Builder channel = JsonMap.newBuilder() .put(DEVICE_TYPE_KEY, deviceType) .put(SET_TAGS_KEY, setTags) .put(OPT_IN_KEY, optIn) .put(PUSH_ADDRESS_KEY, pushAddress) .put(BACKGROUND_ENABLED_KEY, backgroundEnabled) .put(TIMEZONE_KEY, timezone) .put(LANGUAGE_KEY, language) .put(COUNTRY_KEY, country) .put(APP_VERSION_KEY, appVersion) .put(SDK_VERSION_KEY, sdkVersion) .put(DEVICE_MODEL_KEY, deviceModel) .put(CARRIER_KEY, carrier) .put(NAMED_USER_ID_KEY, namedUserId); if (ANDROID_DEVICE_TYPE.equals(deviceType) && deliveryType != null) { channel.put(ANDROID_EXTRAS_KEY, JsonMap.newBuilder() .put(ANDROID_DELIVERY_TYPE, deliveryType) .build()); } if (locationSettings != null) { channel.put(LOCATION_SETTINGS_KEY, locationSettings); } if (apiVersion != null) { channel.put(API_VERSION_KEY, apiVersion); } if (setTags && tags != null) { channel.put(TAGS_KEY, JsonValue.wrapOpt(tags).getList()); } JsonMap.Builder identityHints = JsonMap.newBuilder() .put(USER_ID_KEY, userId) .put(APID_KEY, apid) .put(ACCENGAGE_DEVICE_ID, accengageDeviceId); JsonMap.Builder data = JsonMap.newBuilder() .put(CHANNEL_KEY, channel.build()); JsonMap identityHintsMap = identityHints.build(); if (!identityHintsMap.isEmpty()) { data.put(IDENTITY_HINTS_KEY, identityHintsMap); } return data.build().toJsonValue(); } private  ChannelRegistrationPayload(Builder builder); @NonNull ChannelRegistrationPayload minimizedPayload(@Nullable ChannelRegistrationPayload last); @NonNull @Override JsonValue toJsonValue(); @NonNull @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
ChannelRegistrationPayload implements JsonSerializable { @NonNull @Override public JsonValue toJsonValue() { JsonMap.Builder channel = JsonMap.newBuilder() .put(DEVICE_TYPE_KEY, deviceType) .put(SET_TAGS_KEY, setTags) .put(OPT_IN_KEY, optIn) .put(PUSH_ADDRESS_KEY, pushAddress) .put(BACKGROUND_ENABLED_KEY, backgroundEnabled) .put(TIMEZONE_KEY, timezone) .put(LANGUAGE_KEY, language) .put(COUNTRY_KEY, country) .put(APP_VERSION_KEY, appVersion) .put(SDK_VERSION_KEY, sdkVersion) .put(DEVICE_MODEL_KEY, deviceModel) .put(CARRIER_KEY, carrier) .put(NAMED_USER_ID_KEY, namedUserId); if (ANDROID_DEVICE_TYPE.equals(deviceType) && deliveryType != null) { channel.put(ANDROID_EXTRAS_KEY, JsonMap.newBuilder() .put(ANDROID_DELIVERY_TYPE, deliveryType) .build()); } if (locationSettings != null) { channel.put(LOCATION_SETTINGS_KEY, locationSettings); } if (apiVersion != null) { channel.put(API_VERSION_KEY, apiVersion); } if (setTags && tags != null) { channel.put(TAGS_KEY, JsonValue.wrapOpt(tags).getList()); } JsonMap.Builder identityHints = JsonMap.newBuilder() .put(USER_ID_KEY, userId) .put(APID_KEY, apid) .put(ACCENGAGE_DEVICE_ID, accengageDeviceId); JsonMap.Builder data = JsonMap.newBuilder() .put(CHANNEL_KEY, channel.build()); JsonMap identityHintsMap = identityHints.build(); if (!identityHintsMap.isEmpty()) { data.put(IDENTITY_HINTS_KEY, identityHintsMap); } return data.build().toJsonValue(); } private  ChannelRegistrationPayload(Builder builder); @NonNull ChannelRegistrationPayload minimizedPayload(@Nullable ChannelRegistrationPayload last); @NonNull @Override JsonValue toJsonValue(); @NonNull @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); @NonNull
    static final String ANDROID_DEVICE_TYPE; @NonNull
    static final String AMAZON_DEVICE_TYPE; final boolean optIn; final boolean backgroundEnabled; final String deviceType; final String pushAddress; final boolean setTags; final Set<String> tags; final String userId; final String apid; final String timezone; final String language; final String country; final Boolean locationSettings; final String appVersion; final String sdkVersion; final String deviceModel; final Integer apiVersion; final String carrier; final String accengageDeviceId; final String deliveryType; final String namedUserId; }