]> git.basschouten.com Git - openhab-addons.git/blob
5fb021f69af288084a85953e8d0c25d4dbeff967
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.foobot.internal.handler;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.nio.charset.StandardCharsets;
20 import java.util.List;
21
22 import org.junit.jupiter.api.Test;
23 import org.mockito.Mock;
24 import org.openhab.binding.foobot.internal.FoobotApiConnector;
25 import org.openhab.binding.foobot.internal.FoobotApiException;
26 import org.openhab.binding.foobot.internal.json.FoobotDevice;
27 import org.openhab.core.thing.Bridge;
28
29 /**
30  * Unit test for {@link FoobotAccountHandler}.
31  *
32  * @author Hilbrand Bouwkamp - Initial contribution
33  */
34 public class FoobotAccountHandlerTest {
35
36     private @Mock Bridge bridge;
37     private final FoobotApiConnector connector = new FoobotApiConnector() {
38         @Override
39         protected String request(String url, String apiKey) throws FoobotApiException {
40             try (InputStream stream = getClass().getResourceAsStream("../devices.json")) {
41                 return new String(stream.readAllBytes(), StandardCharsets.UTF_8);
42             } catch (IOException e) {
43                 throw new AssertionError(e.getMessage());
44             }
45         };
46     };
47     private final FoobotAccountHandler handler = new FoobotAccountHandler(bridge, connector);
48
49     @Test
50     public void testSensorDataToState() throws IOException, FoobotApiException {
51         final List<FoobotDevice> deviceList = handler.getDeviceList();
52
53         assertFalse(deviceList.isEmpty(), "Device list should not return empty");
54         assertEquals(deviceList.get(0).getUuid(), "1234567890ABCDEF");
55     }
56 }