-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for SceneChannelBuilder and SceneGroupChannelBuilder.
Signed-off-by: Jacob Laursen <[email protected]>
- Loading branch information
Showing
4 changed files
with
216 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...ng.hdpowerview/src/test/java/org/openhab/binding/hdpowerview/SceneChannelBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.hdpowerview; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Base64; | ||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstants; | ||
import org.openhab.binding.hdpowerview.internal.HDPowerViewTranslationProvider; | ||
import org.openhab.binding.hdpowerview.internal.api.responses.Scenes.Scene; | ||
import org.openhab.binding.hdpowerview.internal.builders.SceneChannelBuilder; | ||
import org.openhab.core.thing.Channel; | ||
import org.openhab.core.thing.ChannelGroupUID; | ||
import org.openhab.core.thing.ThingUID; | ||
import org.osgi.framework.Bundle; | ||
|
||
/** | ||
* Unit tests for {@link SceneChannelBuilder}. | ||
* | ||
* @author Jacob Laursen - Initial contribution | ||
*/ | ||
public class SceneChannelBuilderTest { | ||
|
||
private static final ChannelGroupUID CHANNEL_GROUP_UID = new ChannelGroupUID( | ||
new ThingUID(HDPowerViewBindingConstants.BINDING_ID, SceneChannelBuilderTest.class.getSimpleName()), | ||
HDPowerViewBindingConstants.CHANNELTYPE_SCENE_ACTIVATE); | ||
|
||
private HDPowerViewTranslationProvider translationProvider; | ||
private SceneChannelBuilder builder; | ||
|
||
@BeforeEach | ||
private void setUp() { | ||
translationProvider = new HDPowerViewTranslationProvider(mock(Bundle.class), new TranslationProviderForTests(), | ||
new LocaleProviderForTests()); | ||
builder = SceneChannelBuilder.create(translationProvider, CHANNEL_GROUP_UID); | ||
} | ||
|
||
@Test | ||
public void labelIsCorrect() { | ||
List<Scene> scenes = createScenes(); | ||
|
||
@NonNull | ||
List<@NonNull Channel> channels = builder.withScenes(scenes).build(); | ||
|
||
assertEquals(1, channels.size()); | ||
assertEquals("TestScene", channels.get(0).getLabel()); | ||
} | ||
|
||
@Test | ||
public void descriptionIsCorrect() { | ||
List<Scene> scenes = createScenes(); | ||
|
||
@NonNull | ||
List<@NonNull Channel> channels = builder.withScenes(scenes).build(); | ||
|
||
assertEquals(1, channels.size()); | ||
assertEquals("Activates the scene 'TestScene'", channels.get(0).getDescription()); | ||
} | ||
|
||
@Test | ||
public void groupAndIdAreCorrect() { | ||
List<Scene> scenes = createScenes(); | ||
|
||
@NonNull | ||
List<@NonNull Channel> channels = builder.withScenes(scenes).build(); | ||
|
||
assertEquals(1, channels.size()); | ||
assertEquals(CHANNEL_GROUP_UID.getId(), channels.get(0).getUID().getGroupId()); | ||
assertEquals(Integer.toString(scenes.get(0).id), channels.get(0).getUID().getIdWithoutGroup()); | ||
} | ||
|
||
@Test | ||
public void suppliedListIsUsed() { | ||
List<Scene> scenes = createScenes(); | ||
List<Channel> existingChannels = new ArrayList<>(0); | ||
|
||
@NonNull | ||
List<@NonNull Channel> channels = builder.withScenes(scenes).withChannels(existingChannels).build(); | ||
|
||
assertEquals(existingChannels, channels); | ||
} | ||
|
||
private List<Scene> createScenes() { | ||
Scene scene = new Scene(); | ||
scene.id = 1; | ||
scene.name = Base64.getEncoder().encodeToString(("TestScene").getBytes()); | ||
return new ArrayList<>(List.of(scene)); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...powerview/src/test/java/org/openhab/binding/hdpowerview/SceneGroupChannelBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.hdpowerview; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Base64; | ||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstants; | ||
import org.openhab.binding.hdpowerview.internal.HDPowerViewTranslationProvider; | ||
import org.openhab.binding.hdpowerview.internal.api.responses.SceneCollections.SceneCollection; | ||
import org.openhab.binding.hdpowerview.internal.builders.SceneGroupChannelBuilder; | ||
import org.openhab.core.thing.Channel; | ||
import org.openhab.core.thing.ChannelGroupUID; | ||
import org.openhab.core.thing.ThingUID; | ||
import org.osgi.framework.Bundle; | ||
|
||
/** | ||
* Unit tests for {@link SceneGroupChannelBuilder}. | ||
* | ||
* @author Jacob Laursen - Initial contribution | ||
*/ | ||
public class SceneGroupChannelBuilderTest { | ||
|
||
private static final ChannelGroupUID CHANNEL_GROUP_UID = new ChannelGroupUID( | ||
new ThingUID(HDPowerViewBindingConstants.BINDING_ID, SceneGroupChannelBuilderTest.class.getSimpleName()), | ||
HDPowerViewBindingConstants.CHANNELTYPE_SCENE_GROUP_ACTIVATE); | ||
|
||
private HDPowerViewTranslationProvider translationProvider; | ||
private SceneGroupChannelBuilder builder; | ||
|
||
@BeforeEach | ||
private void setUp() { | ||
translationProvider = new HDPowerViewTranslationProvider(mock(Bundle.class), new TranslationProviderForTests(), | ||
new LocaleProviderForTests()); | ||
builder = SceneGroupChannelBuilder.create(translationProvider, CHANNEL_GROUP_UID); | ||
} | ||
|
||
@Test | ||
public void labelIsCorrect() { | ||
List<SceneCollection> sceneCollections = createSceneCollections(); | ||
|
||
@NonNull | ||
List<@NonNull Channel> channels = builder.withSceneCollections(sceneCollections).build(); | ||
|
||
assertEquals(1, channels.size()); | ||
assertEquals("TestSceneCollection", channels.get(0).getLabel()); | ||
} | ||
|
||
@Test | ||
public void descriptionIsCorrect() { | ||
List<SceneCollection> sceneCollections = createSceneCollections(); | ||
|
||
@NonNull | ||
List<@NonNull Channel> channels = builder.withSceneCollections(sceneCollections).build(); | ||
|
||
assertEquals(1, channels.size()); | ||
assertEquals("Activates the scene group 'TestSceneCollection'", channels.get(0).getDescription()); | ||
} | ||
|
||
@Test | ||
public void groupAndIdAreCorrect() { | ||
List<SceneCollection> sceneCollections = createSceneCollections(); | ||
|
||
@NonNull | ||
List<@NonNull Channel> channels = builder.withSceneCollections(sceneCollections).build(); | ||
|
||
assertEquals(1, channels.size()); | ||
assertEquals(CHANNEL_GROUP_UID.getId(), channels.get(0).getUID().getGroupId()); | ||
assertEquals(Integer.toString(sceneCollections.get(0).id), channels.get(0).getUID().getIdWithoutGroup()); | ||
} | ||
|
||
@Test | ||
public void suppliedListIsUsed() { | ||
List<SceneCollection> sceneCollections = createSceneCollections(); | ||
List<Channel> existingChannels = new ArrayList<>(0); | ||
|
||
@NonNull | ||
List<@NonNull Channel> channels = builder.withSceneCollections(sceneCollections).withChannels(existingChannels) | ||
.build(); | ||
|
||
assertEquals(existingChannels, channels); | ||
} | ||
|
||
private List<SceneCollection> createSceneCollections() { | ||
SceneCollection sceneCollection = new SceneCollection(); | ||
sceneCollection.id = 1; | ||
sceneCollection.name = Base64.getEncoder().encodeToString(("TestSceneCollection").getBytes()); | ||
return new ArrayList<>(List.of(sceneCollection)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters