This repository has been archived by the owner on May 7, 2020. It is now read-only.
/
EDSSensorThingHandlerTest.java
103 lines (85 loc) · 4.31 KB
/
EDSSensorThingHandlerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Copyright (c) 2014,2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.smarthome.binding.onewire.internal;
import static org.eclipse.smarthome.binding.onewire.internal.OwBindingConstants.*;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.times;
import org.eclipse.smarthome.binding.onewire.internal.OwException;
import org.eclipse.smarthome.binding.onewire.internal.OwPageBuffer;
import org.eclipse.smarthome.binding.onewire.internal.SensorId;
import org.eclipse.smarthome.binding.onewire.internal.handler.EDSSensorThingHandler;
import org.eclipse.smarthome.binding.onewire.test.AbstractThingHandlerTest;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.eclipse.smarthome.core.thing.binding.builder.ChannelBuilder;
import org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
/**
* Tests cases for {@link EDSSensorThingHandler}.
*
* @author Jan N. Klug - Initial contribution
*/
public class EDSSensorThingHandlerTest extends AbstractThingHandlerTest {
private static final String TEST_ID = "00.000000000000";
private static final ThingUID THING_UID = new ThingUID(THING_TYPE_EDS_ENV, "testthing");
private static final ChannelUID CHANNEL_UID_TEMPERATURE = new ChannelUID(THING_UID, CHANNEL_TEMPERATURE);
private static final ChannelUID CHANNEL_UID_HUMIDITY = new ChannelUID(THING_UID, CHANNEL_HUMIDITY);
private static final ChannelUID CHANNEL_UID_ABSOLUTE_HUMIDITY = new ChannelUID(THING_UID,
CHANNEL_ABSOLUTE_HUMIDITY);
private static final ChannelUID CHANNEL_UID_DEWPOINT = new ChannelUID(THING_UID, CHANNEL_DEWPOINT);
@Before
public void setup() throws OwException {
MockitoAnnotations.initMocks(this);
initializeBridge();
thingConfiguration.put(CONFIG_ID, TEST_ID);
channels.add(ChannelBuilder.create(CHANNEL_UID_TEMPERATURE, "Number:Temperature").build());
channels.add(ChannelBuilder.create(CHANNEL_UID_HUMIDITY, "Number:Dimensionless").build());
channels.add(ChannelBuilder.create(CHANNEL_UID_ABSOLUTE_HUMIDITY, "Number:Density").build());
channels.add(ChannelBuilder.create(CHANNEL_UID_DEWPOINT, "Number:Temperature").build());
thing = ThingBuilder.create(THING_TYPE_EDS_ENV, "testthing").withLabel("Test thing").withChannels(channels)
.withConfiguration(new Configuration(thingConfiguration)).withProperties(thingProperties)
.withBridge(bridge.getUID()).build();
thingHandler = new EDSSensorThingHandler(thing, stateProvider) {
@Override
protected Bridge getBridge() {
return bridge;
}
};
initializeHandlerMocks();
Mockito.doAnswer(answer -> {
return new OwPageBuffer("EDS0065 ".getBytes());
}).when(secondBridgeHandler).readPages(any());
}
@Test
public void testInitializationEndsWithUnknown() {
thingHandler.initialize();
waitForAssert(() -> assertEquals(ThingStatus.UNKNOWN, thingHandler.getThing().getStatusInfo().getStatus()));
}
@Test
public void testRefresh() throws OwException {
thingHandler.initialize();
// needed to determine initialization is finished
waitForAssert(() -> assertEquals(ThingStatus.UNKNOWN, thingHandler.getThing().getStatusInfo().getStatus()));
thingHandler.refresh(bridgeHandler, System.currentTimeMillis());
inOrder.verify(bridgeHandler, times(1)).checkPresence(new SensorId(TEST_ID));
inOrder.verify(bridgeHandler, times(2)).readDecimalType(eq(new SensorId(TEST_ID)), any());
inOrder.verifyNoMoreInteractions();
}
}