Apply the default formatter of Android Studio to Java code
authorChanhee Lee <ch2102.lee@samsung.com>
Thu, 22 Sep 2022 00:48:44 +0000 (09:48 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Fri, 23 Sep 2022 05:53:18 +0000 (14:53 +0900)
[Problem] Code formats are different among Java source files.
[Solution] Apply IDE formatter (Ctrl+Alt+L) to all Java code.

android/aitt/src/main/java/com/samsung/android/aitt/Aitt.java
android/aitt/src/main/java/com/samsung/android/aitt/AittMessage.java
android/aitt/src/main/java/com/samsung/android/aitt/TransportFactory.java
android/aitt/src/main/java/com/samsung/android/aitt/TransportHandler.java
android/aitt/src/main/java/com/samsung/android/aitt/WebRTCHandler.java
android/aitt/src/test/java/com/samsung/android/aitt/AittMessageUnitTest.java
android/aitt/src/test/java/com/samsung/android/aitt/AittUnitTest.java
android/aitt/src/test/java/com/samsung/android/aitt/ShadowJniInterface.java
android/modules/tcp/src/androidTest/java/com/samsung/android/modules/tcp/TCPInstrumentedTest.java
android/modules/webrtc/src/main/java/com/samsung/android/modules/webrtc/WebRTC.java
android/modules/webrtc/src/main/java/com/samsung/android/modules/webrtc/WebRTCServer.java

index 0af96ee..6fca796 100644 (file)
@@ -113,7 +113,9 @@ public class Aitt {
      */
     public interface ConnectionCallback {
         void onConnected();
+
         void onDisconnected();
+
         void onConnectionFailed();
     }
 
@@ -126,8 +128,9 @@ public class Aitt {
 
     /**
      * Aitt constructor to create AITT object
+     *
      * @param appContext context of the application invoking the constructor
-     * @param id Unique identifier for the Aitt instance
+     * @param id         Unique identifier for the Aitt instance
      */
     public Aitt(Context appContext, String id) throws InstantiationException {
         this(appContext, id, Definitions.AITT_LOCALHOST, false);
@@ -135,9 +138,10 @@ public class Aitt {
 
     /**
      * Aitt constructor to create AITT object
-     * @param appContext context of the application invoking the constructor
-     * @param id Unique identifier for the Aitt instance
-     * @param ip IP address of the device, on which application is running
+     *
+     * @param appContext   context of the application invoking the constructor
+     * @param id           Unique identifier for the Aitt instance
+     * @param ip           IP address of the device, on which application is running
      * @param clearSession "clear" the current session when the client disconnects
      */
     public Aitt(Context appContext, String id, String ip, boolean clearSession) throws InstantiationException {
@@ -153,7 +157,7 @@ public class Aitt {
         }
         this.ip = ip;
         this.appContext = appContext;
-        mJniInterface.registerJniCallback(new JniInterface.JniCallback(){
+        mJniInterface.registerJniCallback(new JniInterface.JniCallback() {
             @Override
             public void jniDataPush(String _topic, byte[] payload) {
                 messageCallback(_topic, payload);
@@ -163,6 +167,7 @@ public class Aitt {
 
     /**
      * Method to set connection status callback
+     *
      * @param callback ConnectionCallback to which status should be updated
      */
     public void setConnectionCallback(ConnectionCallback callback) {
@@ -170,7 +175,7 @@ public class Aitt {
             throw new IllegalArgumentException("Invalid callback");
         }
         connectionCallback = callback;
-        mJniInterface.setConnectionCallback(new JniInterface.JniConnectionCallback(){
+        mJniInterface.setConnectionCallback(new JniInterface.JniConnectionCallback() {
             @Override
             public void jniConnectionCB(int status) {
                 connectionStatusCallback(status);
@@ -180,6 +185,7 @@ public class Aitt {
 
     /**
      * Method to connect to MQTT broker
+     *
      * @param brokerIp Broker IP address to which, device has to connect
      */
     public void connect(@Nullable String brokerIp) {
@@ -188,8 +194,9 @@ public class Aitt {
 
     /**
      * Method to connect to MQTT broker
+     *
      * @param brokerIp Broker IP address to which, device has to connect
-     * @param port Broker port number to which, device has to connect
+     * @param port     Broker port number to which, device has to connect
      */
     public void connect(@Nullable String brokerIp, int port) {
         if (brokerIp == null || brokerIp.isEmpty()) {
@@ -216,7 +223,8 @@ public class Aitt {
 
     /**
      * Method to publish message to a specific topic
-     * @param topic String to which message needs to be published
+     *
+     * @param topic   String to which message needs to be published
      * @param message Byte message that needs to be published
      */
     public void publish(String topic, byte[] message) {
@@ -226,11 +234,12 @@ public class Aitt {
 
     /**
      * Method to publish message to a specific topic
-     * @param topic String to which message needs to be published
-     * @param message Byte message that needs to be published
+     *
+     * @param topic    String to which message needs to be published
+     * @param message  Byte message that needs to be published
      * @param protocol Protocol to be used to publish message
-     * @param qos QoS at which the message should be delivered
-     * @param retain Boolean to decide whether or not the message should be retained by the broker
+     * @param qos      QoS at which the message should be delivered
+     * @param retain   Boolean to decide whether or not the message should be retained by the broker
      */
     public void publish(String topic, byte[] message, Protocol protocol, QoS qos, boolean retain) {
         EnumSet<Protocol> protocolSet = EnumSet.of(protocol);
@@ -239,11 +248,12 @@ public class Aitt {
 
     /**
      * Method to publish message to a specific topic
-     * @param topic String to which message needs to be published
-     * @param message Byte message that needs to be published
+     *
+     * @param topic     String to which message needs to be published
+     * @param message   Byte message that needs to be published
      * @param protocols Protocol to be used to publish message
-     * @param qos QoS at which the message should be delivered
-     * @param retain Boolean to decide whether or not the message should be retained by the broker
+     * @param qos       QoS at which the message should be delivered
+     * @param retain    Boolean to decide whether or not the message should be retained by the broker
      */
     public void publish(String topic, byte[] message, EnumSet<Protocol> protocols, QoS qos, boolean retain) {
 
@@ -257,11 +267,11 @@ public class Aitt {
             }
         }
 
-        if(jniProtocols > 0) {
+        if (jniProtocols > 0) {
             mJniInterface.publish(topic, message, message.length, jniProtocols, qos.ordinal(), retain);
         }
 
-        for(Protocol pro : protocols) {
+        for (Protocol pro : protocols) {
             try {
                 synchronized (this) {
                     if (!publishTable.containsKey(topic)) {
@@ -273,7 +283,7 @@ public class Aitt {
                         PortTable portTable = hostTable.hostMap.get(hostIp);
                         for (Integer port : portTable.portMap.keySet()) {
                             Object transportHandler = portTable.portMap.get(port).second;
-                            if(portTable.portMap.get(port).first == pro)
+                            if (portTable.portMap.get(port).first == pro)
                                 publishHandler(pro, portTable, topic, transportHandler, hostIp, port, message);
                         }
                     }
@@ -286,42 +296,45 @@ public class Aitt {
 
     /**
      * Method to create transportHandler and publish message based on protocol
-     * @param protocol protocol using which data needs to be published
-     * @param portTable portTable has information about port and associated protocol with transport Handler object
-     * @param topic The topic to which data is published
+     *
+     * @param protocol               protocol using which data needs to be published
+     * @param portTable              portTable has information about port and associated protocol with transport Handler object
+     * @param topic                  The topic to which data is published
      * @param transportHandlerObject transportHandler object used to publish message
-     * @param ip IP address of the destination
-     * @param port Port number of the destination
-     * @param message Data to be tranferred over WebRTC
+     * @param ip                     IP address of the destination
+     * @param port                   Port number of the destination
+     * @param message                Data to be tranferred over WebRTC
      */
-    private void publishHandler(Protocol protocol, PortTable portTable, String topic, Object transportHandlerObject, String ip, int port, byte[] message){
+    private void publishHandler(Protocol protocol, PortTable portTable, String topic, Object transportHandlerObject, String ip, int port, byte[] message) {
         TransportHandler transportHandler;
-        if(transportHandlerObject == null){
+        if (transportHandlerObject == null) {
             transportHandler = TransportFactory.createTransport(protocol);
-            if(transportHandler!=null)
+            if (transportHandler != null)
                 transportHandler.setAppContext(appContext);
             portTable.portMap.replace(port, new Pair<>(protocol, transportHandler));
-        }else{
+        } else {
             transportHandler = (TransportHandler) transportHandlerObject;
         }
 
-        if(transportHandler!=null){
-            transportHandler.publish(topic,ip, port, message);
+        if (transportHandler != null) {
+            transportHandler.publish(topic, ip, port, message);
         }
     }
 
     /**
      * Method to differentiate android specific protocol
+     *
      * @param protocols Protocol to be classified
      * @return true if the protocol is specific to android implementation
      */
-    private boolean classifyProtocol(Protocol protocols){
+    private boolean classifyProtocol(Protocol protocols) {
         return protocols.equals(Protocol.WEBRTC) || protocols.equals(Protocol.IPC);
     }
 
     /**
      * Method to subscribe to a specific topic
-     * @param topic String to which applications can subscribe, to receive data
+     *
+     * @param topic    String to which applications can subscribe, to receive data
      * @param callback Callback object specific to a subscribe call
      */
     public void subscribe(String topic, SubscribeCallback callback) {
@@ -331,10 +344,11 @@ public class Aitt {
 
     /**
      * Method to subscribe to a specific topic
-     * @param topic String to which applications can subscribe, to receive data
+     *
+     * @param topic    String to which applications can subscribe, to receive data
      * @param callback Callback object specific to a subscribe call
      * @param protocol Protocol supported by application, invoking subscribe
-     * @param qos QoS at which the message should be delivered
+     * @param qos      QoS at which the message should be delivered
      */
     public void subscribe(String topic, SubscribeCallback callback, Protocol protocol, QoS qos) {
         EnumSet<Protocol> protocolSet = EnumSet.of(protocol);
@@ -343,10 +357,11 @@ public class Aitt {
 
     /**
      * Method to subscribe to a specific topic
-     * @param topic String to which applications can subscribe, to receive data
-     * @param callback Callback object specific to a subscribe call
+     *
+     * @param topic     String to which applications can subscribe, to receive data
+     * @param callback  Callback object specific to a subscribe call
      * @param protocols Protocol supported by application, invoking subscribe
-     * @param qos QoS at which the message should be delivered
+     * @param qos       QoS at which the message should be delivered
      */
     public void subscribe(String topic, SubscribeCallback callback, EnumSet<Protocol> protocols, QoS qos) {
 
@@ -365,14 +380,14 @@ public class Aitt {
             }
         }
 
-        if(jniProtocols > 0) {
+        if (jniProtocols > 0) {
             Long pObject = mJniInterface.subscribe(topic, jniProtocols, qos.ordinal());
             synchronized (this) {
                 aittSubId.put(topic, pObject);
             }
         }
 
-        for(Protocol pro : protocols) {
+        for (Protocol pro : protocols) {
             try {
                 TransportHandler transportHandler = TransportFactory.createTransport(pro);
 
@@ -401,10 +416,11 @@ public class Aitt {
 
     /**
      * Method to verify Aitt pub & sub parameters
-     * @param topic String to which applications can subscribe, to receive data
+     *
+     * @param topic     String to which applications can subscribe, to receive data
      * @param protocols Protocol supported by application, invoking subscribe
      */
-    private void checkParams(String topic, EnumSet<Protocol> protocols){
+    private void checkParams(String topic, EnumSet<Protocol> protocols) {
         if (topic == null || topic.isEmpty()) {
             throw new IllegalArgumentException(INVALID_TOPIC);
         }
@@ -416,7 +432,8 @@ public class Aitt {
 
     /**
      * Method to map subscribe callback instance to subscribing topic
-     * @param topic String to which application can subscribe
+     *
+     * @param topic    String to which application can subscribe
      * @param callback Subscribe callback instance created during subscribe call
      */
     private void addCallBackToSubscribeMap(String topic, SubscribeCallback callback) {
@@ -442,6 +459,7 @@ public class Aitt {
 
     /**
      * Method to unsubscribe to a topic, subscribed by application
+     *
      * @param topic String topic to which application had subscribed
      */
     public void unsubscribe(String topic) {
@@ -483,10 +501,11 @@ public class Aitt {
 
     /**
      * Method invoked from JNI layer to Java layer for MQTT connection status update
+     *
      * @param status Status of the MQTT connection
-     *   0: MQTT Connection disconnected
-     *   1: MQTT connection success
-     *   2: MQTT connection failed
+     *               0: MQTT Connection disconnected
+     *               1: MQTT connection success
+     *               2: MQTT connection failed
      */
     private void connectionStatusCallback(int status) {
         switch (status) {
@@ -506,7 +525,8 @@ public class Aitt {
 
     /**
      * Method invoked from JNI layer to Java layer for message exchange
-     * @param topic Topic to which message callback is called
+     *
+     * @param topic   Topic to which message callback is called
      * @param payload Byte data shared from JNI layer to Java layer
      */
     private void messageCallback(String topic, byte[] payload) {
@@ -551,10 +571,11 @@ public class Aitt {
      *                "port": 20123,
      *             },
      *            }
-    */
-    
+     */
+
     /**
      * Method to receive discovery message with device, protocol and other details and update publish table
+     *
      * @param payload Byte data having discovery related message
      */
     private void discoveryMessageCallback(byte[] payload) {
@@ -595,13 +616,14 @@ public class Aitt {
 
     /**
      * Method used to update Publish table of the application
-     * @param topic The topic to which, other parties have subscribed to
-     * @param host String which specifies a particular host
-     * @param port Port of the party which subscribed to given topic
+     *
+     * @param topic    The topic to which, other parties have subscribed to
+     * @param host     String which specifies a particular host
+     * @param port     Port of the party which subscribed to given topic
      * @param protocol protocol supported by the party which subscribed to given topic
      */
     private void updatePublishTable(String topic, String host, int port, Protocol protocol) {
-        synchronized(this) {
+        synchronized (this) {
             if (!publishTable.containsKey(topic)) {
                 PortTable portTable = new PortTable();
                 portTable.portMap.put(port, new Pair(protocol, null));
@@ -631,6 +653,7 @@ public class Aitt {
 
     /**
      * Method that receives message from JNI layer for topics other than discovery topics
+     *
      * @param message The data received from JNI layer to be sent to application layer
      */
     private void messageReceived(AittMessage message) {
@@ -655,11 +678,11 @@ public class Aitt {
      */
     public void close() {
         synchronized (this) {
-            if(subscribeCallbacks!=null) {
+            if (subscribeCallbacks != null) {
                 subscribeCallbacks.clear();
                 subscribeCallbacks = null;
             }
-            if(aittSubId!=null) {
+            if (aittSubId != null) {
                 aittSubId.clear();
                 aittSubId = null;
             }
index 7ba570f..1385359 100644 (file)
 package com.samsung.android.aitt;
 
 public class AittMessage {
-   private String topic;
-   private String correlation;
-   private String replyTopic;
-   private int sequence;
-   private boolean endSequence;
-   private byte[] payload;
-
-   /**
-    * AittMessage constructor for initializing
-    */
-   public AittMessage() {
-      setPayload(new byte[]{});
-   }
-
-   /**
-    * AittMessage constructor with params for initializing
-    * @param payload The message data set as payload
-    */
-   public AittMessage(byte[] payload) {
-      setPayload(payload);
-   }
-
-   /**
-    * Method to get Topic assigned with AittMessage object
-    * @return The string topic
-    */
-   public String getTopic() {
-      return topic;
-   }
-
-   /**
-    * Method to set topic to AittMessage object
-    * @param topic String topic to be assigned to the object
-    */
-   public void setTopic(String topic) {
-      this.topic = topic;
-   }
-
-   /**
-    * Method to get Correlation
-    * @return the correlation
-    */
-   public String getCorrelation() {
-      return correlation;
-   }
-
-   /**
-    * Method to set correlation
-    * @param correlation correlation string to be set
-    */
-   public void setCorrelation(String correlation) {
-      this.correlation = correlation;
-   }
-
-   /**
-    * Method to get the reply topic
-    * @return the string of reply topic
-    */
-   public String getReplyTopic() {
-      return replyTopic;
-   }
-
-   /**
-    * Method to set reply topic
-    * @param replyTopic String that is set as reply topic
-    */
-   public void setReplyTopic(String replyTopic) {
-      this.replyTopic = replyTopic;
-   }
-
-   /**
-    * Method used to get sequence
-    * @return the sequence
-    */
-   public int getSequence() {
-      return sequence;
-   }
-
-   /**
-    * Method used to set sequence
-    * @param sequence the sequence value to be set
-    */
-   public void setSequence(int sequence) {
-      this.sequence = sequence;
-   }
-
-   /**
-    * Method used to increase the sequence by one
-    */
-   public void increaseSequence() {
-      sequence = sequence+1;
-   }
-
-   /**
-    * Method used to set endSequence
-    * @param endSequence boolean value to be set to end sequence
-    */
-   public void setEndSequence(boolean endSequence) {
-      this.endSequence = endSequence;
-   }
-
-   /**
-    * Method used to get if sequence is ended
-    * @return The state of sequence
-    */
-   public boolean isEndSequence() {
-      return endSequence;
-   }
-
-   /**
-    * Method used to retrieve payload
-    * @return The data in byte[] format
-    */
-   public byte[] getPayload() {
-      return payload;
-   }
-
-   /**
-    * Method used to clear the payload
-    */
-   public void clearPayload() {
-      this.payload = new byte[]{};
-   }
-
-   /**
-    * Method used to set payload to AittMessage object
-    * @param payload the byte[] message/payload to be set
-    */
-   public void setPayload(byte[] payload) {
-      if (payload == null) {
-         throw new NullPointerException();
-      }
-      this.payload = payload;
-   }
+    private String topic;
+    private String correlation;
+    private String replyTopic;
+    private int sequence;
+    private boolean endSequence;
+    private byte[] payload;
+
+    /**
+     * AittMessage constructor for initializing
+     */
+    public AittMessage() {
+        setPayload(new byte[]{});
+    }
+
+    /**
+     * AittMessage constructor with params for initializing
+     *
+     * @param payload The message data set as payload
+     */
+    public AittMessage(byte[] payload) {
+        setPayload(payload);
+    }
+
+    /**
+     * Method to get Topic assigned with AittMessage object
+     *
+     * @return The string topic
+     */
+    public String getTopic() {
+        return topic;
+    }
+
+    /**
+     * Method to set topic to AittMessage object
+     *
+     * @param topic String topic to be assigned to the object
+     */
+    public void setTopic(String topic) {
+        this.topic = topic;
+    }
+
+    /**
+     * Method to get Correlation
+     *
+     * @return the correlation
+     */
+    public String getCorrelation() {
+        return correlation;
+    }
+
+    /**
+     * Method to set correlation
+     *
+     * @param correlation correlation string to be set
+     */
+    public void setCorrelation(String correlation) {
+        this.correlation = correlation;
+    }
+
+    /**
+     * Method to get the reply topic
+     *
+     * @return the string of reply topic
+     */
+    public String getReplyTopic() {
+        return replyTopic;
+    }
+
+    /**
+     * Method to set reply topic
+     *
+     * @param replyTopic String that is set as reply topic
+     */
+    public void setReplyTopic(String replyTopic) {
+        this.replyTopic = replyTopic;
+    }
+
+    /**
+     * Method used to get sequence
+     *
+     * @return the sequence
+     */
+    public int getSequence() {
+        return sequence;
+    }
+
+    /**
+     * Method used to set sequence
+     *
+     * @param sequence the sequence value to be set
+     */
+    public void setSequence(int sequence) {
+        this.sequence = sequence;
+    }
+
+    /**
+     * Method used to increase the sequence by one
+     */
+    public void increaseSequence() {
+        sequence = sequence + 1;
+    }
+
+    /**
+     * Method used to set endSequence
+     *
+     * @param endSequence boolean value to be set to end sequence
+     */
+    public void setEndSequence(boolean endSequence) {
+        this.endSequence = endSequence;
+    }
+
+    /**
+     * Method used to get if sequence is ended
+     *
+     * @return The state of sequence
+     */
+    public boolean isEndSequence() {
+        return endSequence;
+    }
+
+    /**
+     * Method used to retrieve payload
+     *
+     * @return The data in byte[] format
+     */
+    public byte[] getPayload() {
+        return payload;
+    }
+
+    /**
+     * Method used to clear the payload
+     */
+    public void clearPayload() {
+        this.payload = new byte[]{};
+    }
+
+    /**
+     * Method used to set payload to AittMessage object
+     *
+     * @param payload the byte[] message/payload to be set
+     */
+    public void setPayload(byte[] payload) {
+        if (payload == null) {
+            throw new NullPointerException();
+        }
+        this.payload = payload;
+    }
 }
index 31f5e5b..fdb09f8 100644 (file)
@@ -16,9 +16,9 @@
 package com.samsung.android.aitt;
 
 class TransportFactory {
-    public static TransportHandler createTransport(Aitt.Protocol protocol){
+    public static TransportHandler createTransport(Aitt.Protocol protocol) {
         TransportHandler transportHandler;
-        switch(protocol){
+        switch (protocol) {
             case WEBRTC:
                 transportHandler = new WebRTCHandler();
                 break;
index a77b0a6..0e388a5 100644 (file)
@@ -23,16 +23,18 @@ import android.content.Context;
 interface TransportHandler {
     /**
      * Method to implement protocol specific subscribe functionalities
-     * @param topic String topic to which subscribe is called
+     *
+     * @param topic               String topic to which subscribe is called
      * @param handlerDataCallback callback object to send data from transport handler layer to aitt layer
      */
     void subscribe(String topic, HandlerDataCallback handlerDataCallback);
 
     /**
      * Method to implement protocol specific publish functionalities
-     * @param topic String topic to which publish is called
-     * @param ip IP address of the destination
-     * @param port port number of the destination
+     *
+     * @param topic   String topic to which publish is called
+     * @param ip      IP address of the destination
+     * @param port    port number of the destination
      * @param message message to be published to specific topic
      */
     void publish(String topic, String ip, int port, byte[] message);
@@ -49,18 +51,21 @@ interface TransportHandler {
 
     /**
      * Method to set application context to transport handler
+     *
      * @param appContext application context
      */
     void setAppContext(Context appContext);
 
     /**
      * Method to set IP address of self device to transport handler
+     *
      * @param ip IP address of the device
      */
     void setSelfIP(String ip);
 
     /**
      * Method to get data to publish self details
+     *
      * @return returns details of self device
      */
     byte[] getPublishData();
@@ -68,7 +73,7 @@ interface TransportHandler {
     /**
      * Interface to implement handler data callback mechanism
      */
-    interface HandlerDataCallback{
+    interface HandlerDataCallback {
         void pushHandlerData(byte[] data);
     }
 }
index e4d1cf3..cb6eabb 100644 (file)
@@ -64,7 +64,8 @@ class WebRTCHandler implements TransportHandler {
 
     /**
      * Method to wrap topic, device IP address, webRTC server instance port number for publishing
-     * @param topic Topic to which the application has subscribed to
+     *
+     * @param topic      Topic to which the application has subscribed to
      * @param serverPort Port number of the WebRTC server instance
      * @return Byte data wrapped, contains topic, device IP, webRTC server port number
      */
index abbb0a8..1d1dc98 100644 (file)
@@ -32,27 +32,27 @@ public class AittMessageUnitTest {
     private final String message = "Aitt Message";
 
     @Test
-    public void testAittMessageInitialize_P01(){
-         AittMessage aittMessage = new AittMessage();
-         assertNotNull("Not null AittMessage Object", aittMessage);
+    public void testAittMessageInitialize_P01() {
+        AittMessage aittMessage = new AittMessage();
+        assertNotNull("Not null AittMessage Object", aittMessage);
     }
 
     @Test
-    public void testAittMessageInitializePayload_P02(){
+    public void testAittMessageInitializePayload_P02() {
         byte[] payload = message.getBytes();
         AittMessage aittMessage = new AittMessage(payload);
         assertNotNull("Not null AittMessage Object", aittMessage);
     }
 
     @Test(expected = NullPointerException.class)
-    public void testAittMessageInitializeInvalidPayload_N01() throws NullPointerException{
+    public void testAittMessageInitializeInvalidPayload_N01() throws NullPointerException {
         byte[] payload = null;
         AittMessage aittMessage = new AittMessage(payload);
         assertNull("Null AittMessage Object", aittMessage);
     }
 
     @Test
-    public void testTopic_P03(){
+    public void testTopic_P03() {
         byte[] payload = message.getBytes();
         AittMessage aittMessage = new AittMessage(payload);
         aittMessage.setTopic(topic);
@@ -61,7 +61,7 @@ public class AittMessageUnitTest {
     }
 
     @Test
-    public void testCorrelation_P04(){
+    public void testCorrelation_P04() {
         byte[] payload = message.getBytes();
         AittMessage aittMessage = new AittMessage(payload);
         aittMessage.setCorrelation(correlation);
@@ -70,7 +70,7 @@ public class AittMessageUnitTest {
     }
 
     @Test
-    public void testReplyTopic_P05(){
+    public void testReplyTopic_P05() {
         byte[] payload = message.getBytes();
         AittMessage aittMessage = new AittMessage(payload);
         aittMessage.setReplyTopic(replyTopic);
@@ -79,17 +79,17 @@ public class AittMessageUnitTest {
     }
 
     @Test
-    public void testSequence_P06(){
+    public void testSequence_P06() {
         byte[] payload = message.getBytes();
         AittMessage aittMessage = new AittMessage(payload);
         aittMessage.setSequence(sequence);
         aittMessage.increaseSequence();
         int newSequence = aittMessage.getSequence();
-        assertEquals("Received sequence and set sequence are equal", sequence+1, newSequence);
+        assertEquals("Received sequence and set sequence are equal", sequence + 1, newSequence);
     }
 
     @Test
-    public void testEndSequence_P07(){
+    public void testEndSequence_P07() {
         byte[] payload = message.getBytes();
         AittMessage aittMessage = new AittMessage(payload);
         aittMessage.setEndSequence(endSequence);
@@ -98,7 +98,7 @@ public class AittMessageUnitTest {
     }
 
     @Test
-    public void testPayload_P08(){
+    public void testPayload_P08() {
         AittMessage aittMessage = new AittMessage();
         byte[] payload = message.getBytes();
         aittMessage.setPayload(payload);
@@ -114,7 +114,7 @@ public class AittMessageUnitTest {
     }
 
     @Test
-    public void testClearPayload_P09(){
+    public void testClearPayload_P09() {
         byte[] payload = message.getBytes();
         AittMessage aittMessage = new AittMessage(payload);
         aittMessage.clearPayload();
index 9123f4b..00958a4 100644 (file)
@@ -41,732 +41,734 @@ import java.util.EnumSet;
 @RunWith(RobolectricTestRunner.class)
 @Config(shadows = ShadowJniInterface.class)
 public class AittUnitTest {
-   @Mock
-   private final Context appContext = mock(Context.class);
-
-   private static final int DISCOVERY_MESSAGES_COUNT = 6;
-   private final String brokerIp = "192.168.0.1";
-   private final int port = 1803;
-   private final String topic = "aitt/test";
-   private final String message = "test message";
-   private final String aittId = "aitt";
-
-   ShadowJniInterface shadowJniInterface = new ShadowJniInterface();
-
-   private Method messageCallbackMethod;
-
-   @Before
-   public void initialize() {
-      try {
-         messageCallbackMethod = Aitt.class.getDeclaredMethod("messageCallback", String.class, byte[].class);
-         messageCallbackMethod.setAccessible(true);
-      } catch(Exception e) {
-         fail("Failed to Initialize " + e);
-      }
-   }
-
-   private byte[] createDiscoveryMessage(int count) {
-      int start;
-      FlexBuffersBuilder builder = new FlexBuffersBuilder(ByteBuffer.allocate(512));
-      start = builder.startMap();
-      switch (count) {
-         case 1:
-            /*
-             *           {
-             *             "status": "connected",
-             *             "host": "127.0.0.1",
-             *             "aitt/topic1": {
-             *                "protocol": TCP,
-             *                "port": 1000,
-             *             }
-             *            }
-             */
-            builder.putString("status", Definitions.JOIN_NETWORK);
-            builder.putString("host", Definitions.AITT_LOCALHOST);
-            int secondStart = builder.startMap();
-            builder.putInt("port", 1000);
-            builder.putInt("protocol", Aitt.Protocol.TCP.getValue());
-            builder.endMap("aitt/topic1", secondStart);
-            break;
-         case 2:
-            /*
-             *           {
-             *             "status": "connected",
-             *             "host": "127.0.0.2",
-             *             "aitt/topic1": {
-             *                "protocol": MQTT,
-             *                "port": 2000,
-             *             }
-             *            }
-             */
-            builder.putString("status", Definitions.JOIN_NETWORK);
-            builder.putString("host", "127.0.0.2");
-            secondStart = builder.startMap();
-            builder.putInt("port", 2000);
-            builder.putInt("protocol", Aitt.Protocol.MQTT.getValue());
-            builder.endMap("aitt/topic1", secondStart);
-            break;
-         case 3:
-            /*
-             *           {
-             *             "status": "connected",
-             *             "host": "127.0.0.1",
-             *             "aitt/topic2": {
-             *                "protocol": MQTT,
-             *                "port": 2000,
-             *             }
-             *            }
-             */
-            builder.putString("status", Definitions.JOIN_NETWORK);
-            builder.putString("host", Definitions.AITT_LOCALHOST);
-            secondStart = builder.startMap();
-            builder.putInt("port", 2000);
-            builder.putInt("protocol", Aitt.Protocol.MQTT.getValue());
-            builder.endMap("aitt/topic2", secondStart);
-            break;
-         case 4:
-            /*
-             *           {
-             *             "status": "connected",
-             *             "host": "127.0.0.1",
-             *             "aitt/topic2": {
-             *                "protocol": TCP,
-             *                "port": 4000,
-             *             }
-             *            }
-             */
-            builder.putString("status", Definitions.JOIN_NETWORK);
-            builder.putString("host", Definitions.AITT_LOCALHOST);
-            secondStart = builder.startMap();
-            builder.putInt("port", 4000);
-            builder.putInt("protocol", Aitt.Protocol.TCP.getValue());
-            builder.endMap("aitt/topic2", secondStart);
-            break;
-         case 5:
-            /*
-             *           {
-             *             "status": "connected",
-             *             "host": "127.0.0.1",
-             *             "aitt/topic2": {
-             *                "protocol": WEBRTC,
-             *                "port": 2000,
-             *             }
-             *            }
-             */
-            builder.putString("status", Definitions.JOIN_NETWORK);
-            builder.putString("host", Definitions.AITT_LOCALHOST);
-            secondStart = builder.startMap();
-            builder.putInt("port", 2000);
-            builder.putInt("protocol", Aitt.Protocol.WEBRTC.getValue());
-            builder.endMap("aitt/topic2", secondStart);
-            break;
-         case 6:
-            /*
-             *           {
-             *             "status": "disconnected",
-             *             "host": "127.0.0.1",
-             *             "aitt/topic1": {
-             *                "protocol": TCP,
-             *                "port": 1000,
-             *             }
-             *            }
-             */
-            builder.putString("status", Definitions.WILL_LEAVE_NETWORK);
-            builder.putString("host", Definitions.AITT_LOCALHOST);
-            secondStart = builder.startMap();
-            builder.putInt("port", 1000);
-            builder.putInt("protocol", Aitt.Protocol.TCP.getValue());
-            builder.endMap("aitt/topic1", secondStart);
-            break;
-         default:
-            return null;
-      }
-      builder.endMap(null, start);
-      ByteBuffer bb = builder.finish();
-      byte[] array = new byte[bb.remaining()];
-      bb.get(array,0,array.length);
-      return array;
-   }
-
-   @Test
-   public void testAittConstructor_P(){
-      String id = "aitt";
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, id);
-         assertNotNull("Aitt Instance not null", aitt);
-      } catch(Exception e) {
-         fail("Failed testInitialize " + e);
-      }
-   }
-
-   @Test(expected = IllegalArgumentException.class)
-   public void testInitializeInvalidId_N() {
-      String _id = "";
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, _id);
-         aitt.close();
-      } catch(InstantiationException e) {
-         fail("Error during testInitializeInvalidId" + e);
-      }
-   }
-
-   @Test(expected = IllegalArgumentException.class)
-   public void testInitializeInvalidContext_N() {
-      String _id = "";
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(null, _id);
-         aitt.close();
-      } catch(InstantiationException e) {
-         fail("Error during testInitializeInvalidContext" + e);
-      }
-   }
-
-   @Test(expected = InstantiationException.class)
-   public void testConstructorFail_N() throws InstantiationException {
-      shadowJniInterface.setInitReturn(false);
-      String id = "aitt";
-      Aitt aitt = new Aitt(appContext,id);
-      aitt.close();
-   }
-
-   @Test
-   public void testConnect_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         aitt.close();
-      } catch(Exception e) {
-         fail("Failed testConnect " + e);
-      }
-   }
-
-   @Test
-   public void testConnectWithoutIP_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(null);
-
-         aitt.close();
-      } catch(Exception e) {
-         fail("Failed testConnectWithoutIP " + e);
-      }
-   }
-
-   @Test
-   public void testDisconnect_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testDisconnect " + e);
-      }
-   }
-
-   @Test
-   public void testPublishMqtt_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         byte[] payload = message.getBytes();
-         aitt.publish(topic, payload);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testPublishMqtt " + e);
-      }
-   }
-
-   @Test
-   public void testPublishWebRTC_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         byte[] payload = message.getBytes();
-         aitt.publish(topic, payload, Aitt.Protocol.WEBRTC, Aitt.QoS.AT_MOST_ONCE, false);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testPublishWebRTC " + e);
-      }
-   }
-
-   @Test
-   public void testPublishInvalidTopic_N(){
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-         aitt.connect(brokerIp, port);
-         String _topic = "";
-         byte[] payload = message.getBytes();
-
-         assertThrows(IllegalArgumentException.class, () -> {
-            aitt.publish(_topic, payload);
-         });
-
-         aitt.disconnect();
-      } catch(Exception e){
-         fail("Failed testPublishInvalidTopic" + e);
-      }
-   }
-
-   @Test
-   public void testPublishAnyProtocol_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         byte[] payload = message.getBytes();
-         aitt.publish(topic, payload, Aitt.Protocol.TCP, Aitt.QoS.AT_LEAST_ONCE, false);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testPublishAnyProtocol " + e);
-      }
-   }
-
-   @Test
-   public void testPublishProtocolSet_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         byte[] payload = message.getBytes();
-         EnumSet<Aitt.Protocol> protocols = EnumSet.of(Aitt.Protocol.MQTT, Aitt.Protocol.TCP);
-         aitt.publish(topic, payload, protocols, Aitt.QoS.AT_MOST_ONCE, false);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testPublishProtocolSet " + e);
-      }
-   }
-
-   @Test
-   public void testPublishInvalidProtocol_N(){
-      try{
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-         aitt.connect(brokerIp,port);
-         byte[] payload = message.getBytes();
-         EnumSet<Aitt.Protocol> protocols = EnumSet.noneOf(Aitt.Protocol.class);
-
-         assertThrows(IllegalArgumentException.class, () -> {
-            aitt.publish(topic, payload, protocols, Aitt.QoS.AT_MOST_ONCE, false);
-         });
-
-         aitt.disconnect();
-      } catch(Exception e){
-         fail("Failed testPublishInvalidProtocol" + e);
-      }
-   }
-
-   @Test
-   public void testSubscribeMqtt_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         aitt.subscribe(topic, new Aitt.SubscribeCallback() {
-            @Override
-            public void onMessageReceived(AittMessage message) {
-               String _topic = message.getTopic();
-               byte[] payload = message.getPayload();
-            }
-         });
+    @Mock
+    private final Context appContext = mock(Context.class);
+
+    private static final int DISCOVERY_MESSAGES_COUNT = 6;
+    private final String brokerIp = "192.168.0.1";
+    private final int port = 1803;
+    private final String topic = "aitt/test";
+    private final String message = "test message";
+    private final String aittId = "aitt";
+
+    ShadowJniInterface shadowJniInterface = new ShadowJniInterface();
+
+    private Method messageCallbackMethod;
+
+    @Before
+    public void initialize() {
+        try {
+            messageCallbackMethod = Aitt.class.getDeclaredMethod("messageCallback", String.class, byte[].class);
+            messageCallbackMethod.setAccessible(true);
+        } catch (Exception e) {
+            fail("Failed to Initialize " + e);
+        }
+    }
+
+    private byte[] createDiscoveryMessage(int count) {
+        int start;
+        FlexBuffersBuilder builder = new FlexBuffersBuilder(ByteBuffer.allocate(512));
+        start = builder.startMap();
+        switch (count) {
+            case 1:
+                /*
+                 *           {
+                 *             "status": "connected",
+                 *             "host": "127.0.0.1",
+                 *             "aitt/topic1": {
+                 *                "protocol": TCP,
+                 *                "port": 1000,
+                 *             }
+                 *            }
+                 */
+                builder.putString("status", Definitions.JOIN_NETWORK);
+                builder.putString("host", Definitions.AITT_LOCALHOST);
+                int secondStart = builder.startMap();
+                builder.putInt("port", 1000);
+                builder.putInt("protocol", Aitt.Protocol.TCP.getValue());
+                builder.endMap("aitt/topic1", secondStart);
+                break;
+            case 2:
+                /*
+                 *           {
+                 *             "status": "connected",
+                 *             "host": "127.0.0.2",
+                 *             "aitt/topic1": {
+                 *                "protocol": MQTT,
+                 *                "port": 2000,
+                 *             }
+                 *            }
+                 */
+                builder.putString("status", Definitions.JOIN_NETWORK);
+                builder.putString("host", "127.0.0.2");
+                secondStart = builder.startMap();
+                builder.putInt("port", 2000);
+                builder.putInt("protocol", Aitt.Protocol.MQTT.getValue());
+                builder.endMap("aitt/topic1", secondStart);
+                break;
+            case 3:
+                /*
+                 *           {
+                 *             "status": "connected",
+                 *             "host": "127.0.0.1",
+                 *             "aitt/topic2": {
+                 *                "protocol": MQTT,
+                 *                "port": 2000,
+                 *             }
+                 *            }
+                 */
+                builder.putString("status", Definitions.JOIN_NETWORK);
+                builder.putString("host", Definitions.AITT_LOCALHOST);
+                secondStart = builder.startMap();
+                builder.putInt("port", 2000);
+                builder.putInt("protocol", Aitt.Protocol.MQTT.getValue());
+                builder.endMap("aitt/topic2", secondStart);
+                break;
+            case 4:
+                /*
+                 *           {
+                 *             "status": "connected",
+                 *             "host": "127.0.0.1",
+                 *             "aitt/topic2": {
+                 *                "protocol": TCP,
+                 *                "port": 4000,
+                 *             }
+                 *            }
+                 */
+                builder.putString("status", Definitions.JOIN_NETWORK);
+                builder.putString("host", Definitions.AITT_LOCALHOST);
+                secondStart = builder.startMap();
+                builder.putInt("port", 4000);
+                builder.putInt("protocol", Aitt.Protocol.TCP.getValue());
+                builder.endMap("aitt/topic2", secondStart);
+                break;
+            case 5:
+                /*
+                 *           {
+                 *             "status": "connected",
+                 *             "host": "127.0.0.1",
+                 *             "aitt/topic2": {
+                 *                "protocol": WEBRTC,
+                 *                "port": 2000,
+                 *             }
+                 *            }
+                 */
+                builder.putString("status", Definitions.JOIN_NETWORK);
+                builder.putString("host", Definitions.AITT_LOCALHOST);
+                secondStart = builder.startMap();
+                builder.putInt("port", 2000);
+                builder.putInt("protocol", Aitt.Protocol.WEBRTC.getValue());
+                builder.endMap("aitt/topic2", secondStart);
+                break;
+            case 6:
+                /*
+                 *           {
+                 *             "status": "disconnected",
+                 *             "host": "127.0.0.1",
+                 *             "aitt/topic1": {
+                 *                "protocol": TCP,
+                 *                "port": 1000,
+                 *             }
+                 *            }
+                 */
+                builder.putString("status", Definitions.WILL_LEAVE_NETWORK);
+                builder.putString("host", Definitions.AITT_LOCALHOST);
+                secondStart = builder.startMap();
+                builder.putInt("port", 1000);
+                builder.putInt("protocol", Aitt.Protocol.TCP.getValue());
+                builder.endMap("aitt/topic1", secondStart);
+                break;
+            default:
+                return null;
+        }
+        builder.endMap(null, start);
+        ByteBuffer bb = builder.finish();
+        byte[] array = new byte[bb.remaining()];
+        bb.get(array, 0, array.length);
+        return array;
+    }
+
+    @Test
+    public void testAittConstructor_P() {
+        String id = "aitt";
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, id);
+            assertNotNull("Aitt Instance not null", aitt);
+        } catch (Exception e) {
+            fail("Failed testInitialize " + e);
+        }
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testInitializeInvalidId_N() {
+        String _id = "";
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, _id);
+            aitt.close();
+        } catch (InstantiationException e) {
+            fail("Error during testInitializeInvalidId" + e);
+        }
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testInitializeInvalidContext_N() {
+        String _id = "";
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(null, _id);
+            aitt.close();
+        } catch (InstantiationException e) {
+            fail("Error during testInitializeInvalidContext" + e);
+        }
+    }
+
+    @Test(expected = InstantiationException.class)
+    public void testConstructorFail_N() throws InstantiationException {
+        shadowJniInterface.setInitReturn(false);
+        String id = "aitt";
+        Aitt aitt = new Aitt(appContext, id);
+        aitt.close();
+    }
+
+    @Test
+    public void testConnect_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            aitt.close();
+        } catch (Exception e) {
+            fail("Failed testConnect " + e);
+        }
+    }
+
+    @Test
+    public void testConnectWithoutIP_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(null);
+
+            aitt.close();
+        } catch (Exception e) {
+            fail("Failed testConnectWithoutIP " + e);
+        }
+    }
+
+    @Test
+    public void testDisconnect_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testDisconnect " + e);
+        }
+    }
+
+    @Test
+    public void testPublishMqtt_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            byte[] payload = message.getBytes();
+            aitt.publish(topic, payload);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testPublishMqtt " + e);
+        }
+    }
+
+    @Test
+    public void testPublishWebRTC_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            byte[] payload = message.getBytes();
+            aitt.publish(topic, payload, Aitt.Protocol.WEBRTC, Aitt.QoS.AT_MOST_ONCE, false);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testPublishWebRTC " + e);
+        }
+    }
+
+    @Test
+    public void testPublishInvalidTopic_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+            String _topic = "";
+            byte[] payload = message.getBytes();
+
+            assertThrows(IllegalArgumentException.class, () -> {
+                aitt.publish(_topic, payload);
+            });
 
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSubscribeMqtt " + e);
-      }
-   }
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testPublishInvalidTopic" + e);
+        }
+    }
+
+    @Test
+    public void testPublishAnyProtocol_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            byte[] payload = message.getBytes();
+            aitt.publish(topic, payload, Aitt.Protocol.TCP, Aitt.QoS.AT_LEAST_ONCE, false);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testPublishAnyProtocol " + e);
+        }
+    }
+
+    @Test
+    public void testPublishProtocolSet_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            byte[] payload = message.getBytes();
+            EnumSet<Aitt.Protocol> protocols = EnumSet.of(Aitt.Protocol.MQTT, Aitt.Protocol.TCP);
+            aitt.publish(topic, payload, protocols, Aitt.QoS.AT_MOST_ONCE, false);
 
-   @Test
-   public void testSubscribeWebRTC_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testPublishProtocolSet " + e);
+        }
+    }
+
+    @Test
+    public void testPublishInvalidProtocol_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+            byte[] payload = message.getBytes();
+            EnumSet<Aitt.Protocol> protocols = EnumSet.noneOf(Aitt.Protocol.class);
+
+            assertThrows(IllegalArgumentException.class, () -> {
+                aitt.publish(topic, payload, protocols, Aitt.QoS.AT_MOST_ONCE, false);
+            });
 
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testPublishInvalidProtocol" + e);
+        }
+    }
+
+    @Test
+    public void testSubscribeMqtt_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            aitt.subscribe(topic, new Aitt.SubscribeCallback() {
+                @Override
+                public void onMessageReceived(AittMessage message) {
+                    String _topic = message.getTopic();
+                    byte[] payload = message.getPayload();
+                }
+            });
 
-         aitt.subscribe(topic, new Aitt.SubscribeCallback() {
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeMqtt " + e);
+        }
+    }
+
+    @Test
+    public void testSubscribeWebRTC_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            aitt.subscribe(topic, new Aitt.SubscribeCallback() {
+                        @Override
+                        public void onMessageReceived(AittMessage message) {
+                            String _topic = message.getTopic();
+                            byte[] payload = message.getPayload();
+                        }
+                    },
+                    Aitt.Protocol.WEBRTC, Aitt.QoS.AT_MOST_ONCE);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeWebRTC " + e);
+        }
+    }
+
+    @Test
+    public void testSubscribeInvalidTopic_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            String _topic = "";
+
+            assertThrows(IllegalArgumentException.class, () -> {
+                aitt.subscribe(_topic, new Aitt.SubscribeCallback() {
                     @Override
                     public void onMessageReceived(AittMessage message) {
-                       String _topic = message.getTopic();
-                       byte[] payload = message.getPayload();
                     }
-                 },
-                 Aitt.Protocol.WEBRTC, Aitt.QoS.AT_MOST_ONCE);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSubscribeWebRTC " + e);
-      }
-   }
-
-   @Test
-   public void testSubscribeInvalidTopic_N() {
-      try{
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-         aitt.connect(brokerIp, port);
-
-         String _topic = "";
-
-         assertThrows(IllegalArgumentException.class, () -> {
-            aitt.subscribe(_topic, new Aitt.SubscribeCallback() {
-               @Override
-               public void onMessageReceived(AittMessage message) {
-               }
+                });
             });
-         });
 
-         aitt.disconnect();
-      } catch(Exception e){
-         fail("Failed testSubscribeInvalidTopic " + e);
-      }
-   }
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeInvalidTopic " + e);
+        }
+    }
 
-   @Test
-   public void testSubscribeInvalidCallback_N() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
+    @Test
+    public void testSubscribeInvalidCallback_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
 
-         aitt.connect(brokerIp, port);
+            aitt.connect(brokerIp, port);
 
-         String _topic = "topic";
+            String _topic = "topic";
 
-         assertThrows(IllegalArgumentException.class, () -> {
-            aitt.subscribe(_topic, null);
-         });
+            assertThrows(IllegalArgumentException.class, () -> {
+                aitt.subscribe(_topic, null);
+            });
 
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSubscribeInvalidCallback " + e);
-      }
-   }
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeInvalidCallback " + e);
+        }
+    }
+
+    @Test
+    public void testSubscribeAnyProtocol_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            aitt.subscribe(topic, new Aitt.SubscribeCallback() {
+                        @Override
+                        public void onMessageReceived(AittMessage message) {
+                            String _topic = message.getTopic();
+                            byte[] payload = message.getPayload();
+                        }
+                    },
+                    Aitt.Protocol.UDP, Aitt.QoS.AT_MOST_ONCE);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeAnyProtocol " + e);
+        }
+    }
+
+    @Test
+    public void testSubscribeInvalidProtocol_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            aitt.connect(brokerIp, port);
+            EnumSet<Aitt.Protocol> protocols = EnumSet.noneOf(Aitt.Protocol.class);
+
+            assertThrows(IllegalArgumentException.class, () -> {
+                aitt.subscribe(topic, new Aitt.SubscribeCallback() {
+                            @Override
+                            public void onMessageReceived(AittMessage message) {
+                                String _topic = message.getTopic();
+                                byte[] payload = message.getPayload();
+                            }
+                        },
+                        protocols, Aitt.QoS.AT_MOST_ONCE);
+            });
 
-   @Test
-   public void testSubscribeAnyProtocol_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeAnyProtocol " + e);
+        }
+    }
+
+    @Test
+    public void testSubscribeProtocolSet_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            EnumSet<Aitt.Protocol> protocols = EnumSet.of(Aitt.Protocol.MQTT, Aitt.Protocol.TCP);
+            aitt.subscribe(topic, new Aitt.SubscribeCallback() {
+                        @Override
+                        public void onMessageReceived(AittMessage message) {
+                            String _topic = message.getTopic();
+                            byte[] payload = message.getPayload();
+                        }
+                    },
+                    protocols, Aitt.QoS.EXACTLY_ONCE);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeProtocolSet " + e);
+        }
+    }
+
+    @Test
+    public void testUnsubscribe_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            aitt.subscribe(topic, new Aitt.SubscribeCallback() {
+                @Override
+                public void onMessageReceived(AittMessage message) {
+                }
+            });
 
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
+            aitt.unsubscribe(topic);
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testUnsubscribe " + e);
+        }
+    }
 
-         aitt.subscribe(topic, new Aitt.SubscribeCallback() {
-                    @Override
-                    public void onMessageReceived(AittMessage message) {
-                       String _topic = message.getTopic();
-                       byte[] payload = message.getPayload();
-                    }
-                 },
-                 Aitt.Protocol.UDP, Aitt.QoS.AT_MOST_ONCE);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSubscribeAnyProtocol " + e);
-      }
-   }
-
-   @Test
-   public void testSubscribeInvalidProtocol_N() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         aitt.connect(brokerIp, port);
-         EnumSet<Aitt.Protocol> protocols = EnumSet.noneOf(Aitt.Protocol.class);
-
-         assertThrows(IllegalArgumentException.class, () -> {
-                    aitt.subscribe(topic, new Aitt.SubscribeCallback() {
-                               @Override
-                               public void onMessageReceived(AittMessage message) {
-                                  String _topic = message.getTopic();
-                                  byte[] payload = message.getPayload();
-                               }
-                            },
-                            protocols, Aitt.QoS.AT_MOST_ONCE);
-                 });
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSubscribeAnyProtocol " + e);
-      }
-   }
-
-   @Test
-   public void testSubscribeProtocolSet_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         EnumSet<Aitt.Protocol> protocols = EnumSet.of(Aitt.Protocol.MQTT, Aitt.Protocol.TCP);
-         aitt.subscribe(topic, new Aitt.SubscribeCallback() {
-                    @Override
-                    public void onMessageReceived(AittMessage message) {
-                       String _topic = message.getTopic();
-                       byte[] payload = message.getPayload();
-                    }
-                 },
-                 protocols, Aitt.QoS.EXACTLY_ONCE);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSubscribeProtocolSet " + e);
-      }
-   }
-
-   @Test
-   public void testUnsubscribe_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         aitt.subscribe(topic, new Aitt.SubscribeCallback() {
-            @Override
-            public void onMessageReceived(AittMessage message) {
-            }
-         });
-
-         aitt.unsubscribe(topic);
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testUnsubscribe " + e);
-      }
-   }
-
-   @Test
-   public void testUnsubscribeInvalidTopic_N() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         aitt.connect(brokerIp, port);
-         String _topic = "";
-
-         assertThrows(IllegalArgumentException.class, () -> {
-            aitt.unsubscribe(_topic);
-         });
-
-         aitt.disconnect();
-      } catch(Exception e){
-         fail("Failed testUnsubscribeInvalidTopic " + e);
-      }
-   }
-
-   @Test
-   public void testSetConnectionCallback_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.setConnectionCallback(new Aitt.ConnectionCallback() {
-            @Override
-            public void onConnected() {
-            }
+    @Test
+    public void testUnsubscribeInvalidTopic_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
 
-            @Override
-            public void onDisconnected() {
-            }
+            aitt.connect(brokerIp, port);
+            String _topic = "";
 
-            @Override
-            public void onConnectionFailed() {
+            assertThrows(IllegalArgumentException.class, () -> {
+                aitt.unsubscribe(_topic);
+            });
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testUnsubscribeInvalidTopic " + e);
+        }
+    }
+
+    @Test
+    public void testSetConnectionCallback_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.setConnectionCallback(new Aitt.ConnectionCallback() {
+                @Override
+                public void onConnected() {
+                }
+
+                @Override
+                public void onDisconnected() {
+                }
+
+                @Override
+                public void onConnectionFailed() {
+                }
+            });
+            aitt.connect(brokerIp, port);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSetConnectionCallback " + e);
+        }
+    }
+
+    @Test
+    public void testSetConnectionCallbackInvalidCallback_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertThrows(IllegalArgumentException.class, () -> {
+                aitt.setConnectionCallback(null);
+            });
+
+            aitt.connect(brokerIp, port);
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSetConnectionCallbackInvalidCallback " + e);
+        }
+    }
+
+    @Test
+    public void testSubscribeMultipleCallbacks_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            Aitt.SubscribeCallback callback1 = message -> {
+            };
+
+            Aitt.SubscribeCallback callback2 = message -> {
+            };
+
+            aitt.subscribe(topic, callback1);
+            aitt.subscribe(topic, callback2);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeMultipleCallbacks " + e);
+        }
+    }
+
+    // The test covers different cases of updating the publish table
+    @Test
+    public void testDiscoveryMessageCallbackConnected_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            int counter = 1;
+            while (counter < DISCOVERY_MESSAGES_COUNT) {
+                byte[] discoveryMessage = createDiscoveryMessage(counter);
+                messageCallbackMethod.invoke(aitt, Definitions.JAVA_SPECIFIC_DISCOVERY_TOPIC, (Object) discoveryMessage);
+                counter++;
             }
-         });
-         aitt.connect(brokerIp, port);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSetConnectionCallback " + e);
-      }
-   }
-
-   @Test
-   public void testSetConnectionCallbackInvalidCallback_N() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertThrows(IllegalArgumentException.class, () -> {
-            aitt.setConnectionCallback(null);
-         });
-
-         aitt.connect(brokerIp, port);
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSetConnectionCallbackInvalidCallback " + e);
-      }
-   }
-
-   @Test
-   public void testSubscribeMultipleCallbacks_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         Aitt.SubscribeCallback callback1 = message -> {};
-
-         Aitt.SubscribeCallback callback2 = message -> {};
-
-         aitt.subscribe(topic, callback1);
-         aitt.subscribe(topic, callback2);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSubscribeMultipleCallbacks " + e);
-      }
-   }
-
-   // The test covers different cases of updating the publish table
-   @Test
-   public void testDiscoveryMessageCallbackConnected_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         int counter = 1;
-         while (counter < DISCOVERY_MESSAGES_COUNT) {
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testDiscoveryMessageCallback " + e);
+        }
+    }
+
+    @Test
+    public void testDiscoveryMessageCallbackDisconnected_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            int counter = 1;
             byte[] discoveryMessage = createDiscoveryMessage(counter);
             messageCallbackMethod.invoke(aitt, Definitions.JAVA_SPECIFIC_DISCOVERY_TOPIC, (Object) discoveryMessage);
-            counter++;
-         }
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testDiscoveryMessageCallback " + e);
-      }
-   }
-
-   @Test
-   public void testDiscoveryMessageCallbackDisconnected_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         int counter = 1;
-         byte[] discoveryMessage = createDiscoveryMessage(counter);
-         messageCallbackMethod.invoke(aitt, Definitions.JAVA_SPECIFIC_DISCOVERY_TOPIC, (Object) discoveryMessage);
-
-         counter = 6;
-         byte[] disconnectMessage = createDiscoveryMessage(counter);
-         messageCallbackMethod.invoke(aitt, Definitions.JAVA_SPECIFIC_DISCOVERY_TOPIC, (Object) disconnectMessage);
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testDiscoveryMessageCallback " + e);
-      }
-   }
-
-   @Test
-   public void testDiscoveryMessageCallbackEmptyPayload_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-
-         assertNotNull("Aitt Instance not null", aitt);
-         aitt.connect(brokerIp, port);
-
-         byte[] discoveryMessage = new byte[0];
-         messageCallbackMethod.invoke(aitt, Definitions.JAVA_SPECIFIC_DISCOVERY_TOPIC, (Object) discoveryMessage);
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testDiscoveryMessageCallbackEmptyPayload " + e);
-      }
-   }
-
-   @Test
-   public void testSubscribeCallbackVerifyTopic_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-         aitt.connect(brokerIp, port);
-
-         aitt.subscribe(topic, new Aitt.SubscribeCallback() {
-            @Override
-            public void onMessageReceived(AittMessage aittMessage) {
-               String recvTopic = aittMessage.getTopic();
-               assertEquals("Received topic and subscribed topic are equal", recvTopic, topic);
-            }
-         });
-
-         messageCallbackMethod.invoke(aitt, topic, message.getBytes(StandardCharsets.UTF_8));
-
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSubscribeCallback " + e);
-      }
-   }
-
-   @Test
-   public void testSubscribeCallbackVerifyPayload_P() {
-      try {
-         shadowJniInterface.setInitReturn(true);
-         Aitt aitt = new Aitt(appContext, aittId);
-         aitt.connect(brokerIp, port);
-
-         aitt.subscribe(topic, new Aitt.SubscribeCallback() {
-            @Override
-            public void onMessageReceived(AittMessage aittMessage) {
-               String recvMessage = new String(aittMessage.getPayload(), StandardCharsets.UTF_8);
-               assertEquals("Received message and sent message are equal", message, recvMessage);
-            }
-         });
 
-         messageCallbackMethod.invoke(aitt, topic, message.getBytes(StandardCharsets.UTF_8));
+            counter = 6;
+            byte[] disconnectMessage = createDiscoveryMessage(counter);
+            messageCallbackMethod.invoke(aitt, Definitions.JAVA_SPECIFIC_DISCOVERY_TOPIC, (Object) disconnectMessage);
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testDiscoveryMessageCallback " + e);
+        }
+    }
+
+    @Test
+    public void testDiscoveryMessageCallbackEmptyPayload_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("Aitt Instance not null", aitt);
+            aitt.connect(brokerIp, port);
+
+            byte[] discoveryMessage = new byte[0];
+            messageCallbackMethod.invoke(aitt, Definitions.JAVA_SPECIFIC_DISCOVERY_TOPIC, (Object) discoveryMessage);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testDiscoveryMessageCallbackEmptyPayload " + e);
+        }
+    }
+
+    @Test
+    public void testSubscribeCallbackVerifyTopic_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            aitt.subscribe(topic, new Aitt.SubscribeCallback() {
+                @Override
+                public void onMessageReceived(AittMessage aittMessage) {
+                    String recvTopic = aittMessage.getTopic();
+                    assertEquals("Received topic and subscribed topic are equal", recvTopic, topic);
+                }
+            });
+
+            messageCallbackMethod.invoke(aitt, topic, message.getBytes(StandardCharsets.UTF_8));
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeCallback " + e);
+        }
+    }
+
+    @Test
+    public void testSubscribeCallbackVerifyPayload_P() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            aitt.subscribe(topic, new Aitt.SubscribeCallback() {
+                @Override
+                public void onMessageReceived(AittMessage aittMessage) {
+                    String recvMessage = new String(aittMessage.getPayload(), StandardCharsets.UTF_8);
+                    assertEquals("Received message and sent message are equal", message, recvMessage);
+                }
+            });
+
+            messageCallbackMethod.invoke(aitt, topic, message.getBytes(StandardCharsets.UTF_8));
 
