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