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.tplinksmarthome.internal;
15 import static org.junit.Assert.*;
16 import static org.mockito.Mockito.when;
17 import static org.mockito.MockitoAnnotations.initMocks;
19 import java.lang.reflect.Field;
20 import java.util.Arrays;
21 import java.util.List;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.junit.runners.Parameterized;
27 import org.junit.runners.Parameterized.Parameters;
28 import org.mockito.Mock;
29 import org.openhab.binding.tplinksmarthome.internal.device.BulbDevice;
30 import org.openhab.binding.tplinksmarthome.internal.device.DimmerDevice;
31 import org.openhab.binding.tplinksmarthome.internal.device.EnergySwitchDevice;
32 import org.openhab.binding.tplinksmarthome.internal.device.PowerStripDevice;
33 import org.openhab.binding.tplinksmarthome.internal.device.RangeExtenderDevice;
34 import org.openhab.binding.tplinksmarthome.internal.device.SwitchDevice;
35 import org.openhab.binding.tplinksmarthome.internal.handler.SmartHomeHandler;
36 import org.openhab.core.thing.Thing;
37 import org.openhab.core.thing.ThingTypeUID;
40 * Test class for {@link TPLinkSmartHomeHandlerFactory}.
42 * @author Hilbrand Bouwkamp - Initial contribution
44 @RunWith(value = Parameterized.class)
45 public class TPLinkSmartHomeHandlerFactoryTest {
47 private static final String SMART_HOME_DEVICE_FIELD = "smartHomeDevice";
49 private final TPLinkSmartHomeHandlerFactory factory = new TPLinkSmartHomeHandlerFactory();
52 private static final List<Object[]> TESTS = Arrays.asList(new Object[][] {
53 { "hs100", SwitchDevice.class },
54 { "hs110", EnergySwitchDevice.class },
55 { "hs200", SwitchDevice.class },
56 { "hs220", DimmerDevice.class },
57 { "hs300", PowerStripDevice.class },
58 { "lb100", BulbDevice.class },
59 { "lb120", BulbDevice.class },
60 { "lb130", BulbDevice.class },
61 { "lb230", BulbDevice.class },
62 { "kl110", BulbDevice.class },
63 { "kl120", BulbDevice.class },
64 { "kl130", BulbDevice.class },
65 { "re270", RangeExtenderDevice.class },
73 private final String name;
74 private final Class<?> clazz;
76 public TPLinkSmartHomeHandlerFactoryTest(String name, Class<?> clazz) {
81 @Parameters(name = "{0} - {1}")
82 public static List<Object[]> data() {
92 public void testCorrectClass()
93 throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
94 when(thing.getThingTypeUID()).thenReturn(new ThingTypeUID(TPLinkSmartHomeBindingConstants.BINDING_ID, name));
95 SmartHomeHandler handler = (SmartHomeHandler) factory.createHandler(thing);
98 assertNull(name + " should not return any handler but null", handler);
100 assertNotNull(name + " should no return null handler", handler);
101 Field smartHomeDeviceField = SmartHomeHandler.class.getDeclaredField(SMART_HOME_DEVICE_FIELD);
103 smartHomeDeviceField.setAccessible(true);
104 assertSame(name + " should return expected device class", clazz,
105 smartHomeDeviceField.get(handler).getClass());