Migrate tests to JUnit 5 (#8519)

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2020-09-21 18:21:26 +02:00 committed by GitHub
parent 6df6783b60
commit bd82ca82df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
478 changed files with 3996 additions and 4419 deletions

View File

@ -12,15 +12,15 @@
*/
package org.openhab.binding.astro.internal.calc;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openhab.binding.astro.internal.model.Sun;
import org.openhab.binding.astro.internal.model.SunPhaseName;
@ -51,7 +51,7 @@ public class SunCalcTest {
private SunCalc sunCalc;
@Before
@BeforeEach
public void init() {
sunCalc = new SunCalc();
}
@ -178,7 +178,7 @@ public class SunCalcTest {
}
@Test
@Ignore
@Disabled
public void testRangesForCoherenceBetweenNightEndAndAstroDawnStart() {
Sun sun = sunCalc.getSunInfo(FEB_27_2019, AMSTERDAM_LATITUDE, AMSTERDAM_LONGITUDE, AMSTERDAM_ALTITUDE, false);

View File

@ -12,12 +12,12 @@
*/
package org.openhab.binding.astro.internal.model;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.time.ZoneId;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.astro.internal.config.AstroChannelConfig;
import org.openhab.binding.astro.internal.util.PropertyUtils;
import org.openhab.core.library.types.StringType;
@ -39,7 +39,7 @@ public class SunTest {
private static ZoneId ZONE = ZoneId.systemDefault();
@Before
@BeforeEach
public void init() {
sun = new Sun();
config = new AstroChannelConfig();
@ -68,13 +68,14 @@ public class SunTest {
PropertyUtils.getState(new ChannelUID("astro:sun:home:phase#name"), config, sun, ZONE));
}
@Test(expected = NullPointerException.class)
@Test
public void testGetStateWhenNullPhase() throws Exception {
sun.setPhase(null);
assertNull(sun.getPhase());
assertEquals(UnDefType.UNDEF,
PropertyUtils.getState(new ChannelUID("astro:sun:home:phase#name"), config, sun, ZONE));
assertThrows(NullPointerException.class, () -> assertEquals(UnDefType.UNDEF,
PropertyUtils.getState(new ChannelUID("astro:sun:home:phase#name"), config, sun, ZONE)));
}
@Test

View File

@ -12,11 +12,13 @@
*/
package org.openhab.binding.avmfritz.actions;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.Before;
import org.junit.Test;
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.junit.jupiter.MockitoExtension;
import org.openhab.binding.avmfritz.internal.handler.AVMFritzHeatingActionsHandler;
import org.openhab.core.thing.binding.ThingActions;
import org.openhab.core.thing.binding.ThingHandler;
@ -26,6 +28,7 @@ import org.openhab.core.thing.binding.ThingHandler;
*
* @author Christoph Weitkamp - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
public class AVMFritzHeatingActionsTest {
private final ThingActions thingActionsStub = new ThingActions() {
@ -43,32 +46,32 @@ public class AVMFritzHeatingActionsTest {
private AVMFritzHeatingActions heatingActions;
@Before
@BeforeEach
public void setUp() {
initMocks(this);
heatingActions = new AVMFritzHeatingActions();
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSetBoostModeThingActionsIsNull() {
AVMFritzHeatingActions.setBoostMode(null, Long.valueOf(5L));
assertThrows(IllegalArgumentException.class, () -> AVMFritzHeatingActions.setBoostMode(null, Long.valueOf(5L)));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSetBoostModeThingActionsIsNotPushoverThingActions() {
AVMFritzHeatingActions.setBoostMode(thingActionsStub, Long.valueOf(5L));
assertThrows(IllegalArgumentException.class,
() -> AVMFritzHeatingActions.setBoostMode(thingActionsStub, Long.valueOf(5L)));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSetBoostModeThingHandlerIsNull() {
AVMFritzHeatingActions.setBoostMode(heatingActions, Long.valueOf(5L));
assertThrows(IllegalArgumentException.class,
() -> AVMFritzHeatingActions.setBoostMode(heatingActions, Long.valueOf(5L)));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSetBoostModeDurationNull() {
heatingActions.setThingHandler(heatingActionsHandler);
AVMFritzHeatingActions.setBoostMode(heatingActions, null);
assertThrows(IllegalArgumentException.class, () -> AVMFritzHeatingActions.setBoostMode(heatingActions, null));
}
@Test
@ -77,25 +80,29 @@ public class AVMFritzHeatingActionsTest {
AVMFritzHeatingActions.setBoostMode(heatingActions, Long.valueOf(5L));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSetWindowOpenModeThingActionsIsNull() {
AVMFritzHeatingActions.setWindowOpenMode(null, Long.valueOf(5L));
assertThrows(IllegalArgumentException.class,
() -> AVMFritzHeatingActions.setWindowOpenMode(null, Long.valueOf(5L)));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSetWindowOpenModeThingActionsIsNotPushoverThingActions() {
AVMFritzHeatingActions.setWindowOpenMode(thingActionsStub, Long.valueOf(5L));
assertThrows(IllegalArgumentException.class,
() -> AVMFritzHeatingActions.setWindowOpenMode(thingActionsStub, Long.valueOf(5L)));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSetWindowOpenModeThingHandlerIsNull() {
AVMFritzHeatingActions.setWindowOpenMode(heatingActions, Long.valueOf(5L));
assertThrows(IllegalArgumentException.class,
() -> AVMFritzHeatingActions.setWindowOpenMode(heatingActions, Long.valueOf(5L)));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSetWindowOpenModeDurationNull() {
heatingActions.setThingHandler(heatingActionsHandler);
AVMFritzHeatingActions.setWindowOpenMode(heatingActions, null);
assertThrows(IllegalArgumentException.class,
() -> AVMFritzHeatingActions.setWindowOpenMode(heatingActions, null));
}
@Test

View File

@ -12,7 +12,7 @@
*/
package org.openhab.binding.avmfritz.internal.dto;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
import java.io.StringReader;
@ -23,8 +23,8 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
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.avmfritz.internal.util.JAXBUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -41,7 +41,7 @@ public class AVMFritzDeviceListModelTest {
private @NonNullByDefault({}) DeviceListModel devices;
@Before
@BeforeEach
public void setUp() {
//@formatter:off
String xml =

View File

@ -12,7 +12,7 @@
*/
package org.openhab.binding.avmfritz.internal.dto;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.io.StringReader;
import java.util.Optional;
@ -21,8 +21,8 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
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.avmfritz.internal.dto.templates.TemplateListModel;
import org.openhab.binding.avmfritz.internal.dto.templates.TemplateModel;
import org.openhab.binding.avmfritz.internal.util.JAXBUtils;
@ -41,7 +41,7 @@ public class AVMFritzTemplateListModelTest {
private @NonNullByDefault({}) TemplateListModel templates;
@Before
@BeforeEach
public void setUp() {
//@formatter:off
String xml =

View File

@ -12,12 +12,12 @@
*/
package org.openhab.binding.avmfritz.internal.dto;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import java.math.BigDecimal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link HeatingModel} methods.

View File

@ -12,10 +12,10 @@
*/
package org.openhab.binding.bluetooth.airthings;
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.bluetooth.airthings.internal.AirthingsParserException;
import org.openhab.binding.bluetooth.airthings.internal.AirthingsWavePlusDataParser;
@ -27,22 +27,22 @@ import org.openhab.binding.bluetooth.airthings.internal.AirthingsWavePlusDataPar
@NonNullByDefault
public class AirthingsWavePlusParserTest {
@Test(expected = AirthingsParserException.class)
public void testWrongVersion() throws AirthingsParserException {
@Test
public void testWrongVersion() {
int[] data = { 5, 55, 51, 0, 122, 0, 61, 0, 119, 9, 11, 194, 169, 2, 46, 0, 0, 0, 4, 20 };
new AirthingsWavePlusDataParser(data);
assertThrows(AirthingsParserException.class, () -> new AirthingsWavePlusDataParser(data));
}
@Test(expected = AirthingsParserException.class)
public void testEmptyData() throws AirthingsParserException {
@Test
public void testEmptyData() {
int[] data = {};
new AirthingsWavePlusDataParser(data);
assertThrows(AirthingsParserException.class, () -> new AirthingsWavePlusDataParser(data));
}
@Test(expected = AirthingsParserException.class)
@Test
public void testWrongDataLen() throws AirthingsParserException {
int[] data = { 1, 55, 51, 0, 122, 0, 61, 0, 119, 9, 11, 194, 169, 2, 46, 0, 0 };
new AirthingsWavePlusDataParser(data);
assertThrows(AirthingsParserException.class, () -> new AirthingsWavePlusDataParser(data));
}
@Test

View File

@ -12,9 +12,10 @@
*/
package org.openhab.binding.bluetooth.am43;
import static org.junit.jupiter.api.Assertions.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.bluetooth.am43.internal.command.ControlCommand;
import org.openhab.binding.bluetooth.am43.internal.command.GetAllCommand;
import org.openhab.binding.bluetooth.am43.internal.data.ControlAction;
@ -31,7 +32,7 @@ public class CommandTest {
public void findAllCommandTest() {
byte[] expected = HexUtils.hexToBytes("00ff00009aa701013d");
byte[] actual = new GetAllCommand().getRequest();
Assert.assertArrayEquals(expected, actual);
assertArrayEquals(expected, actual);
}
@Test
@ -39,7 +40,7 @@ public class CommandTest {
byte[] expected = HexUtils.hexToBytes("00ff00009a0a01cc5d");
byte[] actual = new ControlCommand(ControlAction.STOP).getRequest();
Assert.assertArrayEquals(expected, actual);
assertArrayEquals(expected, actual);
}
@Test
@ -47,6 +48,6 @@ public class CommandTest {
byte[] expected = HexUtils.hexToBytes("00ff00009a0a01dd4c");
byte[] actual = new ControlCommand(ControlAction.OPEN).getRequest();
Assert.assertArrayEquals(expected, actual);
assertArrayEquals(expected, actual);
}
}

View File

@ -12,10 +12,10 @@
*/
package org.openhab.binding.bluetooth.bluegiga.internal.attributeclient;
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.bluetooth.bluegiga.internal.command.attributeclient.BlueGigaFindInformationFoundEvent;
/**

View File

@ -12,14 +12,14 @@
*/
package org.openhab.binding.bluetooth.bluegiga.internal.eir;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Tests {@link EirRecord}.

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.bluetooth.daikinmadoka.internal;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
import org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.GetIndoorOutoorTemperatures;

View File

@ -12,7 +12,9 @@
*/
package org.openhab.binding.bluetooth;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
/**
* Tests {@link BluetoothAddress}.
@ -21,14 +23,14 @@ import org.junit.Test;
*/
public class BluetoothAddressTest {
@Test(expected = IllegalArgumentException.class)
@Test
public void testConstructorWithNullParam() {
new BluetoothAddress(null);
assertThrows(IllegalArgumentException.class, () -> new BluetoothAddress(null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testConstructorWithoutColons() {
new BluetoothAddress("123456789ABC");
assertThrows(IllegalArgumentException.class, () -> new BluetoothAddress("123456789ABC"));
}
@Test

View File

@ -13,6 +13,8 @@
package org.openhab.binding.bluetooth.discovery.internal;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Collections;
import java.util.List;
@ -25,16 +27,18 @@ import org.apache.commons.lang.RandomStringUtils;
import org.eclipse.jdt.annotation.NonNull;
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.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.openhab.binding.bluetooth.BluetoothAdapter;
import org.openhab.binding.bluetooth.BluetoothAddress;
import org.openhab.binding.bluetooth.BluetoothBindingConstants;
@ -59,8 +63,10 @@ import org.slf4j.LoggerFactory;
*
* @author Connor Petty - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
@NonNullByDefault
@RunWith(MockitoJUnitRunner.class)
@Disabled("Needs to be updated for OH3")
public class BluetoothDiscoveryServiceTest {
private static final int TIMEOUT = 2000;
@ -69,13 +75,10 @@ public class BluetoothDiscoveryServiceTest {
private @NonNullByDefault({}) BluetoothDiscoveryService discoveryService;
@Spy
private @NonNullByDefault({}) MockDiscoveryParticipant participant1 = new MockDiscoveryParticipant();
private @Spy @NonNullByDefault({}) MockDiscoveryParticipant participant1 = new MockDiscoveryParticipant();
private @Mock @NonNullByDefault({}) DiscoveryListener mockDiscoveryListener;
@Mock
private @NonNullByDefault({}) DiscoveryListener mockDiscoveryListener;
@Before
@BeforeEach
public void setup() {
discoveryService = new BluetoothDiscoveryService();
discoveryService.addDiscoveryListener(mockDiscoveryListener);
@ -185,12 +188,12 @@ public class BluetoothDiscoveryServiceTest {
DiscoveryResult result1 = results.get(0);
DiscoveryResult result2 = results.get(1);
Assert.assertNotEquals(result1.getBridgeUID(), result2.getBridgeUID());
Assert.assertThat(result1.getBridgeUID(), anyOf(is(mockAdapter1.getUID()), is(mockAdapter2.getUID())));
Assert.assertThat(result2.getBridgeUID(), anyOf(is(mockAdapter1.getUID()), is(mockAdapter2.getUID())));
Assert.assertEquals(result1.getThingUID().getId(), result2.getThingUID().getId());
Assert.assertEquals(result1.getLabel(), result2.getLabel());
Assert.assertEquals(result1.getRepresentationProperty(), result2.getRepresentationProperty());
assertNotEquals(result1.getBridgeUID(), result2.getBridgeUID());
assertThat(result1.getBridgeUID(), anyOf(is(mockAdapter1.getUID()), is(mockAdapter2.getUID())));
assertThat(result2.getBridgeUID(), anyOf(is(mockAdapter1.getUID()), is(mockAdapter2.getUID())));
assertEquals(result1.getThingUID().getId(), result2.getThingUID().getId());
assertEquals(result1.getLabel(), result2.getLabel());
assertEquals(result1.getRepresentationProperty(), result2.getRepresentationProperty());
}
@Test
@ -308,7 +311,7 @@ public class BluetoothDiscoveryServiceTest {
DiscoveryResult result = resultCaptor.getValue();
Assert.assertEquals(BluetoothBindingConstants.THING_TYPE_BEACON, result.getThingTypeUID());
assertEquals(BluetoothBindingConstants.THING_TYPE_BEACON, result.getThingTypeUID());
Mockito.verify(mockDiscoveryListener, Mockito.timeout(TIMEOUT).times(1)).thingRemoved(
ArgumentMatchers.same(discoveryService),
@ -330,7 +333,7 @@ public class BluetoothDiscoveryServiceTest {
DiscoveryResult result = resultCaptor.getValue();
Assert.assertEquals(BluetoothBindingConstants.THING_TYPE_BEACON, result.getThingTypeUID());
assertEquals(BluetoothBindingConstants.THING_TYPE_BEACON, result.getThingTypeUID());
discoveryService.deviceRemoved(device);
@ -382,7 +385,7 @@ public class BluetoothDiscoveryServiceTest {
DiscoveryResult result = resultCaptor.getValue();
Assert.assertEquals(BluetoothBindingConstants.THING_TYPE_BEACON, result.getThingTypeUID());
assertEquals(BluetoothBindingConstants.THING_TYPE_BEACON, result.getThingTypeUID());
device.setManufacturerId(10);
@ -450,7 +453,7 @@ public class BluetoothDiscoveryServiceTest {
ArgumentMatchers.same(discoveryService),
ArgumentMatchers.argThat(arg -> arg.getThingTypeUID().equals(participant2.typeUID)));
Assert.assertEquals(1, callCount.get());
assertEquals(1, callCount.get());
}
@Test
@ -471,12 +474,12 @@ public class BluetoothDiscoveryServiceTest {
DiscoveryResult result1 = results.get(0);
DiscoveryResult result2 = results.get(1);
Assert.assertNotEquals(result1.getBridgeUID(), result2.getBridgeUID());
Assert.assertThat(result1.getBridgeUID(), anyOf(is(mockAdapter1.getUID()), is(roamingAdapter.getUID())));
Assert.assertThat(result2.getBridgeUID(), anyOf(is(mockAdapter1.getUID()), is(roamingAdapter.getUID())));
Assert.assertEquals(result1.getThingUID().getId(), result2.getThingUID().getId());
Assert.assertEquals(result1.getLabel(), result2.getLabel());
Assert.assertEquals(result1.getRepresentationProperty(), result2.getRepresentationProperty());
assertNotEquals(result1.getBridgeUID(), result2.getBridgeUID());
assertThat(result1.getBridgeUID(), anyOf(is(mockAdapter1.getUID()), is(roamingAdapter.getUID())));
assertThat(result2.getBridgeUID(), anyOf(is(mockAdapter1.getUID()), is(roamingAdapter.getUID())));
assertEquals(result1.getThingUID().getId(), result2.getThingUID().getId());
assertEquals(result1.getLabel(), result2.getLabel());
assertEquals(result1.getRepresentationProperty(), result2.getRepresentationProperty());
}
@Test
@ -499,12 +502,12 @@ public class BluetoothDiscoveryServiceTest {
ThingUID result1 = results.get(0);
ThingUID result2 = results.get(1);
Assert.assertNotEquals(result1.getBridgeIds(), result2.getBridgeIds());
Assert.assertThat(result1.getBridgeIds().get(0),
assertNotEquals(result1.getBridgeIds(), result2.getBridgeIds());
assertThat(result1.getBridgeIds().get(0),
anyOf(is(mockAdapter1.getUID().getId()), is(roamingAdapter.getUID().getId())));
Assert.assertThat(result2.getBridgeIds().get(0),
assertThat(result2.getBridgeIds().get(0),
anyOf(is(mockAdapter1.getUID().getId()), is(roamingAdapter.getUID().getId())));
Assert.assertEquals(result1.getId(), result2.getId());
assertEquals(result1.getId(), result2.getId());
}
private class RoamingDiscoveryParticipant implements BluetoothDiscoveryParticipant {
@ -555,7 +558,8 @@ public class BluetoothDiscoveryServiceTest {
@Override
public @NonNull ThingUID getThingUID(BluetoothDiscoveryDevice device) {
String id = device.getName() != null ? device.getName() : RandomStringUtils.randomAlphabetic(6);
String deviceName = device.getName();
String id = deviceName != null ? deviceName : RandomStringUtils.randomAlphabetic(6);
return new ThingUID(typeUID, device.getAdapter().getUID(), id);
}
}

View File

@ -12,11 +12,10 @@
*/
package org.openhab.binding.bsblan.internal;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
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.core.thing.ThingTypeUID;
/**

View File

@ -12,12 +12,10 @@
*/
package org.openhab.binding.bsblan.internal.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
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.bsblan.internal.api.dto.BsbLanApiParameterDTO;
import org.openhab.binding.bsblan.internal.api.dto.BsbLanApiParameterQueryResponseDTO;
import org.openhab.binding.bsblan.internal.api.dto.BsbLanApiParameterSetRequestDTO;

View File

@ -12,13 +12,11 @@
*/
package org.openhab.binding.bsblan.internal.helper;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.*;
import static org.openhab.binding.bsblan.internal.BsbLanBindingConstants.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.bsblan.internal.api.dto.BsbLanApiParameterDTO;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
@ -219,10 +217,10 @@ public class BsbLanParameterConverterTests {
@Test
public void testGetValueForNumberValueChannel() {
assertNull("1", BsbLanParameterConverter.getValue(PARAMETER_CHANNEL_NUMBER_VALUE, OnOffType.ON));
assertNull("0", BsbLanParameterConverter.getValue(PARAMETER_CHANNEL_NUMBER_VALUE, OnOffType.OFF));
assertEquals("42", BsbLanParameterConverter.getValue(PARAMETER_CHANNEL_NUMBER_VALUE, new DecimalType(42)));
assertEquals("22.5", BsbLanParameterConverter.getValue(PARAMETER_CHANNEL_NUMBER_VALUE, new DecimalType(22.5)));
assertNull(BsbLanParameterConverter.getValue(PARAMETER_CHANNEL_NUMBER_VALUE, OnOffType.ON), "1");
assertNull(BsbLanParameterConverter.getValue(PARAMETER_CHANNEL_NUMBER_VALUE, OnOffType.OFF), "0");
assertEquals(BsbLanParameterConverter.getValue(PARAMETER_CHANNEL_NUMBER_VALUE, new DecimalType(42)), "42");
assertEquals(BsbLanParameterConverter.getValue(PARAMETER_CHANNEL_NUMBER_VALUE, new DecimalType(22.5)), "22.5");
assertNull(BsbLanParameterConverter.getValue(PARAMETER_CHANNEL_NUMBER_VALUE,
new StringType("Not a number value")));
assertNull(BsbLanParameterConverter.getValue(PARAMETER_CHANNEL_NUMBER_VALUE, new StringType("")));

View File

@ -12,14 +12,14 @@
*/
package org.openhab.binding.buienradar;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import java.math.BigDecimal;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.buienradar.internal.buienradarapi.BuienradarParseException;
import org.openhab.binding.buienradar.internal.buienradarapi.BuienradarPredictionAPI;
import org.openhab.binding.buienradar.internal.buienradarapi.Prediction;

View File

@ -12,11 +12,10 @@
*/
package org.openhab.binding.danfossairunit.internal;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
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.core.library.types.OnOffType;
/**

View File

@ -13,16 +13,16 @@
package org.openhab.binding.darksky.internal.utils;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.core.config.core.ConfigConstants;
/**
@ -45,18 +45,18 @@ public class ByteArrayFileCacheTest {
private ByteArrayFileCache subject;
@Before
@BeforeEach
public void setUp() {
subject = new ByteArrayFileCache(SERVICE_PID);
}
@After
@AfterEach
public void tearDown() {
// delete all files
subject.clear();
}
@AfterClass
@AfterAll
public static void cleanUp() {
// delete all folders
SERVICE_CACHE_FOLDER.delete();

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.deconz;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.MockitoAnnotations.initMocks;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@ -23,11 +23,14 @@ import java.time.ZonedDateTime;
import org.apache.commons.io.IOUtils;
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.junit.jupiter.api.extension.ExtendWith;
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.deconz.internal.Util;
import org.openhab.binding.deconz.internal.discovery.ThingDiscoveryService;
import org.openhab.binding.deconz.internal.dto.BridgeFullState;
@ -49,23 +52,18 @@ import com.google.gson.GsonBuilder;
*
* @author Jan N. Klug - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
@NonNullByDefault
public class DeconzTest {
private @NonNullByDefault({}) Gson gson;
@Mock
private @NonNullByDefault({}) DiscoveryListener discoveryListener;
private @Mock @NonNullByDefault({}) DiscoveryListener discoveryListener;
private @Mock @NonNullByDefault({}) DeconzBridgeHandler bridgeHandler;
private @Mock @NonNullByDefault({}) Bridge bridge;
@Mock
private @NonNullByDefault({}) DeconzBridgeHandler bridgeHandler;
@Mock
private @NonNullByDefault({}) Bridge bridge;
@Before
@BeforeEach
public void initialize() {
initMocks(this);
Mockito.doAnswer(answer -> bridge).when(bridgeHandler).getThing();
Mockito.doAnswer(answer -> new ThingUID("deconz", "mybridge")).when(bridge).getUID();
@ -78,9 +76,9 @@ public class DeconzTest {
@Test
public void discoveryTest() throws IOException {
BridgeFullState bridgeFullState = getObjectFromJson("discovery.json", BridgeFullState.class, gson);
Assert.assertNotNull(bridgeFullState);
Assert.assertEquals(6, bridgeFullState.lights.size());
Assert.assertEquals(9, bridgeFullState.sensors.size());
assertNotNull(bridgeFullState);
assertEquals(6, bridgeFullState.lights.size());
assertEquals(9, bridgeFullState.sensors.size());
ThingDiscoveryService discoveryService = new ThingDiscoveryService();
discoveryService.setThingHandler(bridgeHandler);
@ -98,10 +96,10 @@ public class DeconzTest {
@Test
public void dateTimeConversionTest() {
DateTimeType dateTime = Util.convertTimestampToDateTime("2020-08-22T11:09Z");
Assert.assertEquals(new DateTimeType(ZonedDateTime.parse("2020-08-22T11:09:00Z")), dateTime);
assertEquals(new DateTimeType(ZonedDateTime.parse("2020-08-22T11:09:00Z")), dateTime);
dateTime = Util.convertTimestampToDateTime("2020-08-22T11:09:47");
Assert.assertEquals(
new DateTimeType(ZonedDateTime.parse("2020-08-22T11:09:47Z")).toZone(ZoneId.systemDefault()), dateTime);
assertEquals(new DateTimeType(ZonedDateTime.parse("2020-08-22T11:09:47Z")).toZone(ZoneId.systemDefault()),
dateTime);
}
}

View File

@ -12,9 +12,8 @@
*/
package org.openhab.binding.deconz;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.*;
import static org.openhab.binding.deconz.internal.BindingConstants.*;
import java.io.IOException;
@ -23,11 +22,12 @@ import java.util.Map;
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.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openhab.binding.deconz.internal.StateDescriptionProvider;
import org.openhab.binding.deconz.internal.dto.LightMessage;
import org.openhab.binding.deconz.internal.handler.LightThingHandler;
@ -53,20 +53,16 @@ import com.google.gson.GsonBuilder;
*
* @author Jan N. Klug - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@NonNullByDefault
public class LightsTest {
private @NonNullByDefault({}) Gson gson;
@Mock
private @NonNullByDefault({}) ThingHandlerCallback thingHandlerCallback;
private @Mock @NonNullByDefault({}) ThingHandlerCallback thingHandlerCallback;
private @Mock @NonNullByDefault({}) StateDescriptionProvider stateDescriptionProvider;
@Mock
private @NonNullByDefault({}) StateDescriptionProvider stateDescriptionProvider;
@Before
@BeforeEach
public void initialize() {
initMocks(this);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LightType.class, new LightTypeDeserializer());
gsonBuilder.registerTypeAdapter(ThermostatMode.class, new ThermostatModeGsonTypeAdapter());
@ -76,7 +72,7 @@ public class LightsTest {
@Test
public void colorTemperatureLightUpdateTest() throws IOException {
LightMessage lightMessage = DeconzTest.getObjectFromJson("colortemperature.json", LightMessage.class, gson);
Assert.assertNotNull(lightMessage);
assertNotNull(lightMessage);
ThingUID thingUID = new ThingUID("deconz", "light");
ChannelUID channelUID_bri = new ChannelUID(thingUID, CHANNEL_BRIGHTNESS);
@ -122,7 +118,7 @@ public class LightsTest {
@Test
public void dimmableLightUpdateTest() throws IOException {
LightMessage lightMessage = DeconzTest.getObjectFromJson("dimmable.json", LightMessage.class, gson);
Assert.assertNotNull(lightMessage);
assertNotNull(lightMessage);
ThingUID thingUID = new ThingUID("deconz", "light");
ChannelUID channelUID_bri = new ChannelUID(thingUID, CHANNEL_BRIGHTNESS);
@ -139,7 +135,7 @@ public class LightsTest {
@Test
public void dimmableLightOverrangeUpdateTest() throws IOException {
LightMessage lightMessage = DeconzTest.getObjectFromJson("dimmable_overrange.json", LightMessage.class, gson);
Assert.assertNotNull(lightMessage);
assertNotNull(lightMessage);
ThingUID thingUID = new ThingUID("deconz", "light");
ChannelUID channelUID_bri = new ChannelUID(thingUID, CHANNEL_BRIGHTNESS);
@ -156,7 +152,7 @@ public class LightsTest {
@Test
public void dimmableLightUnderrangeUpdateTest() throws IOException {
LightMessage lightMessage = DeconzTest.getObjectFromJson("dimmable_underrange.json", LightMessage.class, gson);
Assert.assertNotNull(lightMessage);
assertNotNull(lightMessage);
ThingUID thingUID = new ThingUID("deconz", "light");
ChannelUID channelUID_bri = new ChannelUID(thingUID, CHANNEL_BRIGHTNESS);
@ -173,7 +169,7 @@ public class LightsTest {
@Test
public void windowCoveringUpdateTest() throws IOException {
LightMessage lightMessage = DeconzTest.getObjectFromJson("windowcovering.json", LightMessage.class, gson);
Assert.assertNotNull(lightMessage);
assertNotNull(lightMessage);
ThingUID thingUID = new ThingUID("deconz", "light");
ChannelUID channelUID_pos = new ChannelUID(thingUID, CHANNEL_POSITION);

View File

@ -12,18 +12,19 @@
*/
package org.openhab.binding.deconz;
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.deconz.internal.BindingConstants.*;
import java.io.IOException;
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.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openhab.binding.deconz.internal.dto.SensorMessage;
import org.openhab.binding.deconz.internal.handler.SensorThermostatThingHandler;
import org.openhab.binding.deconz.internal.handler.SensorThingHandler;
@ -52,17 +53,15 @@ import com.google.gson.GsonBuilder;
* @author Jan N. Klug - Initial contribution
* @author Lukas Agethen - Added Thermostat
*/
@ExtendWith(MockitoExtension.class)
@NonNullByDefault
public class SensorsTest {
private @NonNullByDefault({}) Gson gson;
@Mock
private @NonNullByDefault({}) ThingHandlerCallback thingHandlerCallback;
private @Mock @NonNullByDefault({}) ThingHandlerCallback thingHandlerCallback;
@Before
@BeforeEach
public void initialize() {
initMocks(this);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(LightType.class, new LightTypeDeserializer());
gsonBuilder.registerTypeAdapter(ThermostatMode.class, new ThermostatModeGsonTypeAdapter());
@ -72,7 +71,7 @@ public class SensorsTest {
@Test
public void carbonmonoxideSensorUpdateTest() throws IOException {
SensorMessage sensorMessage = DeconzTest.getObjectFromJson("carbonmonoxide.json", SensorMessage.class, gson);
Assert.assertNotNull(sensorMessage);
assertNotNull(sensorMessage);
ThingUID thingUID = new ThingUID("deconz", "sensor");
ChannelUID channelUID = new ChannelUID(thingUID, "carbonmonoxide");
@ -88,7 +87,7 @@ public class SensorsTest {
@Test
public void thermostatSensorUpdateTest() throws IOException {
SensorMessage sensorMessage = DeconzTest.getObjectFromJson("thermostat.json", SensorMessage.class, gson);
Assert.assertNotNull(sensorMessage);
assertNotNull(sensorMessage);
ThingUID thingUID = new ThingUID("deconz", "sensor");
ChannelUID channelValveUID = new ChannelUID(thingUID, "valve");

View File

@ -13,9 +13,9 @@
package org.openhab.binding.dmx.internal;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.dmx.internal.action.ActionState;
import org.openhab.binding.dmx.internal.action.FadeAction;
import org.openhab.binding.dmx.internal.multiverse.DmxChannel;

View File

@ -13,9 +13,9 @@
package org.openhab.binding.dmx.internal;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.dmx.internal.multiverse.DmxChannel;
import org.openhab.core.library.types.PercentType;

View File

@ -13,11 +13,11 @@
package org.openhab.binding.dmx.internal;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Tests cases ValueSet

View File

@ -12,8 +12,9 @@
*/
package org.openhab.binding.dmx.internal.handler;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
@ -21,9 +22,9 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
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.openhab.core.config.core.Configuration;
import org.openhab.core.test.java.JavaTest;
import org.openhab.core.thing.Bridge;
@ -53,7 +54,7 @@ public class ArtnetBridgeHandlerTest extends JavaTest {
private Bridge bridge;
private ArtnetBridgeHandler bridgeHandler;
@Before
@BeforeEach
public void setUp() {
bridgeProperties = new HashMap<>();
bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
@ -79,7 +80,7 @@ public class ArtnetBridgeHandlerTest extends JavaTest {
bridgeHandler.initialize();
}
@After
@AfterEach
public void tearDown() {
bridgeHandler.dispose();
}

View File

@ -13,8 +13,8 @@
package org.openhab.binding.dmx.internal.handler;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
@ -24,8 +24,8 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.dmx.test.AbstractDmxThingTestParent;
import org.openhab.binding.dmx.test.TestBridgeHandler;
import org.openhab.core.config.core.Configuration;
@ -61,7 +61,7 @@ public class ChaserThingHandlerTest extends AbstractDmxThingTestParent {
private TestBridgeHandler dmxBridgeHandler;
private ChaserThingHandler chaserThingHandler;
@Before
@BeforeEach
public void setUp() {
super.setup();

View File

@ -12,17 +12,18 @@
*/
package org.openhab.binding.dmx.internal.handler;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.dmx.test.AbstractDmxThingTestParent;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.DecimalType;
@ -58,7 +59,7 @@ public class ColorThingHandlerTest extends AbstractDmxThingTestParent {
private final ChannelUID CHANNEL_UID_BRIGHTNESS_G = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_G);
private final ChannelUID CHANNEL_UID_BRIGHTNESS_B = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_B);
@Before
@BeforeEach
public void setUp() {
super.setup();
thingProperties = new HashMap<>();

View File

@ -12,17 +12,18 @@
*/
package org.openhab.binding.dmx.internal.handler;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.dmx.test.AbstractDmxThingTestParent;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.OnOffType;
@ -51,7 +52,7 @@ public class DimmerThingHandlerTest extends AbstractDmxThingTestParent {
private final ThingUID THING_UID_DIMMER = new ThingUID(THING_TYPE_DIMMER, "testdimmer");
private final ChannelUID CHANNEL_UID_BRIGHTNESS = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS);
@Before
@BeforeEach
public void setUp() {
super.setup();

View File

@ -12,8 +12,9 @@
*/
package org.openhab.binding.dmx.internal.handler;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
@ -21,10 +22,10 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openhab.binding.dmx.internal.DmxBridgeHandler;
import org.openhab.binding.dmx.internal.multiverse.BaseDmxChannel;
@ -93,7 +94,7 @@ public class DmxBridgeHandlerTest extends JavaTest {
private Bridge bridge;
private DmxBridgeHandlerImpl bridgeHandler;
@Before
@BeforeEach
public void setUp() {
bridgeProperties = new HashMap<>();
bridge = BridgeBuilder.create(THING_TYPE_TEST_BRIDGE, "testbridge").withLabel("Test Bridge")
@ -112,7 +113,7 @@ public class DmxBridgeHandlerTest extends JavaTest {
bridgeHandler.initialize();
}
@After
@AfterEach
public void tearDown() {
bridgeHandler.dispose();
}
@ -122,13 +123,13 @@ public class DmxBridgeHandlerTest extends JavaTest {
waitForAssert(() -> assertEquals(ThingStatus.ONLINE, bridge.getStatusInfo().getStatus()));
}
@Ignore("https://github.com/eclipse/smarthome/issues/6015#issuecomment-411313627")
@Disabled("https://github.com/eclipse/smarthome/issues/6015#issuecomment-411313627")
@Test
public void assertSendDmxDataIsCalled() {
Mockito.verify(bridgeHandler, after(500).atLeast(9)).sendDmxData();
}
@Ignore("https://github.com/eclipse/smarthome/issues/6015")
@Disabled("https://github.com/eclipse/smarthome/issues/6015")
@Test
public void assertMuteChannelMutesOutput() {
bridgeHandler.handleCommand(CHANNEL_UID_MUTE, OnOffType.ON);

View File

@ -12,7 +12,7 @@
*/
package org.openhab.binding.dmx.internal.handler;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
@ -20,9 +20,9 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
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.openhab.core.config.core.Configuration;
import org.openhab.core.test.java.JavaTest;
import org.openhab.core.thing.Bridge;
@ -51,7 +51,7 @@ public class Lib485BridgeHandlerTest extends JavaTest {
private Bridge bridge;
private Lib485BridgeHandler bridgeHandler;
@Before
@BeforeEach
public void setUp() {
bridgeProperties = new HashMap<>();
bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
@ -76,7 +76,7 @@ public class Lib485BridgeHandlerTest extends JavaTest {
bridgeHandler.initialize();
}
@After
@AfterEach
public void tearDown() {
bridgeHandler.dispose();
}

View File

@ -12,8 +12,9 @@
*/
package org.openhab.binding.dmx.internal.handler;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
@ -21,9 +22,9 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
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.openhab.core.config.core.Configuration;
import org.openhab.core.test.java.JavaTest;
import org.openhab.core.thing.Bridge;
@ -52,7 +53,7 @@ public class SacnBridgeHandlerTest extends JavaTest {
private Bridge bridge;
private SacnBridgeHandler bridgeHandler;
@Before
@BeforeEach
public void setUp() {
bridgeProperties = new HashMap<>();
bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
@ -79,7 +80,7 @@ public class SacnBridgeHandlerTest extends JavaTest {
bridgeHandler.initialize();
}
@After
@AfterEach
public void tearDown() {
bridgeHandler.dispose();
}

View File

@ -12,17 +12,18 @@
*/
package org.openhab.binding.dmx.internal.handler;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.dmx.test.AbstractDmxThingTestParent;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.OnOffType;
@ -54,7 +55,7 @@ public class TunableWhiteThingHandlerTest extends AbstractDmxThingTestParent {
private final ChannelUID CHANNEL_UID_BRIGHTNESS_WW = new ChannelUID(THING_UID_DIMMER, CHANNEL_BRIGHTNESS_WW);
private final ChannelUID CHANNEL_UID_COLOR_TEMP = new ChannelUID(THING_UID_DIMMER, CHANNEL_COLOR_TEMPERATURE);
@Before
@BeforeEach
public void setUp() {
super.setup();

View File

@ -13,11 +13,11 @@
package org.openhab.binding.dmx.internal.multiverse;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Tests cases for BaseChannel

View File

@ -13,10 +13,10 @@
package org.openhab.binding.dmx.internal.multiverse;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openhab.binding.dmx.internal.DmxBindingConstants.ListenerType;
import org.openhab.binding.dmx.internal.action.FadeAction;
@ -37,7 +37,7 @@ public class DmxChannelTest {
DimmerThingHandler dimmerThingHandler;
long currentTime;
@Before
@BeforeEach
public void setup() {
dimmerThingHandler = Mockito.mock(DimmerThingHandler.class);
dmxChannel = new DmxChannel(0, 1, 0);

View File

@ -12,9 +12,10 @@
*/
package org.openhab.binding.dmx.test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.openhab.binding.dmx.test.TestBridgeHandler.THING_TYPE_TEST_BRIDGE;

View File

@ -12,10 +12,10 @@
*/
package org.openhab.binding.doorbird.internal;
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.doorbird.internal.api.DoorbirdInfo;
/**

View File

@ -12,10 +12,10 @@
*/
package org.openhab.binding.doorbird.internal;
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.doorbird.internal.api.SipStatus;
/**

View File

@ -13,10 +13,10 @@
package org.openhab.binding.draytonwiser.internal.discovery;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.doReturn;
import static org.mockito.MockitoAnnotations.initMocks;
import java.io.IOException;
import java.net.URISyntaxException;
@ -28,17 +28,18 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpContentResponse;
import org.eclipse.jetty.client.HttpResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.server.Response;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openhab.binding.draytonwiser.internal.DraytonWiserBindingConstants;
import org.openhab.binding.draytonwiser.internal.api.DraytonWiserApi;
import org.openhab.binding.draytonwiser.internal.api.DraytonWiserApiException;
@ -55,35 +56,22 @@ import org.openhab.core.thing.ThingUID;
*
* @author Hilbrand Bouwkamp - Initial contribution
*/
@RunWith(Parameterized.class)
@ExtendWith(MockitoExtension.class)
public class DraytonWiserDiscoveryServiceTest {
@Mock
private HeatHubHandler bridgeHandler;
@Mock
private Bridge bridge;
@Mock
private HttpClient httpClient;
@Mock
private Request request;
private @Mock HeatHubHandler bridgeHandler;
private @Mock Bridge bridge;
private @Mock HttpClient httpClient;
private @Mock Request request;
private DraytonWiserApi api;
private final String jsonFile;
private final int expectedResults;
public DraytonWiserDiscoveryServiceTest(final String jsonFile, final int expectedResults) {
this.jsonFile = jsonFile;
this.expectedResults = expectedResults;
}
@Parameters(name = "{0}")
public static List<Object[]> data() {
return Arrays.asList(new Object[] { "../test1.json", 11 }, new Object[] { "../test2.json", 22 });
}
@Before
@BeforeEach
public void before() {
initMocks(this);
api = new DraytonWiserApi(httpClient);
api.setConfiguration(new HeatHubConfiguration());
@ -96,12 +84,13 @@ public class DraytonWiserDiscoveryServiceTest {
doReturn(new ThingUID(DraytonWiserBindingConstants.THING_TYPE_BRIDGE, "1")).when(bridge).getUID();
}
@Test
public void testDiscovery() throws IOException, URISyntaxException, InterruptedException, TimeoutException,
ExecutionException, DraytonWiserApiException {
@ParameterizedTest
@MethodSource("data")
public void testDiscovery(final String jsonFile, final int expectedResults) throws IOException, URISyntaxException,
InterruptedException, TimeoutException, ExecutionException, DraytonWiserApiException {
final byte[] content = Files.readAllBytes(Paths.get(getClass().getResource(jsonFile).toURI()));
final HttpResponse response = new HttpResponse(null, null);
response.status(Response.SC_OK);
response.status(HttpServletResponse.SC_OK);
doReturn(new HttpContentResponse(response, content, null, null)).when(request).send();
final List<DiscoveryResult> discoveryResults = new ArrayList<>();
final DraytonWiserDiscoveryService service = new DraytonWiserDiscoveryService() {

View File

@ -12,7 +12,7 @@
*/
package org.openhab.binding.dsmr.internal;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import java.io.InputStream;
@ -63,9 +63,9 @@ public final class TelegramReaderUtil {
parser.setLenientMode(true);
parser.parse(telegram, telegram.length);
assertNotNull("Telegram state should have been set. (Missing newline at end of message?)", p1Telegram.get());
assertEquals("Expected TelegramState should be as expected", expectedTelegramState,
p1Telegram.get().getTelegramState());
assertNotNull(p1Telegram.get(), "Telegram state should have been set. (Missing newline at end of message?)");
assertEquals(expectedTelegramState, p1Telegram.get().getTelegramState(),
"Expected TelegramState should be as expected");
return p1Telegram.get();
}
}

View File

@ -12,10 +12,9 @@
*/
package org.openhab.binding.dsmr.internal.device;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -25,9 +24,11 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Test;
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.junit.jupiter.MockitoExtension;
import org.openhab.binding.dsmr.internal.DSMRBindingConstants;
import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
import org.openhab.binding.dsmr.internal.device.DSMRSerialAutoDevice.DeviceState;
@ -45,22 +46,20 @@ import org.openhab.core.io.transport.serial.SerialPortManager;
*
* @author Hilbrand Bouwkamp - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
public class DSMRSerialAutoDeviceTest {
private static final String DUMMY_PORTNAME = "/dev/dummy-serial";
private static final String TELEGRAM_NAME = "dsmr_50";
@Mock
private SerialPortIdentifier mockIdentifier;
@Mock
private ScheduledExecutorService scheduler;
@Mock
private SerialPort mockSerialPort;
private @Mock SerialPortIdentifier mockIdentifier;
private @Mock ScheduledExecutorService scheduler;
private @Mock SerialPort mockSerialPort;
private SerialPortManager serialPortManager = new SerialPortManager() {
@Override
public SerialPortIdentifier getIdentifier(String name) {
assertEquals("Expect the passed serial port name", DUMMY_PORTNAME, name);
assertEquals(DUMMY_PORTNAME, name, "Expect the passed serial port name");
return mockIdentifier;
}
@ -71,9 +70,8 @@ public class DSMRSerialAutoDeviceTest {
};
private SerialPortEventListener serialPortEventListener;
@Before
@BeforeEach
public void setUp() throws PortInUseException, TooManyListenersException {
initMocks(this);
doAnswer(a -> {
serialPortEventListener = a.getArgument(0);
return null;
@ -100,18 +98,18 @@ public class DSMRSerialAutoDeviceTest {
DSMRSerialAutoDevice device = new DSMRSerialAutoDevice(serialPortManager, DUMMY_PORTNAME, listener,
new DSMRTelegramListener(), scheduler, 1);
device.start();
assertSame("Expect to be starting discovery state", DeviceState.DISCOVER_SETTINGS, device.getState());
assertSame(DeviceState.DISCOVER_SETTINGS, device.getState(), "Expect to be starting discovery state");
serialPortEventListener
.serialEvent(new MockSerialPortEvent(mockSerialPort, SerialPortEvent.BI, false, true));
assertSame("Expect to be still in discovery state", DeviceState.DISCOVER_SETTINGS, device.getState());
assertSame(DeviceState.DISCOVER_SETTINGS, device.getState(), "Expect to be still in discovery state");
serialPortEventListener
.serialEvent(new MockSerialPortEvent(mockSerialPort, SerialPortEvent.DATA_AVAILABLE, false, true));
assertSame("Expect to be in normal state", DeviceState.NORMAL, device.getState());
assertSame(DeviceState.NORMAL, device.getState(), "Expect to be in normal state");
device.restart();
assertSame("Expect not to start rediscovery when in normal state", DeviceState.NORMAL, device.getState());
assertSame(DeviceState.NORMAL, device.getState(), "Expect not to start rediscovery when in normal state");
device.stop();
}
assertNotNull("Expected to have read a telegram", telegramRef.get());
assertNotNull(telegramRef.get(), "Expected to have read a telegram");
}
@Test
@ -137,19 +135,19 @@ public class DSMRSerialAutoDeviceTest {
DSMRSerialAutoDevice device = new DSMRSerialAutoDevice(serialPortManager, DUMMY_PORTNAME, listener,
new DSMRTelegramListener(), scheduler, 1);
device.start();
assertSame("Expected an error", DSMRConnectorErrorEvent.IN_USE, eventRef.get());
assertSame("Expect to be in error state", DeviceState.ERROR, device.getState());
assertSame(DSMRConnectorErrorEvent.IN_USE, eventRef.get(), "Expected an error");
assertSame(DeviceState.ERROR, device.getState(), "Expect to be in error state");
// Trigger device to restart
mockValidSerialPort();
device.restart();
assertSame("Expect to be starting discovery state", DeviceState.DISCOVER_SETTINGS, device.getState());
assertSame(DeviceState.DISCOVER_SETTINGS, device.getState(), "Expect to be starting discovery state");
// Trigger device to go into error stage with port doesn't exist.
mockIdentifier = null;
device = new DSMRSerialAutoDevice(serialPortManager, DUMMY_PORTNAME, listener, new DSMRTelegramListener(),
scheduler, 1);
device.start();
assertSame("Expected an error", DSMRConnectorErrorEvent.DONT_EXISTS, eventRef.get());
assertSame("Expect to be in error state", DeviceState.ERROR, device.getState());
assertSame(DSMRConnectorErrorEvent.DONT_EXISTS, eventRef.get(), "Expected an error");
assertSame(DeviceState.ERROR, device.getState(), "Expect to be in error state");
}
}

View File

@ -13,13 +13,13 @@
package org.openhab.binding.dsmr.internal.device;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1TelegramListener;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1TelegramParser;

View File

@ -12,16 +12,13 @@
*/
package org.openhab.binding.dsmr.internal.device.p1telegram;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram.TelegramState;
@ -30,11 +27,9 @@ import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram.TelegramSt
*
* @author Hilbrand Bouwkamp - Initial contribution
*/
@RunWith(value = Parameterized.class)
public class P1TelegramParserTest {
// @formatter:off
@Parameters(name = "{0}")
public static final List<Object[]> data() {
return Arrays.asList(new Object[][] {
{ "ace4000", 59, },
@ -52,17 +47,13 @@ public class P1TelegramParserTest {
}
// @formatter:on
@Parameter(0)
public String telegramName;
@Parameter(1)
public int numberOfCosemObjects;
@Test
public void testParsing() {
@ParameterizedTest
@MethodSource("data")
public void testParsing(final String telegramName, final int numberOfCosemObjects) {
P1Telegram telegram = TelegramReaderUtil.readTelegram(telegramName, TelegramState.OK);
assertEquals("Should not have any unknown cosem objects", 0, telegram.getUnknownCosemObjects().size());
assertEquals("Expected number of objects", numberOfCosemObjects,
telegram.getCosemObjects().stream().mapToInt(co -> co.getCosemValues().size()).sum());
assertEquals(0, telegram.getUnknownCosemObjects().size(), "Should not have any unknown cosem objects");
assertEquals(numberOfCosemObjects,
telegram.getCosemObjects().stream().mapToInt(co -> co.getCosemValues().size()).sum(),
"Expected number of objects");
}
}

View File

@ -12,7 +12,7 @@
*/
package org.openhab.binding.dsmr.internal.discovery;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.openhab.binding.dsmr.internal.meter.DSMRMeterType.*;
import java.util.Arrays;
@ -24,11 +24,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
import org.openhab.binding.dsmr.internal.device.cosem.CosemObject;
import org.openhab.binding.dsmr.internal.device.cosem.CosemObjectType;
@ -42,11 +39,9 @@ import org.openhab.binding.dsmr.internal.meter.DSMRMeterType;
*
* @author Hilbrand Bouwkamp - Initial contribution
*/
@RunWith(value = Parameterized.class)
public class DSMRMeterDetectorTest {
// @formatter:off
@Parameters(name = "{0}")
public static final List<Object[]> data() {
return Arrays.asList(new Object[][] {
{ "ace4000", EnumSet.of( ELECTRICITY_ACE4000, GAS_ACE4000)},
@ -64,30 +59,26 @@ public class DSMRMeterDetectorTest {
}
// @formatter:on
@Parameter(0)
public String telegramName;
@Parameter(1)
public Set<DSMRMeterType> expectedMeters;
@Test
public void testDetectMeters() {
@ParameterizedTest
@MethodSource("data")
public void testDetectMeters(final String telegramName, final Set<DSMRMeterType> expectedMeters) {
P1Telegram telegram = TelegramReaderUtil.readTelegram(telegramName, TelegramState.OK);
DSMRMeterDetector detector = new DSMRMeterDetector();
Entry<Collection<DSMRMeterDescriptor>, Map<CosemObjectType, CosemObject>> entry = detector
.detectMeters(telegram);
Collection<DSMRMeterDescriptor> detectMeters = entry.getKey();
assertEquals("Should detect correct number of meters: " + Arrays.toString(detectMeters.toArray()),
expectedMeters.size(), detectMeters.size());
assertEquals("Should not have any undetected cosem objects: ", Collections.emptyMap(), entry.getValue());
assertEquals("Should not have any unknown cosem objects", Collections.emptyList(),
telegram.getUnknownCosemObjects());
assertEquals(expectedMeters.size(), detectMeters.size(),
"Should detect correct number of meters: " + Arrays.toString(detectMeters.toArray()));
assertEquals(Collections.emptyMap(), entry.getValue(), "Should not have any undetected cosem objects: ");
assertEquals(Collections.emptyList(), telegram.getUnknownCosemObjects(),
"Should not have any unknown cosem objects");
for (DSMRMeterType meter : expectedMeters) {
assertEquals(
1, detectMeters.stream().filter(e -> e.getMeterType() == meter).count(),
String.format("Meter '%s' not found: %s", meter,
Arrays.toString(detectMeters.toArray(new DSMRMeterDescriptor[0]))),
1, detectMeters.stream().filter(e -> e.getMeterType() == meter).count());
Arrays.toString(detectMeters.toArray(new DSMRMeterDescriptor[0]))));
}
}
}

View File

@ -12,24 +12,23 @@
*/
package org.openhab.binding.dsmr.internal.discovery;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.openhab.binding.dsmr.internal.meter.DSMRMeterType.*;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import java.util.TooManyListenersException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram.TelegramState;
@ -37,7 +36,6 @@ import org.openhab.binding.dsmr.internal.handler.DSMRBridgeHandler;
import org.openhab.binding.dsmr.internal.handler.DSMRMeterHandler;
import org.openhab.binding.dsmr.internal.meter.DSMRMeterDescriptor;
import org.openhab.binding.dsmr.internal.meter.DSMRMeterType;
import org.openhab.core.io.transport.serial.PortInUseException;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingUID;
@ -46,22 +44,15 @@ import org.openhab.core.thing.ThingUID;
*
* @author Hilbrand Bouwkamp - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
public class DSMRMeterDiscoveryServiceTest {
private static final String EXPECTED_CONFIGURED_TELEGRAM = "dsmr_50";
private static final String UNREGISTERED_METER_TELEGRAM = "unregistered_meter";
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private DSMRBridgeHandler bridge;
@Mock
private Thing thing;
@Mock
private DSMRMeterHandler meterHandler;
@Before
public void setUp() throws PortInUseException, TooManyListenersException {
initMocks(this);
}
private @Mock(answer = Answers.RETURNS_DEEP_STUBS) DSMRBridgeHandler bridge;
private @Mock Thing thing;
private @Mock DSMRMeterHandler meterHandler;
/**
* Test if discovery reports when the user has incorrectly configured the binding with the wrong meter types.
@ -100,12 +91,12 @@ public class DSMRMeterDiscoveryServiceTest {
when(bridge.getThing().getThings()).thenReturn(things);
service.telegramReceived(expected);
assertNotNull("Should have invalid configured meters", invalidConfiguredRef.get());
assertTrue("Should have found specific invalid meter",
invalidConfiguredRef.get().contains(DSMRMeterType.ELECTRICITY_V4_2));
assertNotNull("Should have undetected meters", unconfiguredRef.get());
assertTrue("Should have found specific undetected meter",
unconfiguredRef.get().contains(DSMRMeterType.ELECTRICITY_V5_0));
assertNotNull(invalidConfiguredRef.get(), "Should have invalid configured meters");
assertTrue(invalidConfiguredRef.get().contains(DSMRMeterType.ELECTRICITY_V4_2),
"Should have found specific invalid meter");
assertNotNull(unconfiguredRef.get(), "Should have undetected meters");
assertTrue(unconfiguredRef.get().contains(DSMRMeterType.ELECTRICITY_V5_0),
"Should have found specific undetected meter");
}
/**
@ -128,6 +119,6 @@ public class DSMRMeterDiscoveryServiceTest {
when(bridge.getThing().getThings()).thenReturn(Collections.emptyList());
service.telegramReceived(telegram);
assertTrue("Should have found an unregistered meter", unregisteredMeter.get());
assertTrue(unregisteredMeter.get(), "Should have found an unregistered meter");
}
}

View File

@ -12,12 +12,12 @@
*/
package org.openhab.binding.dsmr.internal.meter;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
import org.openhab.binding.dsmr.internal.device.cosem.CosemObject;
import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram.TelegramState;
@ -40,7 +40,7 @@ public class DSMRMeterTest {
List<CosemObject> filterMeterValues = meter
.filterMeterValues(TelegramReaderUtil.readTelegram("dsmr_50", TelegramState.OK).getCosemObjects());
assertEquals("Filter should return all required objects", DSMRMeterType.DEVICE_V5.requiredCosemObjects.length,
filterMeterValues.size());
assertEquals(DSMRMeterType.DEVICE_V5.requiredCosemObjects.length, filterMeterValues.size(),
"Filter should return all required objects");
}
}

View File

@ -13,10 +13,9 @@
package org.openhab.binding.dwdunwetter;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;
import java.io.InputStream;
import java.util.List;
@ -26,10 +25,14 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.lang.StringUtils;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
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.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.openhab.binding.dwdunwetter.internal.DwdUnwetterBindingConstants;
import org.openhab.binding.dwdunwetter.internal.handler.DwdUnwetterHandler;
import org.openhab.core.config.core.Configuration;
@ -51,19 +54,17 @@ import org.w3c.dom.NodeList;
*
* @author Martin Koehler - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
public class DwdUnwetterHandlerTest extends JavaTest {
private ThingHandler handler;
@Mock
private ThingHandlerCallback callback;
private @Mock ThingHandlerCallback callback;
private @Mock Thing thing;
@Mock
private Thing thing;
@Before
@BeforeEach
public void setUp() {
initMocks(this);
handler = new DwdUnwetterHandler(thing);
handler.setCallback(callback);
// mock getConfiguration to prevent NPEs

View File

@ -13,12 +13,12 @@
package org.openhab.binding.dwdunwetter.internal.data;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.time.Instant;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link DwdWarningCache}
@ -29,7 +29,7 @@ public class DwdWarningCacheTest {
private DwdWarningCache cache;
@Before
@BeforeEach
public void setUp() {
cache = new DwdWarningCache();
}

View File

@ -13,7 +13,7 @@
package org.openhab.binding.dwdunwetter.internal.data;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.BufferedReader;
import java.io.IOException;
@ -23,8 +23,8 @@ import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.time.ZoneId;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.types.UnDefType;
@ -47,7 +47,7 @@ public class DwdWarningsDataTest {
private TestDataProvider testDataProvider;
private DwdWarningsData warningsData;
@Before
@BeforeEach
public void setUp() throws IOException {
this.testDataProvider = new TestDataProvider();
loadXmlFromFile();

View File

@ -12,14 +12,15 @@
*/
package org.openhab.binding.enigma2.actions;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.enigma2.handler.Enigma2Handler;
import org.openhab.binding.enigma2.internal.Enigma2BindingConstants;
@ -37,7 +38,7 @@ public class Enigma2ActionsTest {
private Enigma2Handler enigma2Handler;
public static final String SOME_TEXT = "some Text";
@Before
@BeforeEach
public void setUp() {
enigma2Handler = mock(Enigma2Handler.class);
enigma2Actions = new Enigma2Actions();
@ -109,9 +110,9 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendRcCommand("KEY_1");
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSendRcCommandStaticWithException() {
Enigma2Actions.sendRcCommand(null, "KEY_1");
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendRcCommand(null, "KEY_1"));
}
@Test
@ -126,9 +127,9 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendInfo(10, SOME_TEXT);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSendInfoStaticWithException() {
Enigma2Actions.sendInfo(null, SOME_TEXT);
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendInfo(null, SOME_TEXT));
}
@Test
@ -143,9 +144,9 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendError(10, SOME_TEXT);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSendErrorStaticWithException() {
Enigma2Actions.sendError(null, SOME_TEXT);
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendError(null, SOME_TEXT));
}
@Test
@ -160,9 +161,9 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendWarning(10, SOME_TEXT);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSendWarningStaticWithException() {
Enigma2Actions.sendWarning(null, SOME_TEXT);
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendWarning(null, SOME_TEXT));
}
@Test
@ -177,8 +178,8 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendQuestion(10, SOME_TEXT);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testSendQuestionStaticWithException() {
Enigma2Actions.sendQuestion(null, SOME_TEXT);
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendQuestion(null, SOME_TEXT));
}
}

View File

@ -13,8 +13,8 @@
package org.openhab.binding.enigma2.handler;
import static org.eclipse.jdt.annotation.Checks.requireNonNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.time.LocalDateTime;
@ -23,15 +23,20 @@ import java.util.Optional;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.enigma2.actions.Enigma2Actions;
import org.openhab.binding.enigma2.internal.Enigma2BindingConstants;
import org.openhab.binding.enigma2.internal.Enigma2Client;
import org.openhab.binding.enigma2.internal.Enigma2Configuration;
import org.openhab.binding.enigma2.internal.Enigma2RemoteKey;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.*;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.NextPreviousType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.PlayPauseType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.binding.ThingHandlerCallback;
@ -58,7 +63,7 @@ public class Enigma2HandlerTest {
@Nullable
private ThingHandlerCallback callback;
@Before
@BeforeEach
public void setUp() {
enigma2Client = mock(Enigma2Client.class);
thing = mock(Thing.class);

View File

@ -13,8 +13,9 @@
package org.openhab.binding.enigma2.internal;
import static org.eclipse.jdt.annotation.Checks.requireNonNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
import java.io.IOException;
@ -22,8 +23,8 @@ import java.time.LocalDateTime;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* The {@link Enigma2ClientTest} class is responsible for testing {@link Enigma2Client}.
@ -41,7 +42,7 @@ public class Enigma2ClientTest {
@Nullable
private Enigma2HttpClient enigma2HttpClient;
@Before
@BeforeEach
public void setUp() throws IOException {
enigma2HttpClient = mock(Enigma2HttpClient.class);
enigma2Client = spy(new Enigma2Client("localhost:8080", "user", "password", 5));

View File

@ -13,15 +13,14 @@
package org.openhab.binding.enigma2.internal;
import static org.eclipse.jdt.annotation.Checks.requireNonNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
import static org.openhab.binding.enigma2.internal.Enigma2BindingConstants.THING_TYPE_DEVICE;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;

View File

@ -12,11 +12,11 @@
*/
package org.openhab.binding.enigma2.internal;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* The {@link Enigma2RemoteKeyTest} class is responsible for testing {@link Enigma2RemoteKey}.

View File

@ -13,10 +13,9 @@
package org.openhab.binding.enigma2.internal.discovery;
import static org.eclipse.jdt.annotation.Checks.requireNonNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when;
import java.net.Inet4Address;
import java.net.InetAddress;
@ -25,8 +24,8 @@ import javax.jmdns.ServiceInfo;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.enigma2.internal.Enigma2BindingConstants;
import org.openhab.binding.enigma2.internal.Enigma2HttpClient;
import org.openhab.core.config.discovery.DiscoveryResult;
@ -47,7 +46,7 @@ public class Enigma2DiscoveryParticipantTest {
@Nullable
private Enigma2DiscoveryParticipant enigma2DiscoveryParticipant;
@Before
@BeforeEach
public void setUp() {
enigma2HttpClient = mock(Enigma2HttpClient.class);
serviceInfo = mock(ServiceInfo.class);

View File

@ -12,7 +12,7 @@
*/
package org.openhab.binding.fmiweather;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;
import java.io.BufferedReader;
import java.io.IOException;
@ -30,7 +30,7 @@ import org.eclipse.jdt.annotation.Nullable;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.openhab.binding.fmiweather.internal.client.Client;
import org.openhab.binding.fmiweather.internal.client.Data;
import org.openhab.binding.fmiweather.internal.client.FMIResponse;
@ -47,7 +47,7 @@ public class AbstractFMIResponseParsingTest {
@NonNullByDefault({})
protected Client client;
@Before
@BeforeEach
public void setUpClient() {
client = new Client();
}

View File

@ -13,7 +13,7 @@
package org.openhab.binding.fmiweather;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.math.BigDecimal;
import java.util.AbstractMap;
@ -22,7 +22,7 @@ import java.util.List;
import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.fmiweather.internal.client.FMISID;
import org.openhab.binding.fmiweather.internal.client.ForecastRequest;
import org.openhab.binding.fmiweather.internal.client.LatLon;

View File

@ -13,12 +13,13 @@
package org.openhab.binding.fmiweather;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.nio.file.Path;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.fmiweather.internal.client.Client;
import org.openhab.binding.fmiweather.internal.client.FMIResponse;
@ -33,7 +34,7 @@ public class FMIResponseParsingEmptyTest extends AbstractFMIResponseParsingTest
private FMIResponse observationsResponse;
@Before
@BeforeEach
public void setUp() {
client = new Client();
try {

View File

@ -13,12 +13,13 @@
package org.openhab.binding.fmiweather;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import java.nio.file.Path;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.fmiweather.internal.client.exception.FMIResponseException;
/**

View File

@ -12,11 +12,12 @@
*/
package org.openhab.binding.fmiweather;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.nio.file.Path;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.fmiweather.internal.client.exception.FMIResponseException;
import org.xml.sax.SAXParseException;
@ -30,13 +31,15 @@ public class FMIResponseParsingInvalidOrUnexpectedXmlTest extends AbstractFMIRes
private Path observations1 = getTestResource("observations_single_place.xml");
@Test(expected = SAXParseException.class)
public void testInvalidXml() throws IOException, Throwable {
parseMultiPointCoverageXml(readTestResourceUtf8(observations1).replace("276.0", "<<"));
@Test
public void testInvalidXml() {
assertThrows(SAXParseException.class,
() -> parseMultiPointCoverageXml(readTestResourceUtf8(observations1).replace("276.0", "<<")));
}
@Test(expected = FMIResponseException.class)
public void testUnexpectedXml() throws IOException, Throwable {
parseMultiPointCoverageXml(readTestResourceUtf8(observations1).replace("276.0", "<foo>4</foo>"));
@Test
public void testUnexpectedXml() {
assertThrows(FMIResponseException.class,
() -> parseMultiPointCoverageXml(readTestResourceUtf8(observations1).replace("276.0", "<foo>4</foo>")));
}
}

View File

@ -13,7 +13,7 @@
package org.openhab.binding.fmiweather;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.math.BigDecimal;
import java.nio.file.Path;
@ -21,8 +21,8 @@ import java.util.Optional;
import java.util.Set;
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.fmiweather.internal.client.Data;
import org.openhab.binding.fmiweather.internal.client.FMIResponse;
import org.openhab.binding.fmiweather.internal.client.Location;
@ -60,7 +60,7 @@ public class FMIResponseParsingMultiplePlacesTest extends AbstractFMIResponsePar
private Location pointWithNoName = new Location("19.9,61.0973", "61.09726,19.90000", new BigDecimal("61.09726"),
new BigDecimal("19.90000"));
@Before
@BeforeEach
public void setUp() {
try {
observationsMultiplePlacesResponse = parseMultiPointCoverageXml(

View File

@ -13,7 +13,8 @@
package org.openhab.binding.fmiweather;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.math.BigDecimal;
import java.nio.file.Path;
@ -21,8 +22,8 @@ import java.util.Optional;
import java.util.Set;
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.fmiweather.internal.client.Data;
import org.openhab.binding.fmiweather.internal.client.FMIResponse;
import org.openhab.binding.fmiweather.internal.client.Location;
@ -46,7 +47,7 @@ public class FMIResponseParsingSinglePlaceTest extends AbstractFMIResponseParsin
private Location emasalo = new Location("Porvoo Emäsalo", "101023", new BigDecimal("60.20382"),
new BigDecimal("25.62546"));
@Before
@BeforeEach
public void setUp() {
try {
observationsResponse1 = parseMultiPointCoverageXml(readTestResourceUtf8(observations1));

View File

@ -13,14 +13,15 @@
package org.openhab.binding.fmiweather;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.math.BigDecimal;
import java.nio.file.Path;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.fmiweather.internal.client.Location;
/**

View File

@ -12,14 +12,14 @@
*/
package org.openhab.binding.foobot.internal.handler;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.openhab.binding.foobot.internal.FoobotApiConnector;
import org.openhab.binding.foobot.internal.FoobotApiException;
@ -50,7 +50,7 @@ public class FoobotAccountHandlerTest {
public void testSensorDataToState() throws IOException, FoobotApiException {
final List<FoobotDevice> deviceList = handler.getDeviceList();
assertFalse("Device list should not return empty", deviceList.isEmpty());
assertEquals("1234567890ABCDEF", deviceList.get(0).getUuid());
assertFalse(deviceList.isEmpty(), "Device list should not return empty");
assertEquals(deviceList.get(0).getUuid(), "1234567890ABCDEF");
}
}

View File

@ -12,13 +12,13 @@
*/
package org.openhab.binding.foobot.internal.handler;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.openhab.binding.foobot.internal.FoobotApiConnector;
import org.openhab.binding.foobot.internal.FoobotApiException;
@ -52,7 +52,7 @@ public class FoobotDeviceHandlerTest {
public void testSensorDataToState() throws IOException, FoobotApiException {
final FoobotJsonData sensorData = connector.getSensorData("1234");
assertNotNull("No sensor data read", sensorData);
assertNotNull(sensorData, "No sensor data read");
assertEquals(handler.sensorDataToState("temperature", sensorData), new QuantityType(12.345, SIUnits.CELSIUS));
assertEquals(handler.sensorDataToState("gpi", sensorData), new DecimalType(5.6789012));
}

View File

@ -12,9 +12,10 @@
*/
package org.openhab.binding.freebox.internal.api;
import static org.junit.jupiter.api.Assertions.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*
@ -27,6 +28,6 @@ public class FreeboxApiManagerTest {
public void hmacSha1Test() throws Exception {
String expected = "25dad1bb5604321f12b755cc9d755d1480cf7989";
String actual = FreeboxApiManager.hmacSha1("Token1234", "Challenge");
Assert.assertEquals(expected, actual);
assertEquals(expected, actual);
}
}

View File

@ -12,14 +12,14 @@
*/
package org.openhab.binding.fsinternetradio.test;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.jupnp.model.meta.DeviceDetails;
import org.jupnp.model.meta.ManufacturerDetails;
@ -80,7 +80,7 @@ public class FSInternetRadioDiscoveryParticipantJavaTest {
String DEFAULT_RADIO_THING_UID = String.format("%s:%s:%s", RADIO_BINDING_ID, RADIO_THING_TYPE_ID,
DEFAULT_RADIO_SERIAL_NUMBER);
@Before
@BeforeEach
public void setUp() {
discoveryParticipant = new FSInternetRadioDiscoveryParticipant();
}

View File

@ -13,7 +13,8 @@
package org.openhab.binding.fsinternetradio.test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.*;
import static org.openhab.binding.fsinternetradio.internal.FSInternetRadioBindingConstants.*;
@ -29,11 +30,10 @@ import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.openhab.binding.fsinternetradio.internal.FSInternetRadioBindingConstants;
import org.openhab.binding.fsinternetradio.internal.handler.FSInternetRadioHandler;
@ -124,7 +124,7 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
private static final String DEFAULT_CONFIG_PROPERTY_REFRESH = "1";
private static final Configuration DEFAULT_COMPLETE_CONFIGURATION = createDefaultConfiguration();
@BeforeClass
@BeforeAll
public static void setUpClass() throws Exception {
ServletHolder holder = new ServletHolder(radioServiceDummy);
server = new TestServer(DEFAULT_CONFIG_PROPERTY_IP, DEFAULT_CONFIG_PROPERTY_PORT, TIMEOUT, holder);
@ -134,12 +134,12 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
httpClient.start();
}
@Before
@BeforeEach
public void setUp() {
createThePowerChannel();
}
@AfterClass
@AfterAll
public static void tearDownClass() throws Exception {
server.stopServer();
httpClient.stop();
@ -147,13 +147,13 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
private static @NonNull Channel getChannel(final @NonNull Thing thing, final @NonNull String channelId) {
final Channel channel = thing.getChannel(channelId);
Assert.assertNotNull(channel);
assertNotNull(channel);
return channel;
}
private static @NonNull ChannelUID getChannelUID(final @NonNull Thing thing, final @NonNull String channelId) {
final ChannelUID channelUID = getChannel(thing, channelId).getUID();
Assert.assertNotNull(channelUID);
assertNotNull(channelUID);
return channelUID;
}
@ -290,15 +290,15 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
radioHandler.handleCommand(powerChannelUID, OnOffType.ON);
waitForAssert(() -> {
assertTrue("We should be able to turn on the radio",
radioServiceDummy.containsRequestParameter(1, CHANNEL_POWER));
assertTrue(radioServiceDummy.containsRequestParameter(1, CHANNEL_POWER),
"We should be able to turn on the radio");
radioServiceDummy.clearRequestParameters();
});
radioHandler.handleCommand(powerChannelUID, OnOffType.OFF);
waitForAssert(() -> {
assertTrue("We should be able to turn off the radio",
radioServiceDummy.containsRequestParameter(0, CHANNEL_POWER));
assertTrue(radioServiceDummy.containsRequestParameter(0, CHANNEL_POWER),
"We should be able to turn off the radio");
radioServiceDummy.clearRequestParameters();
});
@ -308,8 +308,8 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
*/
radioHandler.handleCommand(powerChannelUID, OnOffType.ON);
waitForAssert(() -> {
assertTrue("We should be able to turn on the radio",
radioServiceDummy.containsRequestParameter(1, CHANNEL_POWER));
assertTrue(radioServiceDummy.containsRequestParameter(1, CHANNEL_POWER),
"We should be able to turn on the radio");
radioServiceDummy.clearRequestParameters();
});
}
@ -333,15 +333,15 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
radioHandler.handleCommand(muteChannelUID, OnOffType.ON);
waitForAssert(() -> {
assertTrue("We should be able to mute the radio",
radioServiceDummy.containsRequestParameter(1, CHANNEL_MUTE));
assertTrue(radioServiceDummy.containsRequestParameter(1, CHANNEL_MUTE),
"We should be able to mute the radio");
radioServiceDummy.clearRequestParameters();
});
radioHandler.handleCommand(muteChannelUID, OnOffType.OFF);
waitForAssert(() -> {
assertTrue("We should be able to unmute the radio",
radioServiceDummy.containsRequestParameter(0, CHANNEL_MUTE));
assertTrue(radioServiceDummy.containsRequestParameter(0, CHANNEL_MUTE),
"We should be able to unmute the radio");
radioServiceDummy.clearRequestParameters();
});
@ -370,8 +370,8 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
radioHandler.handleCommand(modeChannelUID, DecimalType.valueOf("1"));
waitForAssert(() -> {
assertTrue("We should be able to update the mode channel correctly",
radioServiceDummy.containsRequestParameter(1, CHANNEL_MODE));
assertTrue(radioServiceDummy.containsRequestParameter(1, CHANNEL_MODE),
"We should be able to update the mode channel correctly");
radioServiceDummy.clearRequestParameters();
});
@ -381,8 +381,8 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
*/
radioHandler.handleCommand(modeChannelUID, DecimalType.valueOf("3"));
waitForAssert(() -> {
assertTrue("We should be able to update the mode channel correctly",
radioServiceDummy.containsRequestParameter(3, CHANNEL_MODE));
assertTrue(radioServiceDummy.containsRequestParameter(3, CHANNEL_MODE),
"We should be able to update the mode channel correctly");
radioServiceDummy.clearRequestParameters();
});
}
@ -450,8 +450,8 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
radioHandler.handleCommand(absoluteVolumeChannelUID, DecimalType.valueOf("36"));
waitForAssert(() -> {
assertTrue("The volume should not exceed the maximum value",
radioServiceDummy.containsRequestParameter(32, VOLUME));
assertTrue(radioServiceDummy.containsRequestParameter(32, VOLUME),
"The volume should not exceed the maximum value");
radioServiceDummy.clearRequestParameters();
});
@ -459,8 +459,8 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
radioHandler.handleCommand(absoluteVolumeChannelUID, IncreaseDecreaseType.INCREASE);
waitForAssert(() -> {
assertTrue("The volume should not be increased above the maximum value",
radioServiceDummy.areRequestParametersEmpty());
assertTrue(radioServiceDummy.areRequestParametersEmpty(),
"The volume should not be increased above the maximum value");
radioServiceDummy.clearRequestParameters();
});
@ -468,16 +468,16 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
radioHandler.handleCommand(absoluteVolumeChannelUID, UpDownType.UP);
waitForAssert(() -> {
assertTrue("The volume should not be increased above the maximum value",
radioServiceDummy.areRequestParametersEmpty());
assertTrue(radioServiceDummy.areRequestParametersEmpty(),
"The volume should not be increased above the maximum value");
radioServiceDummy.clearRequestParameters();
});
// Trying to set a value that is lower than the minimum volume value
radioHandler.handleCommand(absoluteVolumeChannelUID, DecimalType.valueOf("-10"));
waitForAssert(() -> {
assertTrue("The volume should not be decreased below 0",
radioServiceDummy.containsRequestParameter(0, VOLUME));
assertTrue(radioServiceDummy.containsRequestParameter(0, VOLUME),
"The volume should not be decreased below 0");
radioServiceDummy.clearRequestParameters();
});
@ -489,8 +489,8 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
// trying to set the volume
radioHandler.handleCommand(absoluteVolumeChannelUID, DecimalType.valueOf("15"));
waitForAssert(() -> {
assertTrue("We should be able to set the volume correctly",
radioServiceDummy.containsRequestParameter(15, VOLUME));
assertTrue(radioServiceDummy.containsRequestParameter(15, VOLUME),
"We should be able to set the volume correctly");
radioServiceDummy.clearRequestParameters();
});
}
@ -586,16 +586,16 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
*/
radioHandler.handleCommand(percentVolumeChannelUID, PercentType.valueOf("50"));
waitForAssert(() -> {
assertTrue("We should be able to set the volume correctly using percentages.",
radioServiceDummy.containsRequestParameter(16, VOLUME));
assertTrue(radioServiceDummy.containsRequestParameter(16, VOLUME),
"We should be able to set the volume correctly using percentages.");
radioServiceDummy.clearRequestParameters();
});
radioHandler.handleCommand(percentVolumeChannelUID, PercentType.valueOf("15"));
waitForAssert(() -> {
assertTrue("We should be able to set the volume correctly using percentages.",
radioServiceDummy.containsRequestParameter(4, VOLUME));
assertTrue(radioServiceDummy.containsRequestParameter(4, VOLUME),
"We should be able to set the volume correctly using percentages.");
radioServiceDummy.clearRequestParameters();
});
}
@ -605,31 +605,31 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
// First we have to make sure that the item state is 0
radioHandler.handleCommand(channelUID, DecimalType.valueOf("0"));
waitForAssert(() -> {
assertTrue("We should be able to turn on the radio",
radioServiceDummy.containsRequestParameter(1, CHANNEL_POWER));
assertTrue(radioServiceDummy.containsRequestParameter(1, CHANNEL_POWER),
"We should be able to turn on the radio");
radioServiceDummy.clearRequestParameters();
});
radioHandler.handleCommand(channelUID, IncreaseDecreaseType.INCREASE);
waitForAssert(() -> {
assertTrue("We should be able to increase the volume correctly",
radioServiceDummy.containsRequestParameter(1, VOLUME));
assertTrue(radioServiceDummy.containsRequestParameter(1, VOLUME),
"We should be able to increase the volume correctly");
radioServiceDummy.clearRequestParameters();
});
radioHandler.handleCommand(channelUID, IncreaseDecreaseType.DECREASE);
waitForAssert(() -> {
assertTrue("We should be able to increase the volume correctly",
radioServiceDummy.containsRequestParameter(0, VOLUME));
assertTrue(radioServiceDummy.containsRequestParameter(0, VOLUME),
"We should be able to increase the volume correctly");
radioServiceDummy.clearRequestParameters();
});
// Trying to decrease one more time
radioHandler.handleCommand(channelUID, IncreaseDecreaseType.DECREASE);
waitForAssert(() -> {
assertFalse("We should be able to decrease the volume correctly",
radioServiceDummy.containsRequestParameter(0, VOLUME));
assertFalse(radioServiceDummy.containsRequestParameter(0, VOLUME),
"We should be able to decrease the volume correctly");
radioServiceDummy.clearRequestParameters();
});
}
@ -640,30 +640,30 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
// First we have to make sure that the item state is 0
radioHandler.handleCommand(channelUID, DecimalType.valueOf("0"));
waitForAssert(() -> {
assertTrue("We should be able to turn on the radio",
radioServiceDummy.containsRequestParameter(1, CHANNEL_POWER));
assertTrue(radioServiceDummy.containsRequestParameter(1, CHANNEL_POWER),
"We should be able to turn on the radio");
radioServiceDummy.clearRequestParameters();
});
radioHandler.handleCommand(channelUID, UpDownType.UP);
waitForAssert(() -> {
assertTrue("We should be able to increase the volume correctly",
radioServiceDummy.containsRequestParameter(1, VOLUME));
assertTrue(radioServiceDummy.containsRequestParameter(1, VOLUME),
"We should be able to increase the volume correctly");
radioServiceDummy.clearRequestParameters();
});
radioHandler.handleCommand(channelUID, UpDownType.DOWN);
waitForAssert(() -> {
assertTrue("We should be able to decrease the volume correctly",
radioServiceDummy.containsRequestParameter(0, VOLUME));
assertTrue(radioServiceDummy.containsRequestParameter(0, VOLUME),
"We should be able to decrease the volume correctly");
radioServiceDummy.clearRequestParameters();
});
// Trying to decrease one more time
radioHandler.handleCommand(channelUID, UpDownType.DOWN);
waitForAssert(() -> {
assertTrue("We shouldn't be able to decrease the volume below 0",
radioServiceDummy.areRequestParametersEmpty());
assertTrue(radioServiceDummy.areRequestParametersEmpty(),
"We shouldn't be able to decrease the volume below 0");
radioServiceDummy.clearRequestParameters();
});
}
@ -687,8 +687,8 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest {
radioHandler.handleCommand(presetChannelUID, DecimalType.valueOf("100"));
waitForAssert(() -> {
assertTrue("We should be able to set value to the preset",
radioServiceDummy.containsRequestParameter(100, PRESET));
assertTrue(radioServiceDummy.containsRequestParameter(100, PRESET),
"We should be able to set value to the preset");
radioServiceDummy.clearRequestParameters();
});
}

View File

@ -12,7 +12,7 @@
*/
package org.openhab.binding.hdpowerview;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.openhab.binding.hdpowerview.internal.api.ActuatorClass.*;
import static org.openhab.binding.hdpowerview.internal.api.CoordinateSystem.*;
@ -28,7 +28,7 @@ import javax.ws.rs.client.ClientBuilder;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
import org.openhab.binding.hdpowerview.internal.HubMaintenanceException;
import org.openhab.binding.hdpowerview.internal.api.CoordinateSystem;

View File

@ -13,10 +13,10 @@
package org.openhab.binding.heos.internal.json;
import static java.lang.Long.valueOf;
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.heos.internal.json.dto.HeosCommunicationAttribute;
import org.openhab.binding.heos.internal.json.dto.HeosEvent;
import org.openhab.binding.heos.internal.json.dto.HeosEventObject;

View File

@ -12,13 +12,13 @@
*/
package org.openhab.binding.heos.internal.json;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.openhab.binding.heos.internal.json.dto.HeosCommunicationAttribute.*;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.heos.internal.json.dto.HeosCommand;
import org.openhab.binding.heos.internal.json.dto.HeosCommandGroup;
import org.openhab.binding.heos.internal.json.dto.HeosErrorCode;

View File

@ -12,13 +12,12 @@
*/
package org.openhab.binding.heos.internal.json.dto;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
import static org.openhab.binding.heos.internal.json.dto.HeosCommand.*;
import static org.openhab.binding.heos.internal.json.dto.HeosCommandGroup.SYSTEM;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Tests to validate the functioning of the HeosCommandTuple

View File

@ -20,8 +20,8 @@ import static org.openhab.binding.homematic.test.util.RpcClientMockImpl.*;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.homematic.internal.communicator.message.RpcRequest;
import org.openhab.binding.homematic.internal.communicator.message.XmlRpcRequest;
import org.openhab.binding.homematic.internal.model.HmChannel;
@ -36,7 +36,7 @@ public class RpcClientTest extends JavaTest {
private RpcClientMockImpl rpcClient;
@Before
@BeforeEach
public void setup() throws IOException {
this.rpcClient = new RpcClientMockImpl();
}

View File

@ -17,8 +17,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.homematic.internal.misc.HomematicClientException;
import org.openhab.binding.homematic.internal.misc.HomematicConstants;
import org.openhab.binding.homematic.internal.misc.MiscUtils;
@ -44,7 +44,7 @@ public class ButtonDatapointTest extends JavaTest {
private MockEventReceiver mockEventReceiver;
private final ButtonVirtualDatapointHandler bvdpHandler = new ButtonVirtualDatapointHandler();
@Before
@BeforeEach
public void setup() throws IOException {
this.mockEventReceiver = new MockEventReceiver();
}

View File

@ -12,7 +12,7 @@
*/
package org.openhab.binding.homematic.internal.converter;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.openhab.binding.homematic.internal.model.HmChannel;
import org.openhab.binding.homematic.internal.model.HmDatapoint;
import org.openhab.binding.homematic.internal.model.HmDevice;
@ -34,7 +34,7 @@ public class BaseConverterTest {
protected final HmDatapoint integerQuantityDp = new HmDatapoint("floatIntegerDp", "", HmValueType.INTEGER, null,
false, HmParamsetType.VALUES);
@Before
@BeforeEach
public void setup() {
HmChannel stubChannel = new HmChannel("stubChannel", 0);
stubChannel.setDevice(new HmDevice("LEQ123456", HmInterface.RF, "HM-STUB-DEVICE", "", "", ""));

View File

@ -13,9 +13,9 @@
package org.openhab.binding.homematic.internal.converter;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.homematic.internal.converter.type.AbstractTypeConverter;
import org.openhab.binding.homematic.internal.model.HmDatapoint;
import org.openhab.core.library.types.DecimalType;

View File

@ -14,8 +14,9 @@ package org.openhab.binding.homematic.internal.converter;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.homematic.internal.converter.type.AbstractTypeConverter;
import org.openhab.binding.homematic.internal.converter.type.DecimalTypeConverter;
import org.openhab.binding.homematic.internal.converter.type.QuantityTypeConverter;
@ -99,15 +100,15 @@ public class ConvertToBindingTest extends BaseConverterTest {
assertThat(convertedValue, is(42));
}
@Test(expected = ConverterException.class)
public void testQuantityTypeConverterFailsToConvertDecimalType() throws ConverterException {
@Test
public void testQuantityTypeConverterFailsToConvertDecimalType() {
QuantityTypeConverter converter = new QuantityTypeConverter();
converter.convertToBinding(new DecimalType(99.9), floatDp);
assertThrows(ConverterException.class, () -> converter.convertToBinding(new DecimalType(99.9), floatDp));
}
@Test(expected = ConverterException.class)
public void testDecimalTypeConverterFailsToConvertQuantityType() throws ConverterException {
@Test
public void testDecimalTypeConverterFailsToConvertQuantityType() {
DecimalTypeConverter converter = new DecimalTypeConverter();
converter.convertToBinding(new QuantityType<>("99.9 %"), floatDp);
assertThrows(ConverterException.class, () -> converter.convertToBinding(new QuantityType<>("99.9 %"), floatDp));
}
}

View File

@ -15,7 +15,7 @@ package org.openhab.binding.homematic.internal.converter;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.homematic.internal.converter.type.DecimalTypeConverter;
import org.openhab.binding.homematic.internal.converter.type.OnOffTypeConverter;
import org.openhab.binding.homematic.internal.converter.type.OpenClosedTypeConverter;

View File

@ -21,8 +21,8 @@ import static org.openhab.binding.homematic.test.util.DimmerHelper.createDimmerH
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.homematic.internal.communicator.HomematicGateway;
import org.openhab.binding.homematic.internal.handler.HomematicBridgeHandler;
import org.openhab.binding.homematic.internal.model.HmDevice;
@ -46,7 +46,7 @@ public class HomematicDeviceDiscoveryServiceTest extends JavaTest {
private HomematicDeviceDiscoveryService homematicDeviceDiscoveryService;
private HomematicBridgeHandler homematicBridgeHandler;
@Before
@BeforeEach
public void setup() throws IOException {
this.homematicBridgeHandler = mockHomematicBridgeHandler();
this.homematicDeviceDiscoveryService = new HomematicDeviceDiscoveryService();

View File

@ -19,8 +19,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link org.openhab.binding.homematic.internal.handler.SimplePortPool}.
@ -31,7 +31,7 @@ public class SimplePortPoolTest {
private SimplePortPool simplePortPool;
@Before
@BeforeEach
public void setup() {
this.simplePortPool = new SimplePortPool();
}

View File

@ -17,7 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.openhab.binding.homematic.test.util.BridgeHelper.createHomematicBridge;
import static org.openhab.binding.homematic.test.util.DimmerHelper.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.homematic.internal.model.HmChannel;
import org.openhab.binding.homematic.internal.model.HmDatapoint;
import org.openhab.binding.homematic.internal.model.HmDatapointInfo;

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.hue.internal;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*

View File

@ -13,7 +13,7 @@
package org.openhab.binding.hue.internal;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;
import java.io.IOException;
@ -23,7 +23,7 @@ import java.util.List;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openhab.binding.hue.internal.HttpClient.Result;
import org.openhab.binding.hue.internal.exceptions.ApiException;

View File

@ -13,9 +13,10 @@
package org.openhab.binding.hue.internal;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.hue.internal.State.ColorMode;
import org.openhab.binding.hue.internal.handler.LightStateConverter;
import org.openhab.core.library.types.DecimalType;

View File

@ -13,12 +13,12 @@
package org.openhab.binding.hue.internal;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author HJiang - initial contribution

View File

@ -12,15 +12,15 @@
*/
package org.openhab.binding.hue.internal.handler;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.openhab.binding.hue.internal.HueBindingConstants.*;
import java.util.Collections;
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.openhab.binding.hue.internal.FullConfig;
import org.openhab.binding.hue.internal.FullLight;
@ -65,7 +65,7 @@ public class HueLightHandlerTest {
private Gson gson;
@Before
@BeforeEach
public void setUp() {
gson = new Gson();
}

View File

@ -12,15 +12,15 @@
*/
package org.openhab.binding.icalendar.internal.logic;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
@ -45,7 +45,7 @@ public class BiweeklyPresentableCalendarTest {
private AbstractPresentableCalendar calendar2;
private AbstractPresentableCalendar calendar3;
@Before
@BeforeEach
public void setUp() throws IOException, CalendarException {
calendar = new BiweeklyPresentableCalendar(new FileInputStream("src/test/resources/test.ics"));
calendar2 = new BiweeklyPresentableCalendar(new FileInputStream("src/test/resources/test2.ics"));

View File

@ -12,11 +12,11 @@
*/
package org.openhab.binding.ihc.internal;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.time.Duration;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Test for IHC / ELKO binding

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Test for IHC / ELKO binding

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSDateValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSTimeValue;

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSBooleanValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSEnumValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSFloatingPointValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
@ -42,16 +42,18 @@ public class DecimalTypeWSFloatingPointValueConverterTest {
assertEquals(new DecimalType(2.54), type);
}
@Test(expected = ConversionException.class)
public void testMinExceed() throws ConversionException {
@Test
public void testMinExceed() {
WSFloatingPointValue val = new WSFloatingPointValue(12345, 0, -100, 100);
val = convertFromOHType(val, new DecimalType(-101.5), new ConverterAdditionalInfo(null, false, null));
assertThrows(ConversionException.class,
() -> convertFromOHType(val, new DecimalType(-101.5), new ConverterAdditionalInfo(null, false, null)));
}
@Test(expected = ConversionException.class)
public void testMaxExceed() throws ConversionException {
@Test
public void testMaxExceed() {
WSFloatingPointValue val = new WSFloatingPointValue(12345, 0, -100, 100);
val = convertFromOHType(val, new DecimalType(101.5), new ConverterAdditionalInfo(null, false, null));
assertThrows(ConversionException.class,
() -> convertFromOHType(val, new DecimalType(101.5), new ConverterAdditionalInfo(null, false, null)));
}
private WSFloatingPointValue convertFromOHType(WSFloatingPointValue IHCvalue, Type OHval,

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSIntegerValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
@ -42,16 +42,18 @@ public class DecimalTypeWSIntegerValueConverterTest {
assertEquals(new DecimalType(2), type);
}
@Test(expected = ConversionException.class)
public void testMinExceed() throws ConversionException {
@Test
public void testMinExceed() {
WSIntegerValue val = new WSIntegerValue(12345, 0, -100, 100);
val = convertFromOHType(val, new DecimalType(-101.5), new ConverterAdditionalInfo(null, false, null));
assertThrows(ConversionException.class,
() -> convertFromOHType(val, new DecimalType(-101.5), new ConverterAdditionalInfo(null, false, null)));
}
@Test(expected = ConversionException.class)
public void testMaxExceed() throws ConversionException {
@Test
public void testMaxExceed() {
WSIntegerValue val = new WSIntegerValue(12345, 0, -100, 100);
val = convertFromOHType(val, new DecimalType(101.5), new ConverterAdditionalInfo(null, false, null));
assertThrows(ConversionException.class,
() -> convertFromOHType(val, new DecimalType(101.5), new ConverterAdditionalInfo(null, false, null)));
}
private WSIntegerValue convertFromOHType(WSIntegerValue IHCvalue, Type OHval,

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSTimerValue;

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSWeekdayValue;

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSBooleanValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;

View File

@ -12,13 +12,13 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSIntegerValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
@ -69,15 +69,15 @@ public class OnOffTypeWSIntegerValueConverterTest {
assertEquals(OnOffType.ON, type);
}
@Test(expected = ConversionException.class)
public void testOnLevelledError() throws ConversionException {
@Test
public void testOnLevelledError() {
WSIntegerValue val = new WSIntegerValue(12345, 0, -100, 100);
Map<Command, Object> commandLevels = new HashMap<>();
commandLevels.put(OnOffType.ON, "70");
val = convertFromOHType(val, OnOffType.ON,
new ConverterAdditionalInfo(null, false, Collections.unmodifiableMap(commandLevels)));
assertThrows(ConversionException.class, () -> convertFromOHType(val, OnOffType.ON,
new ConverterAdditionalInfo(null, false, Collections.unmodifiableMap(commandLevels))));
}
@Test

View File

@ -12,9 +12,9 @@
*/
package org.openhab.binding.ihc.internal.converters;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSBooleanValue;
import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;

Some files were not shown because too many files have changed in this diff Show More