]> git.basschouten.com Git - openhab-addons.git/blob
1b0efd4e405615011b19e794017a579c1eed1f37
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lifx.internal;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.hamcrest.Matchers.hasSize;
18 import static org.openhab.binding.lifx.internal.LifxProduct.Feature.*;
19 import static org.openhab.binding.lifx.internal.LifxProduct.TemperatureRange.*;
20
21 import java.util.HashSet;
22 import java.util.Set;
23
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.binding.lifx.internal.LifxProduct.Features;
27 import org.openhab.binding.lifx.internal.LifxProduct.Upgrade;
28
29 /**
30  * Tests {@link LifxProduct}.
31  *
32  * @author Wouter Born - Initial contribution
33  */
34 @NonNullByDefault
35 public class LifxProductTest {
36
37     @Test
38     public void productIDsAreUnique() {
39         Set<Long> productIDs = new HashSet<>();
40         for (LifxProduct product : LifxProduct.values()) {
41             assertThat(productIDs, not(hasItem(product.getID())));
42             productIDs.add(product.getID());
43         }
44     }
45
46     @Test
47     public void productNamesMatchProductIDs() {
48         for (LifxProduct product : LifxProduct.values()) {
49             assertThat(product.name(), is("PRODUCT_" + product.getID()));
50         }
51     }
52
53     @Test
54     public void lightsHaveDefinedTemperatureRange() {
55         for (LifxProduct product : LifxProduct.values()) {
56             if (product.isLight()) {
57                 String reason = String.format("The %s light does not define a temperature range", product.name());
58                 assertThat(reason, product.getFeatures().getTemperatureRange(), is(not(NONE)));
59             }
60         }
61     }
62
63     @Test
64     public void upgradesSortedByMajorMinor() {
65         for (LifxProduct product : LifxProduct.values()) {
66             long major = 0;
67             long minor = 0;
68             for (Upgrade upgrade : product.getUpgrades()) {
69                 String reason = String.format("Upgrades for %s are not sorted by major minor (%s.%s >= %s.%s)",
70                         product.name(), major, minor, upgrade.major, upgrade.minor);
71                 assertThat(reason, major < upgrade.major || (major == upgrade.major && minor < upgrade.minor),
72                         is(true));
73                 major = upgrade.major;
74                 minor = upgrade.minor;
75             }
76         }
77     }
78
79     @Test
80     public void getFeaturesForProductWithoutUpgrades() {
81         LifxProduct product = LifxProduct.PRODUCT_1;
82         assertThat(product.getUpgrades(), hasSize(0));
83
84         Features features = product.getFeatures();
85         assertThat(features.getTemperatureRange(), is(TR_2500_9000));
86         assertThat(features.hasFeature(COLOR), is(true));
87
88         features = product.getFeatures("1.23");
89         assertThat(features.getTemperatureRange(), is(TR_2500_9000));
90         assertThat(features.hasFeature(COLOR), is(true));
91     }
92
93     @Test
94     public void getFeaturesForProductWithUpgrades() {
95         LifxProduct product = LifxProduct.PRODUCT_32;
96         assertThat(product.getUpgrades(), hasSize(2));
97
98         Features features = product.getFeatures();
99         assertThat(features.getTemperatureRange(), is(TR_2500_9000));
100         assertThat(features.hasFeature(COLOR), is(true));
101         assertThat(features.hasFeature(EXTENDED_MULTIZONE), is(false));
102         assertThat(features.hasFeature(INFRARED), is(false));
103         assertThat(features.hasFeature(MULTIZONE), is(true));
104
105         features = product.getFeatures("2.70");
106         assertThat(features.getTemperatureRange(), is(TR_2500_9000));
107         assertThat(features.hasFeature(COLOR), is(true));
108         assertThat(features.hasFeature(EXTENDED_MULTIZONE), is(false));
109         assertThat(features.hasFeature(INFRARED), is(false));
110         assertThat(features.hasFeature(MULTIZONE), is(true));
111
112         features = product.getFeatures("2.77");
113         assertThat(features.getTemperatureRange(), is(TR_2500_9000));
114         assertThat(features.hasFeature(COLOR), is(true));
115         assertThat(features.hasFeature(EXTENDED_MULTIZONE), is(true));
116         assertThat(features.hasFeature(INFRARED), is(false));
117         assertThat(features.hasFeature(MULTIZONE), is(true));
118
119         features = product.getFeatures("2.79");
120         assertThat(features.getTemperatureRange(), is(TR_2500_9000));
121         assertThat(features.hasFeature(COLOR), is(true));
122         assertThat(features.hasFeature(EXTENDED_MULTIZONE), is(true));
123         assertThat(features.hasFeature(INFRARED), is(false));
124         assertThat(features.hasFeature(MULTIZONE), is(true));
125
126         features = product.getFeatures("2.80");
127         assertThat(features.getTemperatureRange(), is(TR_1500_9000));
128         assertThat(features.hasFeature(COLOR), is(true));
129         assertThat(features.hasFeature(EXTENDED_MULTIZONE), is(true));
130         assertThat(features.hasFeature(INFRARED), is(false));
131         assertThat(features.hasFeature(MULTIZONE), is(true));
132
133         features = product.getFeatures("2.81");
134         assertThat(features.getTemperatureRange(), is(TR_1500_9000));
135         assertThat(features.hasFeature(COLOR), is(true));
136         assertThat(features.hasFeature(EXTENDED_MULTIZONE), is(true));
137         assertThat(features.hasFeature(INFRARED), is(false));
138         assertThat(features.hasFeature(MULTIZONE), is(true));
139     }
140 }