2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mercedesme.internal.handler;
15 import static org.mockito.Mockito.mock;
17 import java.util.Locale;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.eclipse.jetty.client.HttpClient;
22 import org.eclipse.jetty.websocket.api.Session;
23 import org.json.JSONObject;
24 import org.openhab.binding.mercedesme.internal.Constants;
25 import org.openhab.binding.mercedesme.internal.config.AccountConfiguration;
26 import org.openhab.binding.mercedesme.internal.discovery.MercedesMeDiscoveryService;
27 import org.openhab.core.i18n.LocaleProvider;
28 import org.openhab.core.net.NetworkAddressService;
29 import org.openhab.core.storage.Storage;
30 import org.openhab.core.storage.StorageService;
31 import org.openhab.core.test.storage.VolatileStorageService;
32 import org.openhab.core.thing.Bridge;
34 import com.daimler.mbcarkit.proto.Client.ClientMessage;
37 * {@link AccountHandlerMock} to retrieve and collect commands from {@link VehicleHandler}
39 * @author Bernd Weymann - Initial contribution
42 public class AccountHandlerMock extends AccountHandler {
43 private static VolatileStorageService storageService = new VolatileStorageService();
44 private static LocaleProvider localeProvider = new LocaleProvider() {
47 public Locale getLocale() {
48 return Locale.getDefault();
52 JSONObject command = new JSONObject();
54 public AccountHandlerMock() {
55 super(mock(Bridge.class), mock(MercedesMeDiscoveryService.class), mock(HttpClient.class),
56 mock(LocaleProvider.class), mock(StorageService.class), mock(NetworkAddressService.class));
59 public AccountHandlerMock(Bridge b, @Nullable String storedObject) {
60 super(b, mock(MercedesMeDiscoveryService.class), mock(HttpClient.class), localeProvider, storageService,
61 mock(NetworkAddressService.class));
62 if (storedObject != null) {
63 Storage<String> storage = storageService.getStorage(Constants.BINDING_ID);
64 storage.put("a@b.c", storedObject);
69 public void registerVin(String vin, VehicleHandler handler) {
73 public void getVehicleCapabilities(String vin) {
77 public void sendCommand(@Nullable ClientMessage cm) {
79 command = ProtoConverter.clientMessage2Json(cm);
83 public AccountConfiguration getConfigT() {
84 return new AccountConfiguration();
87 public JSONObject getCommand() {
91 public void connect() {
92 super.ws.onConnect(mock(Session.class));