Migrate tests to JUnit 5 (#8519)
Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -12,18 +12,27 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.onewire.internal.OwBindingConstants;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
import org.openhab.binding.onewire.internal.device.OwSensorType;
|
||||
import org.openhab.binding.onewire.internal.handler.*;
|
||||
import org.openhab.binding.onewire.internal.handler.AdvancedMultisensorThingHandler;
|
||||
import org.openhab.binding.onewire.internal.handler.BAE091xSensorThingHandler;
|
||||
import org.openhab.binding.onewire.internal.handler.BasicMultisensorThingHandler;
|
||||
import org.openhab.binding.onewire.internal.handler.BasicThingHandler;
|
||||
import org.openhab.binding.onewire.internal.handler.EDSSensorThingHandler;
|
||||
|
||||
/**
|
||||
* Tests cases for binding completeness
|
||||
@@ -48,7 +57,7 @@ public class CompletenessTest {
|
||||
for (OwSensorType sensorType : EnumSet.allOf(OwSensorType.class)) {
|
||||
if (!OwBindingConstants.THING_TYPE_MAP.containsKey(sensorType)
|
||||
&& !IGNORED_SENSOR_TYPES.contains(sensorType)) {
|
||||
Assert.fail("missing thing type map for sensor type " + sensorType.name());
|
||||
fail("missing thing type map for sensor type " + sensorType.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,7 +67,7 @@ public class CompletenessTest {
|
||||
for (OwSensorType sensorType : EnumSet.allOf(OwSensorType.class)) {
|
||||
if (!OwBindingConstants.SENSOR_TYPE_CHANNEL_MAP.containsKey(sensorType)
|
||||
&& !IGNORED_SENSOR_TYPES.contains(sensorType)) {
|
||||
Assert.fail("missing channel configuration map for sensor type " + sensorType.name());
|
||||
fail("missing channel configuration map for sensor type " + sensorType.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +76,7 @@ public class CompletenessTest {
|
||||
public void allSensorsSupportedByThingHandlers() {
|
||||
for (OwSensorType sensorType : EnumSet.allOf(OwSensorType.class)) {
|
||||
if (!THINGHANDLER_SENSOR_TYPES.contains(sensorType) && !IGNORED_SENSOR_TYPES.contains(sensorType)) {
|
||||
Assert.fail("missing thing handler for sensor type " + sensorType.name());
|
||||
fail("missing thing handler for sensor type " + sensorType.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,7 +86,7 @@ public class CompletenessTest {
|
||||
for (OwSensorType sensorType : EnumSet.allOf(OwSensorType.class)) {
|
||||
if (!OwBindingConstants.THING_LABEL_MAP.containsKey(sensorType)
|
||||
&& !IGNORED_SENSOR_TYPES.contains(sensorType)) {
|
||||
Assert.fail("missing label for sensor type " + sensorType.name());
|
||||
fail("missing label for sensor type " + sensorType.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,14 +99,14 @@ public class CompletenessTest {
|
||||
try {
|
||||
return (String) f.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
Assert.fail("unexpected");
|
||||
fail("unexpected");
|
||||
return null;
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
for (String channel : channels) {
|
||||
if (!OwBindingConstants.ACCEPTED_ITEM_TYPES_MAP.containsKey(channel)) {
|
||||
Assert.fail("missing accepted item type for channel " + channel);
|
||||
fail("missing accepted item type for channel " + channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.onewire.internal.SensorId;
|
||||
import org.openhab.binding.onewire.internal.owserver.OwserverDeviceParameter;
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.onewire.internal.SensorId;
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import javax.measure.quantity.Dimensionless;
|
||||
import javax.measure.quantity.Temperature;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.onewire.internal.Util;
|
||||
import org.openhab.core.library.dimension.Density;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
|
||||
@@ -12,16 +12,18 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire.device;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
@@ -42,7 +44,7 @@ import org.openhab.core.types.State;
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BAE0910Test extends DeviceTestParent<BAE0910> {
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMocks() {
|
||||
setupMocks(THING_TYPE_BAE091X, BAE0910.class);
|
||||
}
|
||||
@@ -50,54 +52,49 @@ public class BAE0910Test extends DeviceTestParent<BAE0910> {
|
||||
// pin 1: counter
|
||||
|
||||
@Test
|
||||
public void counter() {
|
||||
public void counter() throws OwException {
|
||||
addChannel(CHANNEL_COUNTER, "Number");
|
||||
final BAE0910 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(
|
||||
mockBridgeHandler.readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter("/counter"))))
|
||||
.thenReturn(new DecimalType(34567));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter("/counter"))))
|
||||
.thenReturn(new DecimalType(34567));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_COUNTER);
|
||||
testDevice.configureChannels(mockBridgeHandler);
|
||||
testDevice.enableChannel(CHANNEL_COUNTER);
|
||||
testDevice.configureChannels(mockBridgeHandler);
|
||||
|
||||
// refresh
|
||||
ArgumentCaptor<State> stateArgumentCaptor = ArgumentCaptor.forClass(State.class);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter("/counter")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_COUNTER), stateArgumentCaptor.capture());
|
||||
assertEquals(new DecimalType(34567), stateArgumentCaptor.getValue());
|
||||
// refresh
|
||||
ArgumentCaptor<State> stateArgumentCaptor = ArgumentCaptor.forClass(State.class);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter("/counter")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_COUNTER), stateArgumentCaptor.capture());
|
||||
assertEquals(new DecimalType(34567), stateArgumentCaptor.getValue());
|
||||
|
||||
// write
|
||||
assertFalse(testDevice.writeChannel(mockBridgeHandler, CHANNEL_COUNTER, new DecimalType(12345)));
|
||||
// write
|
||||
assertFalse(testDevice.writeChannel(mockBridgeHandler, CHANNEL_COUNTER, new DecimalType(12345)));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
// pin 2: digital2 or pwm1
|
||||
|
||||
@Test
|
||||
public void digitalOut2() {
|
||||
public void digitalOut2() throws OwException {
|
||||
addChannel(CHANNEL_DIGITAL2, "Switch");
|
||||
digitalBaseChannel(CHANNEL_DIGITAL2, bitSet(3, 4), 0, "/out", bitSet(0), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pwm4() {
|
||||
public void pwm4() throws OwException {
|
||||
pwmBaseChannel(CHANNEL_PWM_FREQ2, CHANNEL_PWM_DUTY4, "/period2", "/duty4", 2);
|
||||
}
|
||||
|
||||
// pin 6: pio or pwm 3
|
||||
|
||||
@Test
|
||||
public void digital6PioIn() {
|
||||
public void digital6PioIn() throws OwException {
|
||||
Map<String, Object> channelConfig = new HashMap<>();
|
||||
channelConfig.put("pulldevice", "pulldown");
|
||||
channelConfig.put("mode", "input");
|
||||
@@ -106,7 +103,7 @@ public class BAE0910Test extends DeviceTestParent<BAE0910> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void digital6PioOut() {
|
||||
public void digital6PioOut() throws OwException {
|
||||
Map<String, Object> channelConfig = new HashMap<>();
|
||||
channelConfig.put("mode", "output");
|
||||
addChannel(CHANNEL_DIGITAL6, "Switch", new Configuration(channelConfig));
|
||||
@@ -114,14 +111,14 @@ public class BAE0910Test extends DeviceTestParent<BAE0910> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pwm3() {
|
||||
public void pwm3() throws OwException {
|
||||
pwmBaseChannel(CHANNEL_PWM_FREQ1, CHANNEL_PWM_DUTY3, "/period1", "/duty3", 1);
|
||||
}
|
||||
|
||||
// pin 7: analog, output, pwm2
|
||||
|
||||
@Test
|
||||
public void analog() {
|
||||
public void analog() throws OwException {
|
||||
Map<String, Object> channelConfig = new HashMap<>();
|
||||
channelConfig.put("hires", "true");
|
||||
addChannel(CHANNEL_VOLTAGE, "Number:ElectricPotential", new Configuration(channelConfig));
|
||||
@@ -129,61 +126,56 @@ public class BAE0910Test extends DeviceTestParent<BAE0910> {
|
||||
final BAE0910 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter("/adc"))))
|
||||
.thenReturn(new DecimalType(5.2));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter("/adc"))))
|
||||
.thenReturn(new DecimalType(5.2));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_VOLTAGE);
|
||||
testDevice.configureChannels(mockBridgeHandler);
|
||||
testDevice.enableChannel(CHANNEL_VOLTAGE);
|
||||
testDevice.configureChannels(mockBridgeHandler);
|
||||
|
||||
// test configuration
|
||||
assertEquals(bitSet(3, 4), checkConfiguration(2));
|
||||
// test configuration
|
||||
assertEquals(bitSet(3, 4), checkConfiguration(2));
|
||||
|
||||
// refresh
|
||||
ArgumentCaptor<State> stateArgumentCaptor = ArgumentCaptor.forClass(State.class);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter("/adc")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_VOLTAGE), stateArgumentCaptor.capture());
|
||||
assertEquals(new QuantityType<>("5.2 V"), stateArgumentCaptor.getValue());
|
||||
// refresh
|
||||
ArgumentCaptor<State> stateArgumentCaptor = ArgumentCaptor.forClass(State.class);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter("/adc")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_VOLTAGE), stateArgumentCaptor.capture());
|
||||
assertEquals(new QuantityType<>("5.2 V"), stateArgumentCaptor.getValue());
|
||||
|
||||
// write (should fail)
|
||||
assertFalse(testDevice.writeChannel(mockBridgeHandler, CHANNEL_VOLTAGE, new QuantityType<>("3 V")));
|
||||
// write (should fail)
|
||||
assertFalse(testDevice.writeChannel(mockBridgeHandler, CHANNEL_VOLTAGE, new QuantityType<>("3 V")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void digitalOut7() {
|
||||
public void digitalOut7() throws OwException {
|
||||
addChannel(CHANNEL_DIGITAL7, "Switch");
|
||||
digitalBaseChannel(CHANNEL_DIGITAL7, bitSet(4), 4, "/tpm2c", bitSet(4, 7), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pwm2() {
|
||||
public void pwm2() throws OwException {
|
||||
pwmBaseChannel(CHANNEL_PWM_FREQ2, CHANNEL_PWM_DUTY2, "/period2", "/duty2", 2);
|
||||
}
|
||||
|
||||
// pin 8: digital in, digital out or pwm
|
||||
|
||||
@Test
|
||||
public void digitalIn8() {
|
||||
public void digitalIn8() throws OwException {
|
||||
addChannel(CHANNEL_DIGITAL8, "Switch", new ChannelTypeUID(BINDING_ID, "bae-in"));
|
||||
digitalBaseChannel(CHANNEL_DIGITAL8, bitSet(4, 5), 3, "/tpm1c", bitSet(4, 5, 7), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void digitalOut8() {
|
||||
public void digitalOut8() throws OwException {
|
||||
addChannel(CHANNEL_DIGITAL8, "Switch");
|
||||
digitalBaseChannel(CHANNEL_DIGITAL8, bitSet(4), 3, "/tpm1c", bitSet(4, 7), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pwm1() {
|
||||
public void pwm1() throws OwException {
|
||||
pwmBaseChannel(CHANNEL_PWM_FREQ1, CHANNEL_PWM_DUTY1, "/period1", "/duty1", 1);
|
||||
}
|
||||
|
||||
@@ -198,44 +190,39 @@ public class BAE0910Test extends DeviceTestParent<BAE0910> {
|
||||
* @param isOutput if this channel is an output
|
||||
*/
|
||||
private void digitalBaseChannel(String channel, BitSet configBitSet, int configRegister, String channelParam,
|
||||
BitSet returnBitSet, boolean isOutput) {
|
||||
BitSet returnBitSet, boolean isOutput) throws OwException {
|
||||
final BAE0910 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readBitSet(eq(testSensorId), eq(new OwserverDeviceParameter(channelParam))))
|
||||
.thenReturn(returnBitSet);
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readBitSet(eq(testSensorId), eq(new OwserverDeviceParameter(channelParam))))
|
||||
.thenReturn(returnBitSet);
|
||||
|
||||
testDevice.enableChannel(channel);
|
||||
testDevice.configureChannels(mockBridgeHandler);
|
||||
testDevice.enableChannel(channel);
|
||||
testDevice.configureChannels(mockBridgeHandler);
|
||||
|
||||
// test configuration
|
||||
assertEquals(configBitSet, checkConfiguration(configRegister));
|
||||
// test configuration
|
||||
assertEquals(configBitSet, checkConfiguration(configRegister));
|
||||
|
||||
// refresh
|
||||
ArgumentCaptor<State> stateArgumentCaptor = ArgumentCaptor.forClass(State.class);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
inOrder.verify(mockBridgeHandler).readBitSet(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter(channelParam)));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(channel), stateArgumentCaptor.capture());
|
||||
assertEquals(OnOffType.ON, stateArgumentCaptor.getValue());
|
||||
// refresh
|
||||
ArgumentCaptor<State> stateArgumentCaptor = ArgumentCaptor.forClass(State.class);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
inOrder.verify(mockBridgeHandler).readBitSet(eq(testSensorId), eq(new OwserverDeviceParameter(channelParam)));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(channel), stateArgumentCaptor.capture());
|
||||
assertEquals(OnOffType.ON, stateArgumentCaptor.getValue());
|
||||
|
||||
// write
|
||||
if (isOutput) {
|
||||
ArgumentCaptor<BitSet> bitSetArgumentCaptor = ArgumentCaptor.forClass(BitSet.class);
|
||||
assertTrue(testDevice.writeChannel(mockBridgeHandler, channel, OnOffType.ON));
|
||||
inOrder.verify(mockBridgeHandler).writeBitSet(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter(channelParam)), bitSetArgumentCaptor.capture());
|
||||
assertEquals(returnBitSet, bitSetArgumentCaptor.getValue());
|
||||
} else {
|
||||
assertFalse(testDevice.writeChannel(mockBridgeHandler, channel, OnOffType.ON));
|
||||
}
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
// write
|
||||
if (isOutput) {
|
||||
ArgumentCaptor<BitSet> bitSetArgumentCaptor = ArgumentCaptor.forClass(BitSet.class);
|
||||
assertTrue(testDevice.writeChannel(mockBridgeHandler, channel, OnOffType.ON));
|
||||
inOrder.verify(mockBridgeHandler).writeBitSet(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter(channelParam)), bitSetArgumentCaptor.capture());
|
||||
assertEquals(returnBitSet, bitSetArgumentCaptor.getValue());
|
||||
} else {
|
||||
assertFalse(testDevice.writeChannel(mockBridgeHandler, channel, OnOffType.ON));
|
||||
}
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,7 +235,7 @@ public class BAE0910Test extends DeviceTestParent<BAE0910> {
|
||||
* @param registerIndex index for TPM configuration register
|
||||
*/
|
||||
private void pwmBaseChannel(String freqChannel, String dutyChannel, String freqParam, String dutyParam,
|
||||
int registerIndex) {
|
||||
int registerIndex) throws OwException {
|
||||
Map<String, Object> channelConfig = new HashMap<>();
|
||||
channelConfig.put("prescaler", 5);
|
||||
addChannel(freqChannel, "Number:Frequency", new Configuration(channelConfig));
|
||||
@@ -257,51 +244,42 @@ public class BAE0910Test extends DeviceTestParent<BAE0910> {
|
||||
final BAE0910 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(
|
||||
mockBridgeHandler.readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter(freqParam))))
|
||||
.thenReturn(new DecimalType(32768));
|
||||
Mockito.when(
|
||||
mockBridgeHandler.readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter(dutyParam))))
|
||||
.thenReturn(new DecimalType(16384));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter(freqParam))))
|
||||
.thenReturn(new DecimalType(32768));
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter(dutyParam))))
|
||||
.thenReturn(new DecimalType(16384));
|
||||
|
||||
testDevice.enableChannel(freqChannel);
|
||||
testDevice.enableChannel(dutyChannel);
|
||||
testDevice.configureChannels(mockBridgeHandler);
|
||||
testDevice.enableChannel(freqChannel);
|
||||
testDevice.enableChannel(dutyChannel);
|
||||
testDevice.configureChannels(mockBridgeHandler);
|
||||
|
||||
// test configuration
|
||||
assertEquals(bitSet(0, 2), checkConfiguration(registerIndex + 2));
|
||||
// test configuration
|
||||
assertEquals(bitSet(0, 2), checkConfiguration(registerIndex + 2));
|
||||
|
||||
// refresh
|
||||
ArgumentCaptor<State> stateArgumentCaptor = ArgumentCaptor.forClass(State.class);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter(freqParam)));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(freqChannel), stateArgumentCaptor.capture());
|
||||
assertEquals(new QuantityType<>("15.2587890625 Hz"), stateArgumentCaptor.getValue());
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter(dutyParam)));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(dutyChannel), stateArgumentCaptor.capture());
|
||||
assertEquals(new QuantityType<>("50 %"), stateArgumentCaptor.getValue());
|
||||
// refresh
|
||||
ArgumentCaptor<State> stateArgumentCaptor = ArgumentCaptor.forClass(State.class);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter(freqParam)));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(freqChannel), stateArgumentCaptor.capture());
|
||||
assertEquals(new QuantityType<>("15.2587890625 Hz"), stateArgumentCaptor.getValue());
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter(dutyParam)));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(dutyChannel), stateArgumentCaptor.capture());
|
||||
assertEquals(new QuantityType<>("50 %"), stateArgumentCaptor.getValue());
|
||||
|
||||
// write
|
||||
ArgumentCaptor<DecimalType> decimalTypeArgumentCaptor = ArgumentCaptor.forClass(DecimalType.class);
|
||||
assertTrue(testDevice.writeChannel(mockBridgeHandler, freqChannel, new QuantityType<>("50000 Hz")));
|
||||
inOrder.verify(mockBridgeHandler).writeDecimalType(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter(freqParam)), decimalTypeArgumentCaptor.capture());
|
||||
assertEquals(new DecimalType(10), decimalTypeArgumentCaptor.getValue());
|
||||
testDevice.writeChannel(mockBridgeHandler, dutyChannel, new QuantityType<>("25 %"));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter(freqParam)));
|
||||
inOrder.verify(mockBridgeHandler).writeDecimalType(eq(testSensorId),
|
||||
eq(new OwserverDeviceParameter(dutyParam)), decimalTypeArgumentCaptor.capture());
|
||||
assertEquals(new DecimalType(8192), decimalTypeArgumentCaptor.getValue());
|
||||
// write
|
||||
ArgumentCaptor<DecimalType> decimalTypeArgumentCaptor = ArgumentCaptor.forClass(DecimalType.class);
|
||||
assertTrue(testDevice.writeChannel(mockBridgeHandler, freqChannel, new QuantityType<>("50000 Hz")));
|
||||
inOrder.verify(mockBridgeHandler).writeDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter(freqParam)),
|
||||
decimalTypeArgumentCaptor.capture());
|
||||
assertEquals(new DecimalType(10), decimalTypeArgumentCaptor.getValue());
|
||||
testDevice.writeChannel(mockBridgeHandler, dutyChannel, new QuantityType<>("25 %"));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter(freqParam)));
|
||||
inOrder.verify(mockBridgeHandler).writeDecimalType(eq(testSensorId), eq(new OwserverDeviceParameter(dutyParam)),
|
||||
decimalTypeArgumentCaptor.capture());
|
||||
assertEquals(new DecimalType(8192), decimalTypeArgumentCaptor.getValue());
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,8 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire.device;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
|
||||
@@ -21,9 +20,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
@@ -41,7 +39,7 @@ import org.openhab.core.library.types.QuantityType;
|
||||
@NonNullByDefault
|
||||
public class DS18x20Test extends DeviceTestParent<DS18x20> {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMocks() {
|
||||
setupMocks(THING_TYPE_BASIC, DS18x20.class);
|
||||
|
||||
@@ -51,42 +49,34 @@ public class DS18x20Test extends DeviceTestParent<DS18x20> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void temperatureTest() {
|
||||
public void temperatureTest() throws OwException {
|
||||
final DS18x20 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(15.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(15.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_TEMPERATURE);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_TEMPERATURE);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler, times(1)).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("15.0 °C")));
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verify(mockBridgeHandler, times(1)).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("15.0 °C")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void temperatureIgnorePORTest() {
|
||||
public void temperatureIgnorePORTest() throws OwException {
|
||||
final DS18x20 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(85.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(85.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_TEMPERATURE);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_TEMPERATURE);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler, times(1)).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler, times(0)).postUpdate(eq(CHANNEL_TEMPERATURE), any());
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verify(mockBridgeHandler, times(1)).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler, times(0)).postUpdate(eq(CHANNEL_TEMPERATURE), any());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,8 @@ import static org.mockito.Mockito.times;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
@@ -36,7 +35,7 @@ import org.openhab.core.library.types.QuantityType;
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DS1923Test extends DeviceTestParent<DS1923> {
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMocks() {
|
||||
setupMocks(THING_TYPE_MS_TX, DS1923.class);
|
||||
|
||||
@@ -47,52 +46,44 @@ public class DS1923Test extends DeviceTestParent<DS1923> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void temperatureChannel() {
|
||||
public void temperatureChannel() throws OwException {
|
||||
final DS1923 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_TEMPERATURE);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_TEMPERATURE);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("10.0 °C")));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("10.0 °C")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void humidityChannel() {
|
||||
public void humidityChannel() throws OwException {
|
||||
final DS1923 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_ABSOLUTE_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_DEWPOINT);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_ABSOLUTE_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_DEWPOINT);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_HUMIDITY), eq(new QuantityType<>("10.0 %")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_ABSOLUTE_HUMIDITY),
|
||||
eq(new QuantityType<>("0.9381970824113001000 g/m³")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_DEWPOINT),
|
||||
eq(new QuantityType<>("-20.31395053870025 °C")));
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_HUMIDITY), eq(new QuantityType<>("10.0 %")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_ABSOLUTE_HUMIDITY),
|
||||
eq(new QuantityType<>("0.9381970824113001000 g/m³")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_DEWPOINT),
|
||||
eq(new QuantityType<>("-20.31395053870025 °C")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@ package org.openhab.binding.onewire.device;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.THING_TYPE_BASIC;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
import org.openhab.binding.onewire.internal.device.DS2401;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
|
||||
@@ -28,18 +29,18 @@ import org.openhab.core.library.types.OnOffType;
|
||||
@NonNullByDefault
|
||||
public class DS2401Test extends DeviceTestParent<DS2401> {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMocks() {
|
||||
setupMocks(THING_TYPE_BASIC, DS2401.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void presenceTestOn() {
|
||||
public void presenceTestOn() throws OwException {
|
||||
presenceTest(OnOffType.ON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void presenceTestOff() {
|
||||
public void presenceTestOff() throws OwException {
|
||||
presenceTest(OnOffType.OFF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,8 @@ import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
import java.util.BitSet;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
@@ -36,7 +35,7 @@ import org.openhab.core.library.types.OnOffType;
|
||||
@NonNullByDefault
|
||||
public class DS2405Test extends DeviceTestParent<DS2405> {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMocks() {
|
||||
setupMocks(THING_TYPE_BASIC, DS2405.class);
|
||||
|
||||
@@ -44,12 +43,12 @@ public class DS2405Test extends DeviceTestParent<DS2405> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void digitalChannel() {
|
||||
public void digitalChannel() throws OwException {
|
||||
digitalChannelTest(OnOffType.ON, 0);
|
||||
digitalChannelTest(OnOffType.OFF, 0);
|
||||
}
|
||||
|
||||
private void digitalChannelTest(OnOffType state, int channelNo) {
|
||||
private void digitalChannelTest(OnOffType state, int channelNo) throws OwException {
|
||||
final DS2405 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
@@ -58,18 +57,14 @@ public class DS2405Test extends DeviceTestParent<DS2405> {
|
||||
returnValue.flip(0, 7);
|
||||
}
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readBitSet(eq(testSensorId), any())).thenReturn(returnValue);
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readBitSet(eq(testSensorId), any())).thenReturn(returnValue);
|
||||
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readBitSet(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(channelName(channelNo)), eq(state));
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readBitSet(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(channelName(channelNo)), eq(state));
|
||||
}
|
||||
|
||||
private String channelName(int channelNo) {
|
||||
|
||||
@@ -19,9 +19,8 @@ import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
import java.util.BitSet;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
@@ -36,7 +35,7 @@ import org.openhab.core.library.types.OnOffType;
|
||||
@NonNullByDefault
|
||||
public class DS2406_DS2413Test extends DeviceTestParent<DS2406_DS2413> {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMocks() {
|
||||
setupMocks(THING_TYPE_BASIC, DS2406_DS2413.class);
|
||||
|
||||
@@ -46,14 +45,14 @@ public class DS2406_DS2413Test extends DeviceTestParent<DS2406_DS2413> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void digitalChannel() {
|
||||
public void digitalChannel() throws OwException {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
digitalChannelTest(OnOffType.ON, i);
|
||||
digitalChannelTest(OnOffType.OFF, i);
|
||||
}
|
||||
}
|
||||
|
||||
private void digitalChannelTest(OnOffType state, int channelNo) {
|
||||
private void digitalChannelTest(OnOffType state, int channelNo) throws OwException {
|
||||
final DS2406_DS2413 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
@@ -62,18 +61,14 @@ public class DS2406_DS2413Test extends DeviceTestParent<DS2406_DS2413> {
|
||||
returnValue.flip(0, 7);
|
||||
}
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readBitSet(eq(testSensorId), any())).thenReturn(returnValue);
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readBitSet(eq(testSensorId), any())).thenReturn(returnValue);
|
||||
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readBitSet(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(channelName(channelNo)), eq(state));
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readBitSet(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(channelName(channelNo)), eq(state));
|
||||
}
|
||||
|
||||
private String channelName(int channelNo) {
|
||||
|
||||
@@ -19,9 +19,8 @@ import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
import java.util.BitSet;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
@@ -36,7 +35,7 @@ import org.openhab.core.library.types.OnOffType;
|
||||
@NonNullByDefault
|
||||
public class DS2408Test extends DeviceTestParent<DS2408> {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMocks() {
|
||||
setupMocks(THING_TYPE_BASIC, DS2408.class);
|
||||
|
||||
@@ -46,14 +45,14 @@ public class DS2408Test extends DeviceTestParent<DS2408> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void digitalChannel() {
|
||||
public void digitalChannel() throws OwException {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
digitalChannelTest(OnOffType.ON, i);
|
||||
digitalChannelTest(OnOffType.OFF, i);
|
||||
}
|
||||
}
|
||||
|
||||
private void digitalChannelTest(OnOffType state, int channelNo) {
|
||||
private void digitalChannelTest(OnOffType state, int channelNo) throws OwException {
|
||||
final DS2408 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
@@ -62,18 +61,14 @@ public class DS2408Test extends DeviceTestParent<DS2408> {
|
||||
returnValue.flip(0, 8);
|
||||
}
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readBitSet(eq(testSensorId), any())).thenReturn(returnValue);
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readBitSet(eq(testSensorId), any())).thenReturn(returnValue);
|
||||
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readBitSet(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(channelName(channelNo)), eq(state));
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readBitSet(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(channelName(channelNo)), eq(state));
|
||||
}
|
||||
|
||||
private String channelName(int channelNo) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire.device;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
@@ -20,9 +21,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
@@ -39,7 +39,7 @@ import org.openhab.core.types.State;
|
||||
@NonNullByDefault
|
||||
public class DS2423Test extends DeviceTestParent<DS2423> {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMocks() {
|
||||
setupMocks(THING_TYPE_BASIC, DS2423.class);
|
||||
|
||||
@@ -68,7 +68,7 @@ public class DS2423Test extends DeviceTestParent<DS2423> {
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(channelName(0)), eq(returnValue.get(0)));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(channelName(1)), eq(returnValue.get(1)));
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
fail("caught unexpected OwException");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,8 @@ import static org.mockito.Mockito.times;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
@@ -37,7 +36,7 @@ import org.openhab.core.library.types.QuantityType;
|
||||
@NonNullByDefault
|
||||
public class DS2438Test extends DeviceTestParent<DS2438> {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMocks() {
|
||||
setupMocks(THING_TYPE_MS_TX, DS2438.class);
|
||||
|
||||
@@ -52,173 +51,145 @@ public class DS2438Test extends DeviceTestParent<DS2438> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void temperatureChannel() {
|
||||
public void temperatureChannel() throws OwException {
|
||||
final DS2438 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_TEMPERATURE);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_TEMPERATURE);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("10.0 °C")));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("10.0 °C")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void humidityChannel() {
|
||||
public void humidityChannel() throws OwException {
|
||||
final DS2438 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_ABSOLUTE_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_DEWPOINT);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_ABSOLUTE_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_DEWPOINT);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_HUMIDITY), eq(new QuantityType<>("10.0 %")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_ABSOLUTE_HUMIDITY),
|
||||
eq(new QuantityType<>("0.9381970824113001000 g/m³")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_DEWPOINT),
|
||||
eq(new QuantityType<>("-20.31395053870025 °C")));
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_HUMIDITY), eq(new QuantityType<>("10.0 %")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_ABSOLUTE_HUMIDITY),
|
||||
eq(new QuantityType<>("0.9381970824113001000 g/m³")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_DEWPOINT),
|
||||
eq(new QuantityType<>("-20.31395053870025 °C")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void voltageChannel() {
|
||||
public void voltageChannel() throws OwException {
|
||||
final DS2438 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_VOLTAGE);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_VOLTAGE);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_VOLTAGE), eq(new QuantityType<>("2.0 V")));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_VOLTAGE), eq(new QuantityType<>("2.0 V")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentChannel() {
|
||||
public void currentChannel() throws OwException {
|
||||
final DS2438 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_CURRENT);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_CURRENT);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_CURRENT), eq(new QuantityType<>("2.0 mA")));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_CURRENT), eq(new QuantityType<>("2.0 mA")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lightChannel() {
|
||||
public void lightChannel() throws OwException {
|
||||
final DS2438 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(0.1));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(0.1));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_LIGHT);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.setLightSensorType(LightSensorType.ELABNET_V1);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_LIGHT);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.setLightSensorType(LightSensorType.ELABNET_V1);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_LIGHT), eq(new QuantityType<>("97442 lx")));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_LIGHT), eq(new QuantityType<>("97442 lx")));
|
||||
|
||||
testDevice.setLightSensorType(LightSensorType.ELABNET_V2);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.setLightSensorType(LightSensorType.ELABNET_V2);
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_LIGHT), eq(new QuantityType<>("134 lx")));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_LIGHT), eq(new QuantityType<>("134 lx")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supplyVoltageChannel() {
|
||||
public void supplyVoltageChannel() throws OwException {
|
||||
final DS2438 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_SUPPLYVOLTAGE);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_SUPPLYVOLTAGE);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_SUPPLYVOLTAGE), eq(new QuantityType<>("2.0 V")));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_SUPPLYVOLTAGE), eq(new QuantityType<>("2.0 V")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noChannel() {
|
||||
public void noChannel() throws OwException {
|
||||
final DS2438 testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.configureChannels();
|
||||
inOrder.verify(mockThingHandler).getThing();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire.device;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.CHANNEL_PRESENT;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -21,10 +21,13 @@ import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
import org.openhab.binding.onewire.internal.SensorId;
|
||||
import org.openhab.binding.onewire.internal.device.AbstractOwDevice;
|
||||
@@ -33,7 +36,11 @@ import org.openhab.binding.onewire.internal.handler.OwBaseThingHandler;
|
||||
import org.openhab.binding.onewire.internal.handler.OwserverBridgeHandler;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.thing.*;
|
||||
import org.openhab.core.thing.Channel;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
import org.openhab.core.thing.ThingUID;
|
||||
import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
||||
import org.openhab.core.thing.type.ChannelTypeUID;
|
||||
|
||||
@@ -42,27 +49,20 @@ import org.openhab.core.thing.type.ChannelTypeUID;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.WARN)
|
||||
@NonNullByDefault
|
||||
public abstract class DeviceTestParent<T extends AbstractOwDevice> {
|
||||
private @Nullable Class<T> deviceTestClazz;
|
||||
|
||||
@Mock
|
||||
@NonNullByDefault({})
|
||||
protected OwBaseThingHandler mockThingHandler;
|
||||
|
||||
@Mock
|
||||
@NonNullByDefault({})
|
||||
protected OwserverBridgeHandler mockBridgeHandler;
|
||||
|
||||
@Mock
|
||||
@NonNullByDefault({})
|
||||
protected Thing mockThing;
|
||||
protected @Mock @NonNullByDefault({}) OwBaseThingHandler mockThingHandler;
|
||||
protected @Mock @NonNullByDefault({}) OwserverBridgeHandler mockBridgeHandler;
|
||||
protected @Mock @NonNullByDefault({}) Thing mockThing;
|
||||
|
||||
protected SensorId testSensorId = new SensorId("00.000000000000");
|
||||
|
||||
public void setupMocks(ThingTypeUID thingTypeUID, Class<T> deviceTestClazz) {
|
||||
this.deviceTestClazz = deviceTestClazz;
|
||||
initMocks(this);
|
||||
|
||||
Mockito.when(mockThingHandler.getThing()).thenReturn(mockThing);
|
||||
Mockito.when(mockThing.getUID()).thenReturn(new ThingUID(thingTypeUID, "testsensor"));
|
||||
@@ -95,7 +95,7 @@ public abstract class DeviceTestParent<T extends AbstractOwDevice> {
|
||||
try {
|
||||
Constructor<T> constructor = deviceTestClazz.getConstructor(SensorId.class, OwBaseThingHandler.class);
|
||||
T testDevice = constructor.newInstance(testSensorId, mockThingHandler);
|
||||
Assert.assertNotNull(testDevice);
|
||||
assertNotNull(testDevice);
|
||||
return testDevice;
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException e) {
|
||||
@@ -112,7 +112,7 @@ public abstract class DeviceTestParent<T extends AbstractOwDevice> {
|
||||
Constructor<T> constructor = deviceTestClazz.getConstructor(SensorId.class, OwSensorType.class,
|
||||
OwBaseThingHandler.class);
|
||||
T testDevice = constructor.newInstance(testSensorId, sensorType, mockThingHandler);
|
||||
Assert.assertNotNull(testDevice);
|
||||
assertNotNull(testDevice);
|
||||
return testDevice;
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException e) {
|
||||
@@ -120,16 +120,13 @@ public abstract class DeviceTestParent<T extends AbstractOwDevice> {
|
||||
}
|
||||
}
|
||||
|
||||
public void presenceTest(OnOffType state) {
|
||||
public void presenceTest(OnOffType state) throws OwException {
|
||||
final T testDevice = instantiateDevice();
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(state);
|
||||
testDevice.checkPresence(mockBridgeHandler);
|
||||
|
||||
inOrder.verify(mockThingHandler).updatePresenceStatus(eq(state));
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(state);
|
||||
testDevice.checkPresence(mockBridgeHandler);
|
||||
|
||||
inOrder.verify(mockThingHandler).updatePresenceStatus(eq(state));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,8 @@ import static org.mockito.Mockito.times;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
@@ -37,7 +36,7 @@ import org.openhab.core.library.types.QuantityType;
|
||||
@NonNullByDefault
|
||||
public class EDS006xTest extends DeviceTestParent<EDS006x> {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMocks() {
|
||||
setupMocks(THING_TYPE_EDS_ENV, EDS006x.class);
|
||||
|
||||
@@ -50,114 +49,94 @@ public class EDS006xTest extends DeviceTestParent<EDS006x> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void temperatureChannel() {
|
||||
public void temperatureChannel() throws OwException {
|
||||
final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_TEMPERATURE);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_TEMPERATURE);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("10.0 °C")));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("10.0 °C")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void humidityChannel() {
|
||||
public void humidityChannel() throws OwException {
|
||||
final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_ABSOLUTE_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_DEWPOINT);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_ABSOLUTE_HUMIDITY);
|
||||
testDevice.enableChannel(CHANNEL_DEWPOINT);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_HUMIDITY), eq(new QuantityType<>("10.0 %")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_ABSOLUTE_HUMIDITY),
|
||||
eq(new QuantityType<>("0.9381970824113001000 g/m³")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_DEWPOINT),
|
||||
eq(new QuantityType<>("-20.31395053870025 °C")));
|
||||
inOrder.verify(mockBridgeHandler, times(2)).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_HUMIDITY), eq(new QuantityType<>("10.0 %")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_ABSOLUTE_HUMIDITY),
|
||||
eq(new QuantityType<>("0.9381970824113001000 g/m³")));
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_DEWPOINT),
|
||||
eq(new QuantityType<>("-20.31395053870025 °C")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pressureChannel() {
|
||||
public void pressureChannel() throws OwException {
|
||||
final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_PRESSURE);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_PRESSURE);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_PRESSURE), eq(new QuantityType<>("2.0 mbar")));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_PRESSURE), eq(new QuantityType<>("2.0 mbar")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lightChannel() {
|
||||
public void lightChannel() throws OwException {
|
||||
final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(100));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(100));
|
||||
|
||||
testDevice.enableChannel(CHANNEL_LIGHT);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.enableChannel(CHANNEL_LIGHT);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_LIGHT), eq(new QuantityType<>("100 lx")));
|
||||
inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
|
||||
inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_LIGHT), eq(new QuantityType<>("100 lx")));
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noChannel() {
|
||||
public void noChannel() throws OwException {
|
||||
final EDS006x testDevice = instantiateDevice(OwSensorType.EDS0068);
|
||||
final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
|
||||
|
||||
try {
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
|
||||
Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(2.0));
|
||||
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
testDevice.configureChannels();
|
||||
testDevice.refresh(mockBridgeHandler, true);
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,21 +12,17 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire.internal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.CONFIG_ID;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.THING_TYPE_BASIC;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.openhab.binding.onewire.internal.device.OwSensorType;
|
||||
import org.openhab.binding.onewire.internal.handler.BasicThingHandler;
|
||||
import org.openhab.binding.onewire.internal.handler.OwBaseThingHandler;
|
||||
@@ -47,15 +43,13 @@ import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
public class BasicThingHandlerTest extends AbstractThingHandlerTest {
|
||||
private static final String TEST_ID = "00.000000000000";
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws OwException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
initializeBridge();
|
||||
|
||||
final Bridge bridge = this.bridge;
|
||||
if (bridge == null) {
|
||||
Assert.fail("bridge is null");
|
||||
fail("bridge is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,7 +61,7 @@ public class BasicThingHandlerTest extends AbstractThingHandlerTest {
|
||||
|
||||
final Thing thing = this.thing;
|
||||
if (thing == null) {
|
||||
Assert.fail("thing is null");
|
||||
fail("thing is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,7 +79,7 @@ public class BasicThingHandlerTest extends AbstractThingHandlerTest {
|
||||
public void testInitializationEndsWithUnknown() throws OwException {
|
||||
final ThingHandler thingHandler = this.thingHandler;
|
||||
if (thingHandler == null) {
|
||||
Assert.fail("thingHandler is null");
|
||||
fail("thingHandler is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -103,7 +97,7 @@ public class BasicThingHandlerTest extends AbstractThingHandlerTest {
|
||||
final OwBaseThingHandler thingHandler = this.thingHandler;
|
||||
final InOrder inOrder = this.inOrder;
|
||||
if (thingHandler == null || inOrder == null) {
|
||||
Assert.fail("prerequisite is null");
|
||||
fail("prerequisite is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -127,7 +121,7 @@ public class BasicThingHandlerTest extends AbstractThingHandlerTest {
|
||||
final OwBaseThingHandler thingHandler = this.thingHandler;
|
||||
final InOrder inOrder = this.inOrder;
|
||||
if (thingHandler == null || inOrder == null) {
|
||||
Assert.fail("prerequisite is null");
|
||||
fail("prerequisite is null");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,25 +12,26 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire.internal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.openhab.binding.onewire.internal.handler.EDSSensorThingHandler;
|
||||
import org.openhab.binding.onewire.internal.handler.OwBaseThingHandler;
|
||||
import org.openhab.binding.onewire.test.AbstractThingHandlerTest;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
import org.openhab.core.thing.*;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.ThingStatus;
|
||||
import org.openhab.core.thing.ThingUID;
|
||||
import org.openhab.core.thing.binding.ThingHandler;
|
||||
import org.openhab.core.thing.binding.builder.ChannelBuilder;
|
||||
import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
@@ -50,15 +51,13 @@ public class EDSSensorThingHandlerTest extends AbstractThingHandlerTest {
|
||||
CHANNEL_ABSOLUTE_HUMIDITY);
|
||||
private static final ChannelUID CHANNEL_UID_DEWPOINT = new ChannelUID(THING_UID, CHANNEL_DEWPOINT);
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws OwException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
initializeBridge();
|
||||
|
||||
final Bridge bridge = this.bridge;
|
||||
if (bridge == null) {
|
||||
Assert.fail("bridge is null");
|
||||
fail("bridge is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -75,7 +74,7 @@ public class EDSSensorThingHandlerTest extends AbstractThingHandlerTest {
|
||||
|
||||
final Thing thing = this.thing;
|
||||
if (thing == null) {
|
||||
Assert.fail("thing is null");
|
||||
fail("thing is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,7 +96,7 @@ public class EDSSensorThingHandlerTest extends AbstractThingHandlerTest {
|
||||
public void testInitializationEndsWithUnknown() {
|
||||
final ThingHandler thingHandler = this.thingHandler;
|
||||
if (thingHandler == null) {
|
||||
Assert.fail("thingHandler is null");
|
||||
fail("thingHandler is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,7 +110,7 @@ public class EDSSensorThingHandlerTest extends AbstractThingHandlerTest {
|
||||
final OwBaseThingHandler thingHandler = this.thingHandler;
|
||||
final InOrder inOrder = this.inOrder;
|
||||
if (thingHandler == null || inOrder == null) {
|
||||
Assert.fail("prerequisite is null");
|
||||
fail("prerequisite is null");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,21 +12,17 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire.internal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.CONFIG_ID;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.THING_TYPE_MS_TX;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.openhab.binding.onewire.internal.device.OwSensorType;
|
||||
import org.openhab.binding.onewire.internal.handler.BasicMultisensorThingHandler;
|
||||
import org.openhab.binding.onewire.internal.handler.OwBaseThingHandler;
|
||||
@@ -47,15 +43,13 @@ import org.openhab.core.thing.binding.builder.ThingBuilder;
|
||||
public class MultisensorThingHandlerTest extends AbstractThingHandlerTest {
|
||||
private static final String TEST_ID = "00.000000000000";
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws OwException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
initializeBridge();
|
||||
|
||||
final Bridge bridge = this.bridge;
|
||||
if (bridge == null) {
|
||||
Assert.fail("bridge is null");
|
||||
fail("bridge is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,7 +61,7 @@ public class MultisensorThingHandlerTest extends AbstractThingHandlerTest {
|
||||
|
||||
final Thing thing = this.thing;
|
||||
if (thing == null) {
|
||||
Assert.fail("thing is null");
|
||||
fail("thing is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -95,7 +89,7 @@ public class MultisensorThingHandlerTest extends AbstractThingHandlerTest {
|
||||
public void testInitializationEndsWithUnknown() {
|
||||
final ThingHandler thingHandler = this.thingHandler;
|
||||
if (thingHandler == null) {
|
||||
Assert.fail("thingHandler is null");
|
||||
fail("thingHandler is null");
|
||||
return;
|
||||
}
|
||||
thingHandler.initialize();
|
||||
@@ -108,7 +102,7 @@ public class MultisensorThingHandlerTest extends AbstractThingHandlerTest {
|
||||
final OwBaseThingHandler thingHandler = this.thingHandler;
|
||||
final InOrder inOrder = this.inOrder;
|
||||
if (thingHandler == null || inOrder == null) {
|
||||
Assert.fail("prerequisite is null");
|
||||
fail("prerequisite is null");
|
||||
return;
|
||||
}
|
||||
thingHandler.initialize();
|
||||
|
||||
@@ -13,11 +13,10 @@
|
||||
package org.openhab.binding.onewire.internal;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -25,13 +24,14 @@ import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.openhab.binding.onewire.internal.handler.OwserverBridgeHandler;
|
||||
import org.openhab.binding.onewire.internal.owserver.OwserverConnection;
|
||||
import org.openhab.binding.onewire.internal.owserver.OwserverConnectionState;
|
||||
@@ -49,6 +49,7 @@ import org.openhab.core.thing.binding.builder.BridgeBuilder;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@NonNullByDefault
|
||||
public class OwserverBridgeHandlerTest extends JavaTest {
|
||||
|
||||
@@ -56,24 +57,17 @@ public class OwserverBridgeHandlerTest extends JavaTest {
|
||||
private static final int TEST_PORT = 4711;
|
||||
Map<String, Object> bridgeProperties = new HashMap<>();
|
||||
|
||||
@Mock
|
||||
@NonNullByDefault({})
|
||||
private OwserverConnection owserverConnection;
|
||||
|
||||
@Mock
|
||||
@NonNullByDefault({})
|
||||
private ThingHandlerCallback thingHandlerCallback;
|
||||
private @Mock @NonNullByDefault({}) OwserverConnection owserverConnection;
|
||||
private @Mock @NonNullByDefault({}) ThingHandlerCallback thingHandlerCallback;
|
||||
|
||||
private @Nullable OwserverBridgeHandler bridgeHandler;
|
||||
private @Nullable Bridge bridge;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
bridgeProperties.put(CONFIG_ADDRESS, TEST_HOST);
|
||||
bridgeProperties.put(CONFIG_PORT, TEST_PORT);
|
||||
|
||||
initMocks(this);
|
||||
|
||||
bridge = BridgeBuilder.create(THING_TYPE_OWSERVER, "owserver").withLabel("owserver")
|
||||
.withConfiguration(new Configuration(bridgeProperties)).build();
|
||||
|
||||
@@ -85,7 +79,7 @@ public class OwserverBridgeHandlerTest extends JavaTest {
|
||||
final Bridge bridge = this.bridge;
|
||||
|
||||
if (bridge == null) {
|
||||
Assert.fail("bridge is null");
|
||||
fail("bridge is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -95,7 +89,7 @@ public class OwserverBridgeHandlerTest extends JavaTest {
|
||||
this.bridgeHandler = bridgeHandler;
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
final OwserverBridgeHandler bridgeHandler = this.bridgeHandler;
|
||||
if (bridgeHandler != null) {
|
||||
@@ -107,7 +101,7 @@ public class OwserverBridgeHandlerTest extends JavaTest {
|
||||
public void testInitializationStartsConnectionWithOptions() {
|
||||
final OwserverBridgeHandler bridgeHandler = this.bridgeHandler;
|
||||
if (bridgeHandler == null) {
|
||||
Assert.fail("bridgeHandler is null");
|
||||
fail("bridgeHandler is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -123,7 +117,7 @@ public class OwserverBridgeHandlerTest extends JavaTest {
|
||||
public void testInitializationReportsRefreshableOnSuccessfullConnection() {
|
||||
final OwserverBridgeHandler bridgeHandler = this.bridgeHandler;
|
||||
if (bridgeHandler == null) {
|
||||
Assert.fail("bridgeHandler is null");
|
||||
fail("bridgeHandler is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -148,7 +142,7 @@ public class OwserverBridgeHandlerTest extends JavaTest {
|
||||
public void testInitializationReportsNotRefreshableOnFailedConnection() {
|
||||
final OwserverBridgeHandler bridgeHandler = this.bridgeHandler;
|
||||
if (bridgeHandler == null) {
|
||||
Assert.fail("bridgeHandler is null");
|
||||
fail("bridgeHandler is null");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,8 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire.owserver;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -22,12 +21,13 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
import org.openhab.binding.onewire.internal.OwPageBuffer;
|
||||
import org.openhab.binding.onewire.internal.SensorId;
|
||||
@@ -46,6 +46,7 @@ import org.openhab.core.types.State;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@NonNullByDefault
|
||||
public class OwserverConnectionTest extends JavaTest {
|
||||
private static final String TEST_HOST = "127.0.0.1";
|
||||
@@ -53,15 +54,12 @@ public class OwserverConnectionTest extends JavaTest {
|
||||
private @Nullable OwserverTestServer testServer;
|
||||
private @Nullable OwserverConnection owserverConnection;
|
||||
|
||||
@Mock
|
||||
private @NonNullByDefault({}) OwserverBridgeHandler bridgeHandler;
|
||||
private @Mock @NonNullByDefault({}) OwserverBridgeHandler bridgeHandler;
|
||||
|
||||
private int testPort;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
initMocks(this);
|
||||
|
||||
CompletableFuture<Boolean> serverStarted = new CompletableFuture<>();
|
||||
testPort = TestPortUtil.findFreePort();
|
||||
try {
|
||||
@@ -80,7 +78,7 @@ public class OwserverConnectionTest extends JavaTest {
|
||||
serverStarted.get(); // wait for the server thread to start
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
try {
|
||||
final OwserverTestServer testServer = this.testServer;
|
||||
@@ -96,7 +94,7 @@ public class OwserverConnectionTest extends JavaTest {
|
||||
public void successfullConnectionReportedToBridgeHandler() {
|
||||
final OwserverConnection owserverConnection = this.owserverConnection;
|
||||
if (owserverConnection == null) {
|
||||
Assert.fail("connection is null");
|
||||
fail("connection is null");
|
||||
return;
|
||||
}
|
||||
owserverConnection.start();
|
||||
@@ -108,7 +106,7 @@ public class OwserverConnectionTest extends JavaTest {
|
||||
public void failedConnectionReportedToBridgeHandler() {
|
||||
final OwserverConnection owserverConnection = this.owserverConnection;
|
||||
if (owserverConnection == null) {
|
||||
Assert.fail("connection is null");
|
||||
fail("connection is null");
|
||||
return;
|
||||
}
|
||||
owserverConnection.setPort(1);
|
||||
@@ -119,30 +117,27 @@ public class OwserverConnectionTest extends JavaTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDirectory() {
|
||||
public void testGetDirectory() throws OwException {
|
||||
final OwserverConnection owserverConnection = this.owserverConnection;
|
||||
if (owserverConnection == null) {
|
||||
Assert.fail("connection is null");
|
||||
fail("connection is null");
|
||||
return;
|
||||
}
|
||||
owserverConnection.start();
|
||||
try {
|
||||
List<SensorId> directory = owserverConnection.getDirectory("/");
|
||||
|
||||
assertEquals(3, directory.size());
|
||||
assertEquals(new SensorId("/00.0123456789ab"), directory.get(0));
|
||||
assertEquals(new SensorId("/00.0123456789ac"), directory.get(1));
|
||||
assertEquals(new SensorId("/00.0123456789ad"), directory.get(2));
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
List<SensorId> directory = owserverConnection.getDirectory("/");
|
||||
|
||||
assertEquals(3, directory.size());
|
||||
assertEquals(new SensorId("/00.0123456789ab"), directory.get(0));
|
||||
assertEquals(new SensorId("/00.0123456789ac"), directory.get(1));
|
||||
assertEquals(new SensorId("/00.0123456789ad"), directory.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckPresence() {
|
||||
final OwserverConnection owserverConnection = this.owserverConnection;
|
||||
if (owserverConnection == null) {
|
||||
Assert.fail("connection is null");
|
||||
fail("connection is null");
|
||||
return;
|
||||
}
|
||||
owserverConnection.start();
|
||||
@@ -154,71 +149,58 @@ public class OwserverConnectionTest extends JavaTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadDecimalType() {
|
||||
public void testReadDecimalType() throws OwException {
|
||||
final OwserverConnection owserverConnection = this.owserverConnection;
|
||||
if (owserverConnection == null) {
|
||||
Assert.fail("connection is null");
|
||||
fail("connection is null");
|
||||
return;
|
||||
}
|
||||
owserverConnection.start();
|
||||
try {
|
||||
DecimalType number = (DecimalType) owserverConnection.readDecimalType("testsensor/decimal");
|
||||
|
||||
assertEquals(17.4, number.doubleValue(), 0.01);
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
DecimalType number = (DecimalType) owserverConnection.readDecimalType("testsensor/decimal");
|
||||
|
||||
assertEquals(17.4, number.doubleValue(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadDecimalTypeArray() {
|
||||
public void testReadDecimalTypeArray() throws OwException {
|
||||
final OwserverConnection owserverConnection = this.owserverConnection;
|
||||
if (owserverConnection == null) {
|
||||
Assert.fail("connection is null");
|
||||
fail("connection is null");
|
||||
return;
|
||||
}
|
||||
owserverConnection.start();
|
||||
try {
|
||||
List<State> numbers = owserverConnection.readDecimalTypeArray("testsensor/decimalarray");
|
||||
|
||||
assertEquals(3834, ((DecimalType) numbers.get(0)).intValue());
|
||||
assertEquals(0, ((DecimalType) numbers.get(1)).intValue());
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
List<State> numbers = owserverConnection.readDecimalTypeArray("testsensor/decimalarray");
|
||||
|
||||
assertEquals(3834, ((DecimalType) numbers.get(0)).intValue());
|
||||
assertEquals(0, ((DecimalType) numbers.get(1)).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPages() {
|
||||
public void testGetPages() throws OwException {
|
||||
final OwserverConnection owserverConnection = this.owserverConnection;
|
||||
if (owserverConnection == null) {
|
||||
Assert.fail("connection is null");
|
||||
fail("connection is null");
|
||||
return;
|
||||
}
|
||||
owserverConnection.start();
|
||||
try {
|
||||
OwPageBuffer pageBuffer = owserverConnection.readPages("testsensor");
|
||||
|
||||
assertEquals(31, pageBuffer.getByte(5, 7));
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
OwPageBuffer pageBuffer = owserverConnection.readPages("testsensor");
|
||||
assertEquals(31, pageBuffer.getByte(5, 7));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteDecimalType() {
|
||||
public void testWriteDecimalType() throws OwException {
|
||||
final OwserverConnection owserverConnection = this.owserverConnection;
|
||||
if (owserverConnection == null) {
|
||||
Assert.fail("connection is null");
|
||||
fail("connection is null");
|
||||
return;
|
||||
}
|
||||
owserverConnection.start();
|
||||
try {
|
||||
owserverConnection.writeDecimalType("testsensor/decimal", new DecimalType(2009));
|
||||
|
||||
Mockito.verify(bridgeHandler, never()).reportConnectionState(OwserverConnectionState.FAILED);
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
}
|
||||
owserverConnection.writeDecimalType("testsensor/decimal", new DecimalType(2009));
|
||||
|
||||
Mockito.verify(bridgeHandler, never()).reportConnectionState(OwserverConnectionState.FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.openhab.binding.onewire.internal.OwBindingConstants.THING_TYPE_OWSERVER;
|
||||
|
||||
@@ -23,11 +24,14 @@ import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.openhab.binding.onewire.internal.OwDynamicStateDescriptionProvider;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
import org.openhab.binding.onewire.internal.handler.OwBaseThingHandler;
|
||||
@@ -48,6 +52,8 @@ import org.openhab.core.thing.binding.builder.BridgeBuilder;
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.WARN)
|
||||
@NonNullByDefault
|
||||
public abstract class AbstractThingHandlerTest extends JavaTest {
|
||||
|
||||
@@ -56,25 +62,11 @@ public abstract class AbstractThingHandlerTest extends JavaTest {
|
||||
protected Map<String, Object> thingConfiguration = new HashMap<>();
|
||||
protected Map<String, Object> channelProperties = new HashMap<>();
|
||||
|
||||
@Mock
|
||||
@NonNullByDefault({})
|
||||
protected ThingHandlerCallback thingHandlerCallback;
|
||||
|
||||
@Mock
|
||||
@NonNullByDefault({})
|
||||
protected OwDynamicStateDescriptionProvider stateProvider;
|
||||
|
||||
@Mock
|
||||
@NonNullByDefault({})
|
||||
protected ThingHandlerCallback bridgeHandlerCallback;
|
||||
|
||||
@Mock
|
||||
@NonNullByDefault({})
|
||||
protected OwserverBridgeHandler bridgeHandler;
|
||||
|
||||
@Mock
|
||||
@NonNullByDefault({})
|
||||
protected OwserverBridgeHandler secondBridgeHandler;
|
||||
protected @Mock @NonNullByDefault({}) ThingHandlerCallback thingHandlerCallback;
|
||||
protected @Mock @NonNullByDefault({}) OwDynamicStateDescriptionProvider stateProvider;
|
||||
protected @Mock @NonNullByDefault({}) ThingHandlerCallback bridgeHandlerCallback;
|
||||
protected @Mock @NonNullByDefault({}) OwserverBridgeHandler bridgeHandler;
|
||||
protected @Mock @NonNullByDefault({}) OwserverBridgeHandler secondBridgeHandler;
|
||||
|
||||
protected List<Channel> channels = new ArrayList<>();
|
||||
|
||||
@@ -84,7 +76,7 @@ public abstract class AbstractThingHandlerTest extends JavaTest {
|
||||
|
||||
protected @Nullable InOrder inOrder;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
final ThingHandler thingHandler = this.thingHandler;
|
||||
if (thingHandler != null) {
|
||||
@@ -95,7 +87,7 @@ public abstract class AbstractThingHandlerTest extends JavaTest {
|
||||
protected void initializeHandlerMocks() {
|
||||
final ThingHandler thingHandler = this.thingHandler;
|
||||
if (thingHandler == null) {
|
||||
Assert.fail("thingHandler is null");
|
||||
fail("thingHandler is null");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -131,7 +123,7 @@ public abstract class AbstractThingHandlerTest extends JavaTest {
|
||||
Mockito.doAnswer(answer -> {
|
||||
final OwBaseThingHandler thingHandler = this.thingHandler;
|
||||
if (thingHandler == null) {
|
||||
Assert.fail("thingHandler is null");
|
||||
fail("thingHandler is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.binding.onewire.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -22,7 +24,6 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.Assert;
|
||||
import org.openhab.binding.onewire.internal.OwException;
|
||||
import org.openhab.binding.onewire.internal.OwPageBuffer;
|
||||
import org.openhab.binding.onewire.internal.owserver.OwserverPacket;
|
||||
@@ -78,7 +79,7 @@ public class OwserverTestServer {
|
||||
} catch (IOException e) {
|
||||
logger.error("I/O Error: {}", e.getMessage());
|
||||
} catch (OwException e) {
|
||||
Assert.fail("caught unexpected OwException");
|
||||
fail("caught unexpected OwException");
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
Reference in New Issue
Block a user