-         aitt.disconnect();
-      } catch(Exception e) {
-         fail("Failed testSubscribeCallback " + e);
-      }
-   }
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeCallback " + e);
+        }
+    }
 }
index 71092d2..47867be 100644 (file)
@@ -10,32 +10,33 @@ public class ShadowJniInterface {
     private static boolean initReturn = true;
 
     @Implementation
-    public long init(String id, String ip, boolean clearSession){
-        if(initReturn)
+    public long init(String id, String ip, boolean clearSession) {
+        if (initReturn)
             return 1L;
         else
             return 0L;
     }
 
     @Implementation
-    public void connect(long instance, final String host, int port){
+    public void connect(long instance, final String host, int port) {
     }
 
     @Implementation
-    public void publish(long instance, final String topic, final byte[] data, long datalen, int protocol, int qos, boolean retain){
+    public void publish(long instance, final String topic, final byte[] data, long datalen, int protocol, int qos, boolean retain) {
     }
 
     @Implementation
-    public void disconnect(long instance){
+    public void disconnect(long instance) {
 
     }
+
     @Implementation
-    public long subscribe(long instance, final String topic, int protocol, int qos){
+    public long subscribe(long instance, final String topic, int protocol, int qos) {
         return 1L;
     }
 
     @Implementation
-    public void unsubscribe(long instance, final long aittSubId){
+    public void unsubscribe(long instance, final long aittSubId) {
     }
 
     public void setInitReturn(boolean initReturn) {
index bb08157..ac87c09 100644 (file)
@@ -41,7 +41,7 @@ public class TCPInstrumentedTest {
             aitt.publish(topic, payload, Aitt.Protocol.TCP, Aitt.QoS.AT_LEAST_ONCE, false);
 
             // TODO: aitt.disconnect();
-        } catch(Exception e) {
+        } catch (Exception e) {
             fail("Failed to execute testPublishWithTCP_P " + e);
         }
     }
@@ -59,7 +59,7 @@ public class TCPInstrumentedTest {
             }, Aitt.Protocol.TCP, Aitt.QoS.AT_LEAST_ONCE);
 
             // TODO: aitt.disconnect();
-        } catch(Exception e) {
+        } catch (Exception e) {
             fail("Failed testSubscribeWithTCP_P " + e);
         }
     }
@@ -82,7 +82,7 @@ public class TCPInstrumentedTest {
             aitt.publish(topic, payload, Aitt.Protocol.TCP, Aitt.QoS.AT_LEAST_ONCE, false);
 
             // TODO: aitt.disconnect();
-        } catch(Exception e) {
+        } catch (Exception e) {
             fail("Failed testPublishSubscribeWithTCP_P " + e);
         }
     }
index ec7e7a0..c23e0af 100644 (file)
@@ -44,6 +44,7 @@ import org.webrtc.VideoFrame;
 import org.webrtc.VideoSink;
 import org.webrtc.VideoSource;
 import org.webrtc.VideoTrack;
+
 import static org.webrtc.SessionDescription.Type.ANSWER;
 import static org.webrtc.SessionDescription.Type.OFFER;
 
@@ -67,7 +68,7 @@ public class WebRTC {
     private boolean isInitiator;
     private boolean isChannelReady;
     private boolean isStarted;
-    private boolean isReciever;
+    private boolean isReceiver;
     private PeerConnection peerConnection;
     private PeerConnectionFactory factory;
     private VideoTrack videoTrackFromSource;
@@ -78,35 +79,38 @@ public class WebRTC {
     private DataChannel localDataChannel;
     private FrameVideoCapturer videoCapturer;
     private ReceiveDataCallback dataCallback;
-    private String recieverIP;
-    private Integer recieverPort;
+    private String receiverIP;
+    private Integer receiverPort;
 
     /**
      * WebRTC constructor to create webRTC instance
+     *
      * @param appContext Application context creating webRTC instance
      */
     public WebRTC(Context appContext) {
         this.appContext = appContext;
-        this.isReciever = false;
+        this.isReceiver = false;
     }
 
     /**
      * WebRTC constructor to create webRTC instance
+     *
      * @param appContext Application context creating webRTC instance
-     * @param socket Java server socket for webrtc signalling
+     * @param socket     Java server socket for webrtc signalling
      */
-    WebRTC(Context appContext , Socket socket) {
-        Log.d(TAG , "InWebRTC Constructor");
+    WebRTC(Context appContext, Socket socket) {
+        Log.d(TAG, "InWebRTC Constructor");
         this.appContext = appContext;
         this.socket = socket;
-        this.isReciever = true;
+        this.isReceiver = true;
     }
 
     /**
      * To create data call-back mechanism
+     *
      * @param cb aitt callback registered to receive a webrtc data
      */
-    public void registerDataCallback(ReceiveDataCallback cb){
+    public void registerDataCallback(ReceiveDataCallback cb) {
         this.dataCallback = cb;
     }
 
@@ -145,26 +149,27 @@ public class WebRTC {
 
     /**
      * Method to establish communication with peer node
-     * @param recieverIP IP Address of the destination(peer) node
-     * @param recieverPort Port number of the destination(peer) node
+     *
+     * @param receiverIP   IP Address of the destination(peer) node
+     * @param receiverPort Port number of the destination(peer) node
      */
-    public void connect(String recieverIP , Integer recieverPort){
-        this.recieverIP = recieverIP;
-        this.recieverPort = recieverPort;
+    public void connect(String receiverIP, Integer receiverPort) {
+        this.receiverIP = receiverIP;
+        this.receiverPort = receiverPort;
         initialize();
     }
 
     /**
      * Method to initialize webRTC APIs while establishing connection
      */
-    private void initialize(){
+    private void initialize() {
         initializePeerConnectionFactory();
         initializePeerConnections();
-        if(!isReciever){
+        if (!isReceiver) {
             createVideoTrack();
             addVideoTrack();
         }
-        isInitiator = isReciever;
+        isInitiator = isReceiver;
 
         sdpThread = new SDPThread();
         new Thread(sdpThread).start();
@@ -186,7 +191,7 @@ public class WebRTC {
                 try {
                     message.put("type", "offer");
                     message.put("sdp", sessionDescription.description);
-                    sendMessage(true , message);
+                    sendMessage(true, message);
                 } catch (JSONException | IOException e) {
                     Log.e(TAG, "Error during create offer", e);
                 }
@@ -196,7 +201,8 @@ public class WebRTC {
 
     /**
      * Method to send signalling messages over socket connection
-     * @param isJSON Boolean to check if message is JSON
+     *
+     * @param isJSON  Boolean to check if message is JSON
      * @param message Data to be sent over webRTC connection
      * @throws IOException Throws IOException if writing to outStream fails
      */
@@ -220,14 +226,16 @@ public class WebRTC {
 
         /**
          * ProxyVideoSink constructor to create its instance
+         *
          * @param dataCb DataCall back to be set to self-object
          */
-        ProxyVideoSink(ReceiveDataCallback dataCb){
+        ProxyVideoSink(ReceiveDataCallback dataCb) {
             this.dataCallback = dataCb;
         }
 
         /**
          * Method to send data through data call back
+         *
          * @param frame VideoFrame to be transferred using media channel
          */
         @Override
@@ -238,6 +246,7 @@ public class WebRTC {
 
         /**
          * Method used to convert VideoFrame to NV21 data format
+         *
          * @param i420Buffer VideoFrame in I420 buffer format
          * @return the video frame in NV21 data format
          */
@@ -286,10 +295,10 @@ public class WebRTC {
     /**
      * Method to create video track
      */
-    private void createVideoTrack(){
+    private void createVideoTrack() {
         videoCapturer = new FrameVideoCapturer();
         VideoSource videoSource = factory.createVideoSource(false);
-        videoCapturer.initialize(null , null ,videoSource.getCapturerObserver());
+        videoCapturer.initialize(null, null, videoSource.getCapturerObserver());
         videoTrackFromSource = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource);
         videoTrackFromSource.setEnabled(true);
     }
@@ -310,13 +319,14 @@ public class WebRTC {
     private void addVideoTrack() {
         MediaStream mediaStream = factory.createLocalMediaStream("ARDAMS");
         mediaStream.addTrack(videoTrackFromSource);
-        if(peerConnection!=null){
+        if (peerConnection != null) {
             peerConnection.addStream(mediaStream);
         }
     }
 
     /**
      * Method to create peer connection
+     *
      * @param factory Peer connection factory object
      * @return return factory object
      */
@@ -355,7 +365,7 @@ public class WebRTC {
                     message.put("id", iceCandidate.sdpMid);
                     message.put(CANDIDATE, iceCandidate.sdp);
                     Log.d(TAG, "onIceCandidate: sending candidate " + message);
-                    sendMessage(true , message);
+                    sendMessage(true, message);
                 } catch (JSONException | IOException e) {
                     Log.e(TAG, "Error during onIceCandidate", e);
                 }
@@ -409,11 +419,11 @@ public class WebRTC {
             @Override
             public void onAddTrack(RtpReceiver rtpReceiver, MediaStream[] mediaStreams) {
                 MediaStreamTrack track = rtpReceiver.track();
-                if (track instanceof VideoTrack && isReciever) {
+                if (track instanceof VideoTrack && isReceiver) {
                     Log.i(TAG, "onAddVideoTrack");
                     VideoTrack remoteVideoTrack = (VideoTrack) track;
                     remoteVideoTrack.setEnabled(true);
-                    ProxyVideoSink  videoSink = new ProxyVideoSink(dataCallback);
+                    ProxyVideoSink videoSink = new ProxyVideoSink(dataCallback);
                     remoteVideoTrack.addSink(videoSink);
                 }
             }
@@ -423,16 +433,18 @@ public class WebRTC {
 
     /**
      * Method used to send video data
-     * @param frame Video frame in byte format
-     * @param width width of the video frame
+     *
+     * @param frame  Video frame in byte format
+     * @param width  width of the video frame
      * @param height height of the video frame
      */
-    public void sendVideoData(byte[] frame , int width , int height){
-        videoCapturer.send(frame , width , height);
+    public void sendVideoData(byte[] frame, int width, int height) {
+        videoCapturer.send(frame, width, height);
     }
 
     /**
      * Method to send message data
+     *
      * @param message message to be sent in byte format
      */
     public void sendMessageData(byte[] message) {
@@ -443,7 +455,7 @@ public class WebRTC {
     /**
      * Interface to create data call back mechanism
      */
-    public interface ReceiveDataCallback{
+    public interface ReceiveDataCallback {
         void pushData(byte[] frame);
     }
 
@@ -453,12 +465,13 @@ public class WebRTC {
     private static class Packet implements Serializable {
         boolean isString;
         String obj;
-        Packet(String s){
+
+        Packet(String s) {
             isString = true;
             obj = s;
         }
 
-        Packet(JSONObject json){
+        Packet(JSONObject json) {
             isString = false;
             obj = json.toString();
         }
@@ -466,6 +479,7 @@ public class WebRTC {
 
     /**
      * Method to read incoming message and convert it to byte format
+     *
      * @param buffer Message incoming in Byte buffer format
      * @return returns byteBuffer message in byte format
      */
@@ -580,6 +594,7 @@ public class WebRTC {
 
         /**
          * Method to decode message
+         *
          * @param message Message received in JSON object format
          */
         private void decodeMessage(JSONObject message) {
@@ -624,10 +639,10 @@ public class WebRTC {
         /**
          * Method used to create a socket for SDP negotiation
          */
-        private void createSocket(){
+        private void createSocket() {
             try {
-                if(!isReciever){
-                    socket = new Socket(recieverIP, recieverPort);
+                if (!isReceiver) {
+                    socket = new Socket(receiverIP, receiverPort);
                 }
                 outStream = new ObjectOutputStream(socket.getOutputStream());
                 inputStream = new ObjectInputStream(socket.getInputStream());
@@ -639,9 +654,9 @@ public class WebRTC {
         /**
          * Method to invoke Signalling handshake message
          */
-        private void invokeSendMessage(){
+        private void invokeSendMessage() {
             try {
-                sendMessage(false , "got user media");
+                sendMessage(false, "got user media");
             } catch (Exception e) {
                 Log.e(TAG, "Error during invoke send message", e);
             }
@@ -650,7 +665,7 @@ public class WebRTC {
         /**
          * Method to check if the message in received packet is "got user media"
          */
-        private void checkPacketMessage(String message){
+        private void checkPacketMessage(String message) {
             if (message.equals("got user media")) {
                 maybeStart();
             }
@@ -659,7 +674,7 @@ public class WebRTC {
         /**
          * Method to invoke MaybeStart()
          */
-        private void invokeMaybeStart(){
+        private void invokeMaybeStart() {
             if (!isInitiator && !isStarted) {
                 maybeStart();
             }
index 4b29985..808d3d7 100644 (file)
@@ -38,19 +38,21 @@ public class WebRTCServer {
 
     /**
      * WebRTCServer constructor to create its instance
-     * @param appContext Application context of the app creating WebRTCServer instance
+     *
+     * @param appContext   Application context of the app creating WebRTCServer instance
      * @param dataCallback Data callback object to create call back mechanism
      */
-    public WebRTCServer(Context appContext, WebRTC.ReceiveDataCallback dataCallback){
+    public WebRTCServer(Context appContext, WebRTC.ReceiveDataCallback dataCallback) {
         this.appContext = appContext;
         this.dataCallback = dataCallback;
     }
 
     /**
      * Method to start WebRTCServer instance
+     *
      * @return Returns Port number on success and -1 on failure
      */
-    public int start(){
+    public int start() {
         try {
             serverSocket = new ServerSocket(0);
         } catch (IOException e) {
@@ -66,7 +68,7 @@ public class WebRTCServer {
     /**
      * Method to stop running WebRTC server instance
      */
-    public void stop(){
+    public void stop() {
         if (serverThread != null) {
             serverThread.stop();
         }
@@ -77,7 +79,7 @@ public class WebRTCServer {
         } catch (IOException e) {
             Log.e(TAG, "Error during stop", e);
         }
-        for(WebRTC web : connectionList){
+        for (WebRTC web : connectionList) {
             web.disconnect();
         }
     }
@@ -85,15 +87,15 @@ public class WebRTCServer {
     /**
      * Class to implement a server thread
      */
-    private class ServerThread implements Runnable{
+    private class ServerThread implements Runnable {
         private volatile boolean isRunning = true;
 
         @Override
         public void run() {
-            while(isRunning){
+            while (isRunning) {
                 try {
                     Socket socket = serverSocket.accept();
-                    WebRTC web = new WebRTC(appContext , socket);
+                    WebRTC web = new WebRTC(appContext, socket);
                     web.connect();
                     web.registerDataCallback(dataCallback);
                     connectionList.add(web);