Skip to content

Commit

Permalink
Made MqttClientPublishException and MqttClientSubscribeException have…
Browse files Browse the repository at this point in the history
… a similar interface

Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Feb 23, 2023
1 parent 044fd76 commit 6966fb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MqttClientPublishException extends MqttClientException {
*
* @since 1.2.0
*/
final String topic;
final MqttTopic topic;

/**
* The {@link MqttMessage} was meant to be published.
Expand All @@ -47,7 +47,11 @@ public class MqttClientPublishException extends MqttClientException {
* @since 2.0.0
*/
public MqttClientPublishException(Throwable cause, String clientId, MqttTopic topic, MqttMessage mqttMessage) {
this(cause, clientId, topic.toString(), mqttMessage);
super(MqttClientErrorCodes.PUBLISH_ERROR, cause, clientId, topic, mqttMessage.getPayload().hasBody() ? mqttMessage.getPayload().getBody().length : null);

this.topic = topic;
this.mqttMessage = mqttMessage;

}

/**
Expand All @@ -58,12 +62,11 @@ public MqttClientPublishException(Throwable cause, String clientId, MqttTopic to
* @param topic The {@link MqttTopic} in {@link String} form where the {@link MqttMessage} that was meant to be published.
* @param mqttMessage The {@link MqttMessage} was meant to be published.
* @since 1.2.0
* @deprecated Since 2.0.0. Please make use of {@link #MqttClientPublishException(Throwable, String, MqttTopic, MqttMessage)}
*/
@Deprecated
public MqttClientPublishException(Throwable cause, String clientId, String topic, MqttMessage mqttMessage) {
super(MqttClientErrorCodes.PUBLISH_ERROR, cause, clientId, topic, mqttMessage.getPayload().hasBody() ? mqttMessage.getPayload().getBody().length : null);

this.topic = topic;
this.mqttMessage = mqttMessage;
this(cause, clientId, new MqttTopic(topic), mqttMessage);
}

/**
Expand All @@ -72,7 +75,7 @@ public MqttClientPublishException(Throwable cause, String clientId, String topic
* @return The {@link MqttTopic} where the {@link MqttMessage} that was meant to be published.
* @since 1.2.0
*/
public String getTopic() {
public MqttTopic getTopic() {
return topic;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void testMqttClientPublishException() {
Assert.assertEquals(MqttClientErrorCodes.PUBLISH_ERROR, mqttClientPublishException.getCode());
Assert.assertEquals(cause, mqttClientPublishException.getCause());
Assert.assertEquals(clientId, mqttClientPublishException.getClientId());
Assert.assertEquals(mqttTopic.toString(), mqttClientPublishException.getTopic());
Assert.assertEquals(mqttTopic, mqttClientPublishException.getTopic());
Assert.assertEquals(mqttMessage, mqttClientPublishException.getMqttMessage());
Assert.assertEquals(exceptionMessage, mqttClientPublishException.getMessage());
Assert.assertEquals(exceptionMessage, mqttClientPublishException.getLocalizedMessage());
Expand Down

0 comments on commit 6966fb9

Please sign in to comment.