From f5a04d2fe38cb1dacfbcee31b15fa45b50889ab5 Mon Sep 17 00:00:00 2001 From: Tino Desjardins Date: Tue, 9 Aug 2022 07:47:26 +0200 Subject: [PATCH 1/2] Add support of empty device lists fixes #37 --- .../fritzbox/model/homeautomation/DeviceList.java | 5 +++-- .../kaklakariada/fritzbox/mapping/DeserializerTest.java | 6 ++++++ src/test/resources/FritzOS29/deviceListEmpty.xml | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/FritzOS29/deviceListEmpty.xml diff --git a/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/DeviceList.java b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/DeviceList.java index 3488834..97bf7a8 100644 --- a/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/DeviceList.java +++ b/src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/DeviceList.java @@ -19,6 +19,7 @@ import static java.util.stream.Collectors.toList; +import java.util.ArrayList; import java.util.List; import org.simpleframework.xml.Attribute; @@ -31,8 +32,8 @@ public class DeviceList { @Attribute(name = "version") private String apiVersion; - @ElementList(name = "device", type = Device.class, inline = true) - private List devices; + @ElementList(name = "device", type = Device.class, inline = true, required = false) + private List devices = new ArrayList<>(); @ElementList(name = "group", type = Group.class, inline = true, required = false) private List groups; diff --git a/src/test/java/com/github/kaklakariada/fritzbox/mapping/DeserializerTest.java b/src/test/java/com/github/kaklakariada/fritzbox/mapping/DeserializerTest.java index a9879ae..4d944b1 100644 --- a/src/test/java/com/github/kaklakariada/fritzbox/mapping/DeserializerTest.java +++ b/src/test/java/com/github/kaklakariada/fritzbox/mapping/DeserializerTest.java @@ -90,6 +90,12 @@ void parseDeviceListAllTogether() throws IOException { assertThat(deviceList.getDevices()).hasSize(5); } + @Test + void parseDeviceListEmpty() throws IOException { + final DeviceList deviceList = parseDeviceList(Paths.get("src/test/resources/FritzOS29/deviceListEmpty.xml")); + assertThat(deviceList.getDevices()).hasSize(0); + } + @Test void parseDeviceList() throws IOException { final DeviceList deviceList = parseDeviceList(Paths.get("src/test/resources/deviceList.xml")); diff --git a/src/test/resources/FritzOS29/deviceListEmpty.xml b/src/test/resources/FritzOS29/deviceListEmpty.xml new file mode 100644 index 0000000..025105a --- /dev/null +++ b/src/test/resources/FritzOS29/deviceListEmpty.xml @@ -0,0 +1 @@ + \ No newline at end of file From 5f085e515d7901b71ffcba40db6721fda728f7a0 Mon Sep 17 00:00:00 2001 From: Tino Desjardins Date: Tue, 9 Aug 2022 18:55:40 +0200 Subject: [PATCH 2/2] Add changelog entry for fix #37 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ff239c..85f2145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#29](https://github.com/kaklakariada/fritzbox-java-api/issues/29) Add support for login via Pbkdf2 challenge-response (propsed by [@linnex81](https://github.com/linnex81)) +### Fixed + +* [#37](https://github.com/kaklakariada/fritzbox-java-api/issues/37) Support empty device lists + ### Refactoring * [#50](https://github.com/kaklakariada/fritzbox-java-api/pull/50) Migrate to Junit 5