@Test public void fromJsonReturnsExpected() { final Target actual = ImmutableMqttTarget.fromJson(TARGET_JSON); assertThat(actual).isEqualTo(TARGET); }
/** * Creates a new {@code Target} object from the specified JSON object. Decides which specific {@link Target} * implementation to choose depending on the given {@link ConnectionType}. * * @param jsonObject a JSON object which provides the data for the Target to be created. * @param type the connection type required to decide which iplementation of {@link Source} to choose * @return a new Source Target is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Target targetFromJson(final JsonObject jsonObject, final ConnectionType type) { switch (type) { case AMQP_091: case AMQP_10: return ImmutableTarget.fromJson(jsonObject); case MQTT: return ImmutableMqttTarget.fromJson(jsonObject); default: throw ConnectionConfigurationInvalidException .newBuilder("Unexpected connection type <" + type + ">") .build(); } }
/** * Creates a new {@code Target} object from the specified JSON object. Decides which specific {@link Target} * implementation to choose depending on the given {@link ConnectionType}. * * @param jsonObject a JSON object which provides the data for the Target to be created. * @param type the connection type required to decide which iplementation of {@link Source} to choose * @return a new Source Target is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Target targetFromJson(final JsonObject jsonObject, final ConnectionType type) { switch (type) { case AMQP_091: case AMQP_10: return ImmutableTarget.fromJson(jsonObject); case MQTT: return ImmutableMqttTarget.fromJson(jsonObject); default: throw ConnectionConfigurationInvalidException .newBuilder("Unexpected connection type <" + type + ">") .build(); } }