Skip to content

Commit

Permalink
Fix package and folder structure alignment
Browse files Browse the repository at this point in the history
1. Move tests to tests.unit from devicetwin package
2. Move service samples to com.microsoft.azure.sdk.iot.samples.service
3. Move device samples to com.microsoft.azure.sdk.iot.samples.device
4. Move device twin package from module DeviceTwin to devicetwin on service only
  • Loading branch information
prmathur-microsoft committed Mar 24, 2017
1 parent a626d1e commit f9091c9
Show file tree
Hide file tree
Showing 39 changed files with 167 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Pair<Type1, Type2>
private Type1 key;
private Type2 value;

Pair(Type1 t1, Type2 t2)
public Pair(Type1 t1, Type2 t2)
{
/*
**Codes_SRS_Pair_25_001: [**The constructor shall save the key and value representing this Pair.**]**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package com.microsoft.azure.sdk.iot.device.DeviceTwin;
package tests.unit.com.microsoft.azure.sdk.iot.device.DeviceTwin;

import com.microsoft.azure.sdk.iot.deps.serializer.Twin;
import com.microsoft.azure.sdk.iot.deps.serializer.TwinChangedCallback;
import com.microsoft.azure.sdk.iot.device.*;
import com.microsoft.azure.sdk.iot.device.DeviceTwin.*;
import mockit.*;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package com.microsoft.azure.sdk.iot.device.DeviceTwin;
package tests.unit.com.microsoft.azure.sdk.iot.device.DeviceTwin;

import com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package com.microsoft.azure.sdk.iot.device.transport.mqtt;
package tests.unit.com.microsoft.azure.sdk.iot.device.transport.mqtt;

import com.microsoft.azure.sdk.iot.device.Message;
import com.microsoft.azure.sdk.iot.device.MessageType;
import com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage;
import com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations;

import mockit.Deencapsulation;
import mockit.Mocked;
import mockit.Verifications;
import com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt;
import com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod;
import mockit.*;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -70,12 +70,13 @@ public void startSucceedsCalls() throws IOException
new Verifications()
{
{
mockedMqtt.subscribe(anyString);
Deencapsulation.invoke(mockedMqtt, "subscribe", anyString);
times = 0;
}
};
}


@Test
public void startSucceedsDoesNotCallsSubscribeIfStarted() throws IOException
{
Expand All @@ -89,7 +90,7 @@ public void startSucceedsDoesNotCallsSubscribeIfStarted() throws IOException
new Verifications()
{
{
mockedMqtt.subscribe(anyString);
Deencapsulation.invoke(mockedMqtt, "subscribe", anyString);
maxTimes = 0;
}
};
Expand All @@ -109,10 +110,11 @@ public void stopSucceedsCallsUnSubscribe() throws IOException
testMethod.stop();

//assert

new Verifications()
{
{
mockedMqtt.unsubscribe(anyString);
Deencapsulation.invoke(mockedMqtt, "unsubscribe", anyString);
maxTimes = 1;
}
};
Expand All @@ -133,7 +135,7 @@ public void stopSucceedsDoesNotCallUnSubscribeIfStopped() throws IOException
new Verifications()
{
{
mockedMqtt.unsubscribe(anyString);
Deencapsulation.invoke(mockedMqtt, "unsubscribe", anyString);
maxTimes = 1;
}
};
Expand All @@ -152,7 +154,7 @@ public void stopSucceedsDoesNotCallUnSubscribeIfNotStarted() throws IOException
new Verifications()
{
{
mockedMqtt.unsubscribe(anyString);
Deencapsulation.invoke(mockedMqtt, "unsubscribe", anyString);
maxTimes = 0;
}
};
Expand Down Expand Up @@ -184,7 +186,7 @@ public void sendSucceedsCallsSubscribe() throws IOException
new Verifications()
{
{
mockedMqtt.subscribe(actualSubscribeTopic);
Deencapsulation.invoke(mockedMqtt, "subscribe", actualSubscribeTopic);
maxTimes = 1;
}
};
Expand Down Expand Up @@ -214,7 +216,7 @@ public void sendSucceedsCallsPublish() throws IOException
new Verifications()
{
{
mockedMqtt.publish(anyString, actualPayload);
Deencapsulation.invoke(mockedMqtt, "publish", anyString, actualPayload);
maxTimes = 1;
}
};
Expand Down Expand Up @@ -279,9 +281,9 @@ public void sendDoesNotSendOnDifferentMessageType() throws IOException
new Verifications()
{
{
mockedMqtt.publish(anyString, actualPayload);
Deencapsulation.invoke(mockedMqtt, "publish", anyString, actualPayload);
maxTimes = 0;
mockedMqtt.subscribe(anyString);
Deencapsulation.invoke(mockedMqtt, "subscribe", anyString);
maxTimes = 0;
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package com.microsoft.azure.sdk.iot.device.transport.mqtt;
package tests.unit.com.microsoft.azure.sdk.iot.device.transport.mqtt;

import com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage;

import com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations;
import com.microsoft.azure.sdk.iot.device.MessageType;
import com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt;
import com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin;
import mockit.*;
import mockit.Deencapsulation;
import mockit.Mocked;
Expand Down Expand Up @@ -69,7 +71,7 @@ public void startSubscribesToDeviceTwinResponse(@Mocked final Mqtt mockMqtt) thr
new Verifications()
{
{
mockMqtt.subscribe(resTopic);
Deencapsulation.invoke(mockMqtt, "subscribe", resTopic);
times = 1;

}
Expand All @@ -88,7 +90,7 @@ public void startThrowsExceptionIfSubscribesFails(@Mocked final Mqtt mockMqtt) t
new StrictExpectations()
{
{
mockMqtt.subscribe(resTopic);
Deencapsulation.invoke(mockMqtt, "subscribe", resTopic);
result = mockIOException;
}
};
Expand Down Expand Up @@ -123,7 +125,7 @@ public void stopUnsubscribesFromDeviceTwinResponse(@Mocked final Mqtt mockMqtt)
new Verifications()
{
{
mockMqtt.unsubscribe(resTopic);
Deencapsulation.invoke(mockMqtt, "unsubscribe", resTopic);
times = 1;

}
Expand All @@ -141,7 +143,7 @@ public void stopThrowsExceptionIfUnSubscribesFails(@Mocked final Mqtt mockMqtt)
new StrictExpectations()
{
{
mockMqtt.unsubscribe(resTopic);
Deencapsulation.invoke(mockMqtt, "unsubscribe", resTopic);
result = mockIOException;
}
};
Expand Down Expand Up @@ -174,7 +176,7 @@ public void parseTopicLooksForDeviceTwinTopic(@Mocked final Mqtt mockMqtt) throw

//act

String parsedTopic = testTwin.parseTopic();
String parsedTopic = Deencapsulation.invoke(testTwin, "parseTopic") ;

//assert
assertNotNull(parsedTopic);
Expand All @@ -196,7 +198,7 @@ public void parseTopicReturnsNullIfNoDeviceTwinTopicFound(@Mocked final Mqtt moc
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);

//act
String parsedTopic = testTwin.parseTopic();
String parsedTopic = Deencapsulation.invoke(testTwin, "parseTopic") ;

//assert
assertNull(parsedTopic);
Expand All @@ -214,7 +216,7 @@ public void parseTopicReturnsNullIfRecevedQueueIsEmpty(@Mocked final Mqtt mockMq
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);

//act
String parsedTopic = testTwin.parseTopic();
String parsedTopic = Deencapsulation.invoke(testTwin, "parseTopic") ;

//assert
assertNull(parsedTopic);
Expand All @@ -231,7 +233,7 @@ public void parseTopicThrowsExceptionIfQueueIsNull(@Mocked final Mqtt mockMqtt)
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);

//act
String parsedTopic = testTwin.parseTopic();
String parsedTopic = Deencapsulation.invoke(testTwin, "parseTopic") ;

//assert
assertNull(parsedTopic);
Expand All @@ -247,7 +249,7 @@ public void parsePayloadReturnNullIfTopicIsNull(@Mocked final Mqtt mockMqtt) thr
MqttDeviceTwin testTwin = new MqttDeviceTwin();

//act
byte[] parsedPayload = testTwin.parsePayload(null);
byte[] parsedPayload = Deencapsulation.invoke(testTwin, "parsePayload", String.class) ;

//assert
assertNull(parsedPayload);
Expand All @@ -266,7 +268,7 @@ public void parsePayloadThrowsExceptionIfQueueIsNull(@Mocked final Mqtt mockMqtt
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);

//act
byte[] parsedPayload = testTwin.parsePayload(resTopic);
byte[] parsedPayload = Deencapsulation.invoke(testTwin, "parsePayload", resTopic) ;

//assert

Expand All @@ -288,7 +290,7 @@ public void parsePayloadThrowsExceptionTopicIsNotFound(@Mocked final Mqtt mockMq
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);

//act
byte[] parsedPayload = testTwin.parsePayload(notTwinTopic);
byte[] parsedPayload = Deencapsulation.invoke(testTwin, "parsePayload", notTwinTopic);

//assert

Expand All @@ -309,7 +311,7 @@ public void parsePayloadReturnsBytesForSpecifiedTopic(@Mocked final Mqtt mockMqt
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);

//act
byte[] parsedPayload = testTwin.parsePayload(insertTopic);
byte[] parsedPayload = Deencapsulation.invoke(testTwin, "parsePayload", insertTopic);

//assert
assertNotNull(parsedPayload);
Expand All @@ -336,7 +338,7 @@ public void parsePayloadRemovesTopicIfFound(@Mocked final Mqtt mockMqtt) throws
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);

//act
byte[] parsedPayload = testTwin.parsePayload(insertTopic);
byte[] parsedPayload = Deencapsulation.invoke(testTwin, "parsePayload", insertTopic);

//assert
ConcurrentSkipListMap<String, byte[]> retrieveTestMap = Deencapsulation.getField(mockMqtt, "allReceivedMessages");
Expand Down Expand Up @@ -378,7 +380,7 @@ public void sendPublishesMessageForGetTwinOnCorrectTopic(@Mocked final Mqtt mock
{
mockMessage.getBytes();
times = 2;
mockMqtt.publish(expectedTopic, actualPayload);
Deencapsulation.invoke(mockMqtt, "publish", expectedTopic, actualPayload);
times = 1;

}
Expand Down Expand Up @@ -425,7 +427,7 @@ public void sendThrowsExceptionForGetTwinOnCorrectTopicIfReqIdIsNullOrEmpty(@Moc
{
mockMessage.getBytes();
times = 1;
mockMqtt.publish(expectedTopic, actualPayload);
Deencapsulation.invoke(mockMqtt, "publish", expectedTopic, actualPayload);
times = 0;

}
Expand Down Expand Up @@ -470,7 +472,7 @@ public void sendPublishesMessageForUpdateReportedPropertiesOnCorrectTopic(@Mocke
{
mockMessage.getBytes();
times = 2;
mockMqtt.publish(expectedTopic, actualPayload);
Deencapsulation.invoke(mockMqtt, "publish", expectedTopic, actualPayload);
times = 1;

}
Expand Down Expand Up @@ -513,7 +515,7 @@ public void sendThrowsExceptionForUpdateReportedPropertiesOnCorrectTopicIfReqIdI
{
mockMessage.getBytes();
times = 1;
mockMqtt.publish(expectedTopic, actualPayload);
Deencapsulation.invoke(mockMqtt, "publish", expectedTopic, actualPayload);
times = 0;

}
Expand Down Expand Up @@ -556,9 +558,9 @@ public void sendDoesNotPublishesMessageForSubscribeToDesiredPropertiesOnCorrectT
{
mockMessage.getBytes();
times = 1;
mockMqtt.subscribe(expectedTopic);
Deencapsulation.invoke(mockMqtt, "subscribe", expectedTopic);
times = 1;
mockMqtt.publish(expectedTopic, actualPayload);
Deencapsulation.invoke(mockMqtt, "publish", expectedTopic, actualPayload);
times = 0;

}
Expand Down Expand Up @@ -601,9 +603,9 @@ public void sendSubscribesMessageForSubscribeToDesiredPropertiesOnCorrectTopic(@
{
mockMessage.getBytes();
times = 1;
mockMqtt.subscribe(expectedSubscribeTopic);
Deencapsulation.invoke(mockMqtt, "subscribe", expectedSubscribeTopic);
times = 1;
mockMqtt.publish(expectedTopic, actualPayload);
Deencapsulation.invoke(mockMqtt, "publish", expectedTopic, actualPayload);
times = 0;

}
Expand Down Expand Up @@ -633,7 +635,7 @@ public void sendThrowsIoExceptionIfMessageIsNull(@Mocked final Mqtt mockMqtt, @M
{
mockMessage.getBytes();
times = 0;
mockMqtt.publish(expectedTopic, actualPayload);
Deencapsulation.invoke(mockMqtt, "publish", expectedTopic, actualPayload);
times = 0;

}
Expand Down Expand Up @@ -674,7 +676,7 @@ public void sendDoesNotThrowsIoExceptionIfMessageIsEmpty(@Mocked final Mqtt mock
{
mockMessage.getBytes();
times = 2;
mockMqtt.publish(expectedTopic, actualPayload);
Deencapsulation.invoke(mockMqtt, "publish", expectedTopic, actualPayload);
times = 1;

}
Expand Down
Loading

0 comments on commit f9091c9

Please sign in to comment.