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