Skip to content

Commit

Permalink
Fix bug in group manager initialisation and add test (#1442)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <[email protected]>
  • Loading branch information
cdjackson authored Oct 12, 2024
1 parent c389dda commit 04111d7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,16 @@ public ZigBeeNetworkGroupManager(ZigBeeNetworkManager networkManager) {
}

public void initialize() {
networkManager.readNetworkDataStore(DATASTORE_KEY_GROUPS);
Set<ZigBeeGroupDao> daoSet = (Set<ZigBeeGroupDao>) 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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ZigBeeGroupDao> 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());
}
}

0 comments on commit 04111d7

Please sign in to comment.