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.boschshc.internal.devices;
15 import static org.mockito.ArgumentMatchers.argThat;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.verify;
18 import static org.mockito.Mockito.when;
20 import java.util.concurrent.ExecutionException;
21 import java.util.concurrent.TimeoutException;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.junit.jupiter.api.Test;
25 import org.junit.jupiter.params.ParameterizedTest;
26 import org.junit.jupiter.params.provider.MethodSource;
27 import org.openhab.binding.boschshc.internal.devices.bridge.dto.Device;
28 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
29 import org.openhab.core.config.core.Configuration;
30 import org.openhab.core.thing.ThingStatus;
31 import org.openhab.core.thing.ThingStatusDetail;
34 * Abstract unit test implementation for device handlers.
36 * @author David Pace - Initial contribution
38 * @param <T> type of the device handler to be tested
41 public abstract class AbstractBoschSHCDeviceHandlerTest<T extends BoschSHCDeviceHandler>
42 extends AbstractBoschSHCHandlerTest<T> {
45 protected void configureDevice(Device device) {
46 super.configureDevice(device);
48 device.id = getDeviceID();
52 protected Configuration getConfiguration() {
53 Configuration configuration = super.getConfiguration();
54 configuration.put("id", getDeviceID());
58 protected abstract String getDeviceID();
61 void initializeInvalidDeviceId() {
62 getFixture().getThing().getConfiguration().remove("id");
63 getFixture().initialize();
65 verify(getCallback()).statusUpdated(eq(getThing()),
66 argThat(status -> status.getStatus().equals(ThingStatus.OFFLINE)
67 && status.getStatusDetail().equals(ThingStatusDetail.CONFIGURATION_ERROR)));
71 @MethodSource("org.openhab.binding.boschshc.internal.tests.common.CommonTestUtils#getExecutionExceptionAndInterruptedExceptionArguments()")
72 void initializeHandleExceptionDuringDeviceInfoRestCall(Exception exception)
73 throws BoschSHCException, InterruptedException, TimeoutException, ExecutionException {
74 when(getBridgeHandler().getDeviceInfo(getDeviceID())).thenThrow(exception);
76 getFixture().initialize();
78 verify(getCallback()).statusUpdated(eq(getThing()),
79 argThat(status -> status.getStatus().equals(ThingStatus.OFFLINE)
80 && status.getStatusDetail().equals(ThingStatusDetail.CONFIGURATION_ERROR)));