2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lifx.internal;
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.*;
21 import java.util.HashSet;
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;
30 * Tests {@link LifxProduct}.
32 * @author Wouter Born - Initial contribution
35 public class LifxProductTest {
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());
47 public void productNamesMatchProductIDs() {
48 for (LifxProduct product : LifxProduct.values()) {
49 assertThat(product.name(), is("PRODUCT_" + product.getID()));
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)));
64 public void upgradesSortedByMajorMinor() {
65 for (LifxProduct product : LifxProduct.values()) {
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),
73 major = upgrade.major;
74 minor = upgrade.minor;
80 public void getFeaturesForProductWithoutUpgrades() {
81 LifxProduct product = LifxProduct.PRODUCT_1;
82 assertThat(product.getUpgrades(), hasSize(0));
84 Features features = product.getFeatures();
85 assertThat(features.getTemperatureRange(), is(TR_2500_9000));
86 assertThat(features.hasFeature(COLOR), is(true));
88 features = product.getFeatures("1.23");
89 assertThat(features.getTemperatureRange(), is(TR_2500_9000));
90 assertThat(features.hasFeature(COLOR), is(true));
94 public void getFeaturesForProductWithUpgrades() {
95 LifxProduct product = LifxProduct.PRODUCT_32;
96 assertThat(product.getUpgrades(), hasSize(2));
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));
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));
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));
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));
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));
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));