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.tplinksmarthome.internal;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.when;
18 import java.lang.reflect.Field;
19 import java.util.Arrays;
20 import java.util.List;
22 import org.junit.jupiter.api.extension.ExtendWith;
23 import org.junit.jupiter.params.ParameterizedTest;
24 import org.junit.jupiter.params.provider.MethodSource;
25 import org.mockito.Mock;
26 import org.mockito.junit.jupiter.MockitoExtension;
27 import org.openhab.binding.tplinksmarthome.internal.device.BulbDevice;
28 import org.openhab.binding.tplinksmarthome.internal.device.DimmerDevice;
29 import org.openhab.binding.tplinksmarthome.internal.device.EnergySwitchDevice;
30 import org.openhab.binding.tplinksmarthome.internal.device.PowerStripDevice;
31 import org.openhab.binding.tplinksmarthome.internal.device.RangeExtenderDevice;
32 import org.openhab.binding.tplinksmarthome.internal.device.SwitchDevice;
33 import org.openhab.binding.tplinksmarthome.internal.handler.SmartHomeHandler;
34 import org.openhab.core.thing.Thing;
35 import org.openhab.core.thing.ThingTypeUID;
38 * Test class for {@link TPLinkSmartHomeHandlerFactory}.
40 * @author Hilbrand Bouwkamp - Initial contribution
42 @ExtendWith(MockitoExtension.class)
43 public class TPLinkSmartHomeHandlerFactoryTest {
45 private static final String SMART_HOME_DEVICE_FIELD = "smartHomeDevice";
47 private final TPLinkSmartHomeHandlerFactory factory = new TPLinkSmartHomeHandlerFactory();
50 private static final List<Object[]> TESTS = Arrays.asList(new Object[][] {
51 { "hs100", SwitchDevice.class },
52 { "hs110", EnergySwitchDevice.class },
53 { "hs200", SwitchDevice.class },
54 { "hs220", DimmerDevice.class },
55 { "hs300", PowerStripDevice.class },
56 { "lb100", BulbDevice.class },
57 { "lb120", BulbDevice.class },
58 { "lb130", BulbDevice.class },
59 { "lb230", BulbDevice.class },
60 { "kl110", BulbDevice.class },
61 { "kl120", BulbDevice.class },
62 { "kl130", BulbDevice.class },
63 { "re270", RangeExtenderDevice.class },
68 private @Mock Thing thing;
70 public static List<Object[]> data() {
76 public void testCorrectClass(String name, Class<?> clazz)
77 throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
78 when(thing.getThingTypeUID()).thenReturn(new ThingTypeUID(TPLinkSmartHomeBindingConstants.BINDING_ID, name));
79 SmartHomeHandler handler = (SmartHomeHandler) factory.createHandler(thing);
82 assertNull(handler, name + " should not return any handler but null");
84 assertNotNull(handler, name + " should no return null handler");
85 Field smartHomeDeviceField = SmartHomeHandler.class.getDeclaredField(SMART_HOME_DEVICE_FIELD);
87 smartHomeDeviceField.setAccessible(true);
88 assertSame(clazz, smartHomeDeviceField.get(handler).getClass(),
89 name + " should return expected device class");