Skip to content

Commit f5a04d2

Browse files
committed
Add support of empty device lists fixes #37
1 parent 141f563 commit f5a04d2

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/DeviceList.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static java.util.stream.Collectors.toList;
2121

22+
import java.util.ArrayList;
2223
import java.util.List;
2324

2425
import org.simpleframework.xml.Attribute;
@@ -31,8 +32,8 @@ public class DeviceList {
3132
@Attribute(name = "version")
3233
private String apiVersion;
3334

34-
@ElementList(name = "device", type = Device.class, inline = true)
35-
private List<Device> devices;
35+
@ElementList(name = "device", type = Device.class, inline = true, required = false)
36+
private List<Device> devices = new ArrayList<>();
3637

3738
@ElementList(name = "group", type = Group.class, inline = true, required = false)
3839
private List<Group> groups;

src/test/java/com/github/kaklakariada/fritzbox/mapping/DeserializerTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ void parseDeviceListAllTogether() throws IOException {
9090
assertThat(deviceList.getDevices()).hasSize(5);
9191
}
9292

93+
@Test
94+
void parseDeviceListEmpty() throws IOException {
95+
final DeviceList deviceList = parseDeviceList(Paths.get("src/test/resources/FritzOS29/deviceListEmpty.xml"));
96+
assertThat(deviceList.getDevices()).hasSize(0);
97+
}
98+
9399
@Test
94100
void parseDeviceList() throws IOException {
95101
final DeviceList deviceList = parseDeviceList(Paths.get("src/test/resources/deviceList.xml"));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<devicelist version="1" fwversion="7.29"></devicelist>

0 commit comments

Comments
 (0)