Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in group manager initialisation and add test #1442

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading