]> git.basschouten.com Git - openhab-addons.git/blob
53d70691a459097c28a27065652373b08e29f9a7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.luftdateninfo.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
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.BeforeEach;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.luftdateninfo.internal.dto.SensorDataValue;
24 import org.openhab.binding.luftdateninfo.internal.handler.HTTPHandler;
25 import org.openhab.binding.luftdateninfo.internal.util.FileReader;
26
27 /**
28  * The {@link HTTPHandlerEvalTest} test all evaluations on SensorDataValues
29  *
30  * @author Bernd Weymann - Initial contribution
31  */
32 @NonNullByDefault
33 public class HTTPHandlerEvalTest {
34
35     private @Nullable List<SensorDataValue> conditions;
36     private @Nullable List<SensorDataValue> particulate;
37     private @Nullable List<SensorDataValue> noise;
38     private HTTPHandler http = new HTTPHandler();
39
40     @BeforeEach
41     public void setUp() {
42         String conditionsStr = FileReader.readFileInString("src/test/resources/condition-result-no-pressure.json");
43         assertNotNull(conditionsStr);
44         conditions = http.getLatestValues(conditionsStr);
45
46         String particulateStr = FileReader.readFileInString("src/test/resources/pm-result.json");
47         assertNotNull(particulateStr);
48         particulate = http.getLatestValues(particulateStr);
49
50         String noiseStr = FileReader.readFileInString("src/test/resources/noise-result.json");
51         assertNotNull(noiseStr);
52         noise = http.getLatestValues(noiseStr);
53     }
54
55     @Test
56     public void testIsCondition() {
57         assertTrue(http.isCondition(conditions));
58         assertFalse(http.isCondition(particulate));
59         assertFalse(http.isCondition(noise));
60         assertFalse(http.isCondition(null));
61     }
62
63     @Test
64     public void testIsParticulate() {
65         assertFalse(http.isParticulate(conditions));
66         assertTrue(http.isParticulate(particulate));
67         assertFalse(http.isParticulate(noise));
68         assertFalse(http.isParticulate(null));
69     }
70
71     @Test
72     public void testIsNoise() {
73         assertFalse(http.isNoise(conditions));
74         assertFalse(http.isNoise(particulate));
75         assertTrue(http.isNoise(noise));
76         assertFalse(http.isNoise(null));
77     }
78 }