2 * Copyright (c) 2010-2020 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.Assert.assertEquals;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertNull;
18 import static org.mockito.Mockito.when;
19 import static org.mockito.MockitoAnnotations.initMocks;
20 import static org.openhab.binding.yeelight.internal.YeelightBindingConstants.PARAMETER_DEVICE_ID;
22 import java.util.Arrays;
23 import java.util.List;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.Parameterized;
29 import org.junit.runners.Parameterized.Parameters;
30 import org.mockito.Mock;
31 import org.openhab.binding.yeelight.internal.handler.*;
32 import org.openhab.core.config.core.Configuration;
33 import org.openhab.core.thing.Thing;
34 import org.openhab.core.thing.ThingTypeUID;
35 import org.openhab.core.thing.binding.ThingHandler;
38 * Unit tests for {@link YeelightHandlerFactory}
40 * @author Viktor Koop - Initial contribution
41 * @author Nikita Pogudalov - Added YeelightCeilingWithNightHandler for Ceiling 1
43 @RunWith(value = Parameterized.class)
44 public class YeelightHandlerFactoryTest {
46 private static final List<Object[]> TESTS = Arrays.asList(
47 new Object[][] { { "dolphin", YeelightWhiteHandler.class }, { "ct_bulb", YeelightWhiteHandler.class },
48 { "wonder", YeelightColorHandler.class }, { "stripe", YeelightStripeHandler.class },
49 { "ceiling", YeelightCeilingHandler.class }, { "ceiling3", YeelightCeilingHandler.class },
50 { "ceiling1", YeelightCeilingWithNightHandler.class }, { "desklamp", YeelightCeilingHandler.class },
51 { "ceiling4", YeelightCeilingWithAmbientHandler.class }, { "unknown", null } });
53 private final YeelightHandlerFactory factory = new YeelightHandlerFactory();
58 private final String name;
59 private final Class<?> clazz;
61 public YeelightHandlerFactoryTest(String name, Class<?> clazz) {
66 @Parameters(name = "{0} - {1}")
67 public static List<Object[]> data() {
74 Configuration configuration = new Configuration();
75 configuration.put(PARAMETER_DEVICE_ID, "");
77 when(thing.getConfiguration()).thenReturn(configuration);
81 public void testCorrectClass() {
82 when(thing.getThingTypeUID()).thenReturn(new ThingTypeUID(YeelightBindingConstants.BINDING_ID, name));
83 ThingHandler handler = factory.createHandler(thing);
86 assertNull(name + " should not return any handler but null", handler);
88 assertNotNull(name + " should no return null handler", handler);
89 assertEquals(" should be correct matcher", clazz, handler.getClass());
91 assertEquals(thing, handler.getThing());