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 8, 2017
1 parent 4cd46a9 commit 39e423c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
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 free();
}
```

Expand Down Expand Up @@ -72,5 +71,5 @@ public void hasDesiredProperty(Property desiredProp, PropertyCallBack<String, Ob
public void free();
```

**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 and set existing collections to new, empty collections.**]**

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 and set existing collections to new, empty collections.]
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 and set existing collections to new, empty collections.]
@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 39e423c

Please sign in to comment.