]> git.basschouten.com Git - openhab-addons.git/blob
11f371bd7f56d0d8d297bc559869f0441e4ad0e6
[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.enigma2.internal;
14
15 import static org.eclipse.jdt.annotation.Checks.requireNonNull;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.hamcrest.Matchers.*;
18 import static org.mockito.Mockito.*;
19 import static org.openhab.binding.enigma2.internal.Enigma2BindingConstants.THING_TYPE_DEVICE;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.junit.jupiter.api.Test;
24 import org.openhab.core.config.core.Configuration;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingTypeUID;
27
28 /**
29  * The {@link Enigma2HandlerFactoryTest} class is responsible for testing {@link Enigma2HandlerFactory}.
30  *
31  * @author Guido Dolfen - Initial contribution
32  */
33 @SuppressWarnings("null")
34 @NonNullByDefault
35 public class Enigma2HandlerFactoryTest {
36     @Nullable
37     private Thing thing;
38     @Nullable
39     private Configuration configuration;
40
41     @Test
42     public void testSupportsThingType() {
43         assertThat(new Enigma2HandlerFactory().supportsThingType(Enigma2BindingConstants.THING_TYPE_DEVICE), is(true));
44     }
45
46     @Test
47     public void testSupportsThingTypeFalse() {
48         assertThat(new Enigma2HandlerFactory().supportsThingType(new ThingTypeUID("any", "device")), is(false));
49     }
50
51     @Test
52     public void testCreateHandlerNull() {
53         thing = mock(Thing.class);
54         assertThat(new Enigma2HandlerFactory().createHandler(requireNonNull(thing)), is(nullValue()));
55     }
56
57     @Test
58     public void testCreateHandler() {
59         thing = mock(Thing.class);
60         configuration = mock(Configuration.class);
61         when(thing.getConfiguration()).thenReturn(requireNonNull(configuration));
62         when(configuration.as(Enigma2Configuration.class)).thenReturn(new Enigma2Configuration());
63         when(thing.getThingTypeUID()).thenReturn(THING_TYPE_DEVICE);
64         assertThat(new Enigma2HandlerFactory().createHandler(requireNonNull(thing)), is(notNullValue()));
65     }
66 }