]> git.basschouten.com Git - openhab-addons.git/blob
50db2bdc5b6ca8d63b35c7adcdfd8d546aa33fd0
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.mybmw.internal.handler;
14
15 import static org.mockito.Mockito.*;
16
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.junit.jupiter.api.Test;
22 import org.mockito.ArgumentCaptor;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingUID;
26 import org.openhab.core.thing.binding.ThingHandlerCallback;
27 import org.openhab.core.types.State;
28
29 /**
30  * The {@link ErrorResponseTest} is responsible for handling commands, which are
31  * sent to one of the channels.
32  *
33  * @author Bernd Weymann - Initial contribution
34  */
35 @NonNullByDefault
36 @SuppressWarnings("null")
37 public class ErrorResponseTest {
38     @Nullable
39     ArgumentCaptor<ChannelUID> channelCaptor;
40     @Nullable
41     ArgumentCaptor<State> stateCaptor;
42     @Nullable
43     ThingHandlerCallback tc;
44     @Nullable
45     VehicleHandler cch;
46     @Nullable
47     List<ChannelUID> allChannels;
48     @Nullable
49     List<State> allStates;
50     @Nullable
51     String driveTrain;
52     boolean imperial;
53
54     /**
55      * Prepare environment for Vehicle Status Updates
56      */
57     public void setup(String type, boolean imperial) {
58         driveTrain = type;
59         this.imperial = imperial;
60         Thing thing = mock(Thing.class);
61         when(thing.getUID()).thenReturn(new ThingUID("testbinding", "test"));
62         MyBMWCommandOptionProvider cop = mock(MyBMWCommandOptionProvider.class);
63         cch = new VehicleHandler(thing, cop, type);
64         tc = mock(ThingHandlerCallback.class);
65         cch.setCallback(tc);
66         channelCaptor = ArgumentCaptor.forClass(ChannelUID.class);
67         stateCaptor = ArgumentCaptor.forClass(State.class);
68     }
69
70     @Test
71     public void testErrorResponseCallbacks() {
72         String error = "{\"error\":true,\"reason\":\"offline\"}";
73         setup("BEV", false);
74         cch.vehicleStatusCallback.onResponse(error);
75     }
76 }