]> git.basschouten.com Git - openhab-addons.git/blob
5e3d1a2bb9790b0f12302fbf469d432522d3e3ca
[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.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.test.java.JavaOSGiTest;
19 import org.openhab.core.thing.Thing;
20 import org.openhab.core.thing.binding.ThingHandler;
21
22 /**
23  * @author Markus Rathgeb - Initial contribution
24  * @author Markus Rathgeb - migrated to plain Java test
25  */
26 @NonNullByDefault
27 public class AbstractHueOSGiTestParent extends JavaOSGiTest {
28
29     /**
30      * Gets the handler of a thing if it fits to a specific type.
31      *
32      * @param thing the thing
33      * @param clazz type of thing handler
34      * @param <T> a ThingHandler or subtype
35      * @return the thing handler
36      */
37     protected <T extends ThingHandler> T getThingHandler(Thing thing, Class<T> clazz) {
38         return waitForAssert(() -> {
39             final ThingHandler tmp = thing.getHandler();
40             if (clazz.isInstance(tmp)) {
41                 return clazz.cast(tmp);
42             } else {
43                 assertNotNull(tmp);
44                 assertEquals(clazz, tmp.getClass());
45                 throw new IllegalStateException();
46             }
47         });
48     }
49 }