diff --git a/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/groups/ZigBeeNetworkGroupManager.java b/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/groups/ZigBeeNetworkGroupManager.java index 97660dcc7c..4bfac1351f 100644 --- a/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/groups/ZigBeeNetworkGroupManager.java +++ b/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/groups/ZigBeeNetworkGroupManager.java @@ -113,7 +113,16 @@ public ZigBeeNetworkGroupManager(ZigBeeNetworkManager networkManager) { } public void initialize() { - networkManager.readNetworkDataStore(DATASTORE_KEY_GROUPS); + Set daoSet = (Set) networkManager.readNetworkDataStore(DATASTORE_KEY_GROUPS); + if (daoSet == null) { + return; + } + + for (ZigBeeGroupDao dao : daoSet) { + ZigBeeGroup group = new ZigBeeGroup(networkManager, 0); + group.setDao(dao); + networkGroups.put(group.getGroupId(), group); + } } public void shutdown() { diff --git a/com.zsmartsystems.zigbee/src/test/java/com/zsmartsystems/zigbee/groups/ZigBeeNetworkGroupManagerTest.java b/com.zsmartsystems.zigbee/src/test/java/com/zsmartsystems/zigbee/groups/ZigBeeNetworkGroupManagerTest.java new file mode 100644 index 0000000000..c612bc8667 --- /dev/null +++ b/com.zsmartsystems.zigbee/src/test/java/com/zsmartsystems/zigbee/groups/ZigBeeNetworkGroupManagerTest.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2016-2024 by the respective copyright holders. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package com.zsmartsystems.zigbee.groups; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.mockito.Mockito; + +import com.zsmartsystems.zigbee.ZigBeeNetworkManager; + +/** + * Tests for {@link ZigBeeNetworkGroupManager} + * + * @author Chris Jackson + * + */ +public class ZigBeeNetworkGroupManagerTest { + + @Test + public void initialize() { + ZigBeeNetworkManager networkManager = Mockito.mock(ZigBeeNetworkManager.class); + ZigBeeNetworkGroupManager groupManager = new ZigBeeNetworkGroupManager(networkManager); + + assertTrue(groupManager.getAll().isEmpty()); + groupManager.initialize(); + assertTrue(groupManager.getAll().isEmpty()); + + Set daoSet = new HashSet<>(); + daoSet.add(new ZigBeeGroupDao()); + + Mockito.when(networkManager.readNetworkDataStore(any())).thenReturn(daoSet); + + assertTrue(groupManager.getAll().isEmpty()); + groupManager.initialize(); + assertEquals(1, groupManager.getAll().size()); + } +}