Skip to content

Commit

Permalink
Fixed bug where device.clean() broke state of a Device object
Browse files Browse the repository at this point in the history
Github bug #164
  • Loading branch information
timtay-microsoft committed Dec 11, 2017
1 parent 05c5c48 commit 9b02e83
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public byte[] getAmqpBody()
* Set the application property for the message
* @param userProperties
*/
public void setApplicationProperty(Map<String, String> userProperties)
public void setApplicationProperty(Map<String, Object> userProperties)
{
ApplicationProperties applicationProperties = new ApplicationProperties(userProperties);
this.messageImpl.setApplicationProperties(applicationProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void setApplicationPropertySucceeds()
}
};

Map<String, String> userProperties = new HashMap<>();
Map<String, Object> userProperties = new HashMap<>();
amqpMessage.setApplicationProperty(userProperties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ abstract public class Device implements PropertyCallBack<String, Object>
public HashMap<Property, Pair<PropertyCallBack<String, Object>, Object>> getDesiredProp();
public void hasDesiredProperty(Property desiredProp, PropertyCallBack<String, Object> desiredPropCallBack, Object desiredPropCallBackContext);

public void free();

public void clean();
}
```

Expand Down Expand Up @@ -66,11 +65,11 @@ public void hasDesiredProperty(Property desiredProp, PropertyCallBack<String, Ob

**SRS_DEVICE_25_008: [**This method shall add the parameters to the map even if callback and object pair are null**]**

### free
### clean

```java
public void free();
public void clean();
```

**SRS_DEVICE_25_009: [**The method shall remove all the reported and desired properties set by the user so far and mark existing collections as null to be garbage collected.**]**
**SRS_DEVICE_34_009: [**The method shall remove all the reported and desired properties set by the user so far.**]**

Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public void setDesiredPropertyCallback(Property desiredProp, PropertyCallBack<St

public void clean()
{
/*
**Codes_SRS_DEVICE_25_009: [**The method shall remove all the reported and desired properties set by the user so far and mark existing collections as null to be garbage collected.**]**
*/
//Codes_SRS_DEVICE_34_009: [The method shall remove all the reported and desired properties set by the user so far.]
if (reportedProp != null)
{
for (Iterator repProperty = reportedProp.iterator(); repProperty.hasNext();)
Expand All @@ -73,7 +71,6 @@ public void clean()
repProperty.remove();
}
}
reportedProp = null;

if (desiredProp != null)
{
Expand All @@ -83,7 +80,5 @@ public void clean()
desiredProperty.remove();
}
}
desiredProp = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

import static org.junit.Assert.*;

/**
* Unit tests for Device.java
* Methods: 100%
* Lines: 100%
*/
public class DeviceTest
{
@Test
Expand Down Expand Up @@ -275,9 +280,7 @@ public void PropertyCall(String propertyKey, Object propertyValue, Object contex

}

/*
**Tests_SRS_DEVICE_25_009: [**The method shall remove all the reported and desired properties set by the user so far and mark existing collections as null to be garbage collected.**]**
*/
//Tests_SRS_DEVICE_34_009: [The method shall remove all the reported and desired properties set by the user so far.]
@Test
public void freeEmptiesAllProperties()
{
Expand All @@ -303,8 +306,8 @@ public void PropertyCall(String propertyKey, Object propertyValue, Object contex
HashMap<Property, Pair<PropertyCallBack<String, Object>, Object>> testDesiredMap = testDev.getDesiredProp();
HashSet<Property> testRepMap = testDev.getReportedProp();

assertNull(testDesiredMap);
assertNull(testRepMap);
assertTrue(testDesiredMap.isEmpty());
assertTrue(testRepMap.isEmpty());
}

}

0 comments on commit 9b02e83

Please sign in to comment.