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.yeelight.internal;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.when;
17 import static org.openhab.binding.yeelight.internal.YeelightBindingConstants.PARAMETER_DEVICE_ID;
19 import java.util.Arrays;
20 import java.util.List;
22 import org.junit.jupiter.api.BeforeEach;
23 import org.junit.jupiter.api.extension.ExtendWith;
24 import org.junit.jupiter.params.ParameterizedTest;
25 import org.junit.jupiter.params.provider.MethodSource;
26 import org.mockito.Mock;
27 import org.mockito.junit.jupiter.MockitoExtension;
28 import org.mockito.junit.jupiter.MockitoSettings;
29 import org.mockito.quality.Strictness;
30 import org.openhab.binding.yeelight.internal.handler.YeelightCeilingHandler;
31 import org.openhab.binding.yeelight.internal.handler.YeelightCeilingWithAmbientHandler;
32 import org.openhab.binding.yeelight.internal.handler.YeelightCeilingWithNightHandler;
33 import org.openhab.binding.yeelight.internal.handler.YeelightColorHandler;
34 import org.openhab.binding.yeelight.internal.handler.YeelightStripeHandler;
35 import org.openhab.binding.yeelight.internal.handler.YeelightWhiteHandler;
36 import org.openhab.core.config.core.Configuration;
37 import org.openhab.core.thing.Thing;
38 import org.openhab.core.thing.ThingTypeUID;
39 import org.openhab.core.thing.binding.ThingHandler;
42 * Unit tests for {@link YeelightHandlerFactory}
44 * @author Viktor Koop - Initial contribution
45 * @author Nikita Pogudalov - Added YeelightCeilingWithNightHandler for Ceiling 1
47 @ExtendWith(MockitoExtension.class)
48 @MockitoSettings(strictness = Strictness.LENIENT)
49 public class YeelightHandlerFactoryTest {
51 private static final List<Object[]> TESTS = Arrays.asList(
52 new Object[][] { { "dolphin", YeelightWhiteHandler.class }, { "ct_bulb", YeelightWhiteHandler.class },
53 { "wonder", YeelightColorHandler.class }, { "stripe", YeelightStripeHandler.class },
54 { "ceiling", YeelightCeilingHandler.class }, { "ceiling3", YeelightCeilingWithNightHandler.class },
55 { "ceiling1", YeelightCeilingWithNightHandler.class }, { "desklamp", YeelightCeilingHandler.class },
56 { "ceiling4", YeelightCeilingWithAmbientHandler.class }, { "unknown", null } });
58 private final YeelightHandlerFactory factory = new YeelightHandlerFactory();
60 private @Mock Thing thing;
62 public static List<Object[]> data() {
68 Configuration configuration = new Configuration();
69 configuration.put(PARAMETER_DEVICE_ID, "");
71 when(thing.getConfiguration()).thenReturn(configuration);
76 public void testCorrectClass(String name, Class<?> clazz) {
77 when(thing.getThingTypeUID()).thenReturn(new ThingTypeUID(YeelightBindingConstants.BINDING_ID, name));
78 ThingHandler handler = factory.createHandler(thing);
81 assertNull(handler, name + " should not return any handler but null");
83 assertNotNull(handler, name + " should no return null handler");
84 assertEquals(clazz, handler.getClass(), " should be correct matcher");
86 assertEquals(thing, handler.getThing());