]> git.basschouten.com Git - openhab-addons.git/blob
2510bfdc9ba7f2db78eb8a5ee6bb9685c3b42dd9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.hue.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.openhab.core.test.java.JavaOSGiTest;
18 import org.openhab.core.thing.Thing;
19 import org.openhab.core.thing.binding.ThingHandler;
20
21 /**
22  * @author Markus Rathgeb - migrated to plain Java test
23  */
24 public class AbstractHueOSGiTestParent extends JavaOSGiTest {
25
26     /**
27      * Gets the handler of a thing if it fits to a specific type.
28      *
29      * @param thing the thing
30      * @param clazz type of thing handler
31      * @return the thing handler
32      */
33     protected <T extends ThingHandler> T getThingHandler(Thing thing, Class<T> clazz) {
34         return waitForAssert(() -> {
35             final ThingHandler tmp = thing.getHandler();
36             if (clazz.isInstance(tmp)) {
37                 return clazz.cast(tmp);
38             } else {
39                 assertNotNull(tmp);
40                 assertEquals(clazz, tmp.getClass());
41                 throw new RuntimeException();
42             }
43         });
44     }
45 }