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
478 changed files with 3996 additions and 4419 deletions

View File

@@ -30,7 +30,7 @@ import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.astro.internal.handler.AstroThingHandler;
import org.openhab.binding.astro.internal.handler.SunHandler;
import org.openhab.binding.astro.internal.model.Sun;

View File

@@ -28,7 +28,7 @@ import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.binding.astro.internal.handler.AstroThingHandler;
import org.openhab.binding.astro.internal.handler.SunHandler;

View File

@@ -12,7 +12,7 @@
*/
package org.openhab.binding.astro.test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.openhab.binding.astro.internal.AstroBindingConstants.*;
import static org.openhab.binding.astro.test.cases.AstroBindingTestsData.*;
import static org.openhab.binding.astro.test.cases.AstroParametrizedTestCases.*;
@@ -24,19 +24,17 @@ import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.types.State;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.openhab.binding.astro.internal.calc.MoonCalc;
import org.openhab.binding.astro.internal.calc.SunCalc;
import org.openhab.binding.astro.internal.config.AstroChannelConfig;
import org.openhab.binding.astro.internal.model.Planet;
import org.openhab.binding.astro.internal.util.PropertyUtils;
import org.openhab.binding.astro.test.cases.AstroParametrizedTestCases;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.types.State;
/**
* Tests for the Astro Channels state
@@ -47,30 +45,19 @@ import org.openhab.binding.astro.test.cases.AstroParametrizedTestCases;
* @author Erdoan Hadzhiyusein - Adapted the class to work with the new DateTimeType
* @author Christoph Weitkamp - Migrated tests to pure Java
*/
@RunWith(Parameterized.class)
public class AstroStateTest {
private String thingID;
private String channelId;
private State expectedState;
// These test result timestamps are adapted for the +03:00 time zone
private static final ZoneId ZONE_ID = ZoneId.of("+03:00");
public AstroStateTest(String thingID, String channelId, State expectedState) {
this.thingID = thingID;
this.channelId = channelId;
this.expectedState = expectedState;
}
@Parameters
public static List<Object[]> data() {
AstroParametrizedTestCases cases = new AstroParametrizedTestCases();
return cases.getCases();
}
@Test
public void testParametrized() {
@ParameterizedTest
@MethodSource("data")
public void testParametrized(String thingID, String channelId, State expectedState) {
try {
assertStateUpdate(thingID, channelId, expectedState);
} catch (Exception e) {

View File

@@ -13,7 +13,7 @@
package org.openhab.binding.avmfritz.internal.discovery;
import static org.openhab.core.thing.Thing.*;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
import java.io.StringReader;
@@ -31,9 +31,9 @@ import org.openhab.core.config.discovery.DiscoveryResultFlag;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
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.binding.avmfritz.internal.dto.AVMFritzBaseModel;
import org.openhab.binding.avmfritz.internal.dto.DeviceListModel;
import org.openhab.binding.avmfritz.internal.handler.AVMFritzThingHandlerOSGiTest;
@@ -71,7 +71,7 @@ public class AVMFritzDiscoveryServiceOSGiTest extends AVMFritzThingHandlerOSGiTe
};
@Override
@Before
@BeforeEach
public void setUp() {
super.setUp();
discovery = new AVMFritzDiscoveryService();
@@ -79,7 +79,7 @@ public class AVMFritzDiscoveryServiceOSGiTest extends AVMFritzThingHandlerOSGiTe
discovery.addDiscoveryListener(listener);
}
@After
@AfterEach
public void cleanUp() {
discoveryResult = null;
}

View File

@@ -12,7 +12,7 @@
*/
package org.openhab.binding.avmfritz.internal.handler;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
@@ -21,19 +21,19 @@ import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jetty.client.HttpClient;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.openhab.binding.avmfritz.internal.AVMFritzDynamicCommandDescriptionProvider;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ManagedThingProvider;
import org.openhab.core.thing.ThingProvider;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.openhab.binding.avmfritz.internal.AVMFritzDynamicCommandDescriptionProvider;
/**
* Tests for {@link AVMFritzThingHandlerOSGiTest}.
@@ -51,17 +51,17 @@ public abstract class AVMFritzThingHandlerOSGiTest extends JavaOSGiTest {
protected @NonNullByDefault({}) Bridge bridge;
protected @NonNullByDefault({}) BoxHandler bridgeHandler;
@BeforeClass
@BeforeAll
public static void setUpClass() throws Exception {
httpClient.start();
}
@Before
@BeforeEach
public void setUp() {
registerService(volatileStorageService);
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertNotNull("Could not get ManagedThingProvider", managedThingProvider);
assertNotNull(managedThingProvider, "Could not get ManagedThingProvider");
bridge = buildBridge();
assertNotNull(bridge.getConfiguration());
@@ -82,7 +82,7 @@ public abstract class AVMFritzThingHandlerOSGiTest extends JavaOSGiTest {
bridgeHandler.initialize();
}
@After
@AfterEach
public void tearDown() {
if (bridge != null) {
managedThingProvider.remove(bridge.getUID());
@@ -91,7 +91,7 @@ public abstract class AVMFritzThingHandlerOSGiTest extends JavaOSGiTest {
unregisterService(volatileStorageService);
}
@AfterClass
@AfterAll
public static void tearDownClass() throws Exception {
httpClient.stop();
}

View File

@@ -13,9 +13,9 @@
package org.openhab.binding.feed.test;
import static java.lang.Thread.sleep;
import static org.openhab.core.thing.ThingStatus.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.openhab.core.thing.ThingStatus.*;
import java.io.IOException;
import java.math.BigDecimal;
@@ -27,12 +27,19 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.feed.internal.FeedBindingConstants;
import org.openhab.binding.feed.internal.handler.FeedHandler;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.items.Item;
import org.openhab.core.items.ItemRegistry;
import org.openhab.core.items.StateChangeListener;
import org.openhab.core.library.items.StringItem;
import org.openhab.core.library.types.StringType;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ManagedThingProvider;
@@ -47,14 +54,6 @@ import org.openhab.core.thing.link.ItemChannelLink;
import org.openhab.core.thing.link.ManagedItemChannelLinkProvider;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openhab.binding.feed.internal.FeedBindingConstants;
import org.openhab.binding.feed.internal.handler.FeedHandler;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
@@ -143,7 +142,7 @@ public class FeedHandlerTest extends JavaOSGiTest {
}
}
@Before
@BeforeEach
public void setUp() {
volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
@@ -157,7 +156,7 @@ public class FeedHandlerTest extends JavaOSGiTest {
registerFeedTestServlet();
}
@After
@AfterEach
public void tearDown() {
currentItemState = null;
if (feedThing != null) {
@@ -315,7 +314,6 @@ public class FeedHandlerTest extends JavaOSGiTest {
}
@Test
@Category(SlowTests.class)
public void assertThatItemsStateIsNotUpdatedOnAutoRefreshIfContentIsNotChanged()
throws IOException, InterruptedException {
boolean commandReceived = false;
@@ -324,7 +322,6 @@ public class FeedHandlerTest extends JavaOSGiTest {
}
@Test
@Category(SlowTests.class)
public void assertThatItemsStateIsUpdatedOnAutoRefreshIfContentChanged() throws IOException, InterruptedException {
boolean commandReceived = false;
boolean contentChanged = true;

View File

@@ -12,7 +12,7 @@
*/
package org.openhab.binding.hue.internal;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.binding.ThingHandler;

View File

@@ -12,10 +12,11 @@
*/
package org.openhab.binding.hue.internal;
import static org.openhab.core.thing.Thing.PROPERTY_SERIAL_NUMBER;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.openhab.binding.hue.internal.HueBindingConstants.*;
import static org.openhab.core.thing.Thing.PROPERTY_SERIAL_NUMBER;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -23,6 +24,11 @@ import java.util.Collection;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.hue.internal.discovery.HueLightDiscoveryService;
import org.openhab.binding.hue.internal.handler.HueBridgeHandler;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.config.discovery.DiscoveryListener;
import org.openhab.core.config.discovery.DiscoveryResult;
@@ -36,12 +42,6 @@ import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.builder.ThingStatusInfoBuilder;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openhab.binding.hue.internal.discovery.HueLightDiscoveryService;
import org.openhab.binding.hue.internal.handler.HueBridgeHandler;
/**
* Tests for {@link HueLightDiscoveryService}.
@@ -64,7 +64,7 @@ public class HueLightDiscoveryServiceOSGiTest extends AbstractHueOSGiTestParent
protected final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID("hue", "bridge");
protected final ThingUID BRIDGE_THING_UID = new ThingUID(BRIDGE_THING_TYPE_UID, "testBridge");
@Before
@BeforeEach
public void setUp() {
registerVolatileStorageService();
@@ -89,7 +89,7 @@ public class HueLightDiscoveryServiceOSGiTest extends AbstractHueOSGiTestParent
assertThat(discoveryService, is(notNullValue()));
}
@After
@AfterEach
public void cleanUp() {
thingRegistry.remove(BRIDGE_THING_UID);
waitForAssert(() -> {
@@ -217,7 +217,7 @@ public class HueLightDiscoveryServiceOSGiTest extends AbstractHueOSGiTestParent
usernameField.setAccessible(true);
usernameField.set(hueBridgeValue, hueBridgeHandler.getThing().getConfiguration().get(USER_NAME));
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
Assert.fail("Reflection usage error");
fail("Reflection usage error");
}
});
hueBridgeHandler.initialize();

View File

@@ -12,23 +12,18 @@
*/
package org.openhab.binding.hue.internal.discovery;
import static org.openhab.core.thing.Thing.PROPERTY_SERIAL_NUMBER;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.openhab.binding.hue.internal.HueBindingConstants.*;
import static org.openhab.core.thing.Thing.PROPERTY_SERIAL_NUMBER;
import java.net.MalformedURLException;
import java.net.URL;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultFlag;
import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.test.java.JavaOSGiTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.jupnp.model.meta.DeviceDetails;
import org.jupnp.model.meta.ManufacturerDetails;
@@ -38,6 +33,11 @@ import org.jupnp.model.meta.RemoteDeviceIdentity;
import org.jupnp.model.meta.RemoteService;
import org.jupnp.model.types.DeviceType;
import org.jupnp.model.types.UDN;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultFlag;
import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.thing.ThingUID;
/**
* Tests for {@link org.openhab.binding.hue.internal.discovery.HueBridgeDiscoveryParticipant}.
@@ -53,7 +53,7 @@ public class HueBridgeDiscoveryParticipantOSGITest extends JavaOSGiTest {
RemoteDevice hueDevice;
RemoteDevice otherDevice;
@Before
@BeforeEach
public void setUp() {
discoveryParticipant = getService(UpnpDiscoveryParticipant.class, HueBridgeDiscoveryParticipant.class);
assertThat(discoveryParticipant, is(notNullValue()));
@@ -74,11 +74,11 @@ public class HueBridgeDiscoveryParticipantOSGITest extends JavaOSGiTest {
new ManufacturerDetails("Taiwan"), new ModelDetails("$%&/"), "serial567", "upc"),
remoteService);
} catch (final ValidationException | MalformedURLException ex) {
Assert.fail("Internal test error.");
fail("Internal test error.");
}
}
@After
@AfterEach
public void cleanUp() {
}

View File

@@ -12,10 +12,11 @@
*/
package org.openhab.binding.hue.internal.discovery;
import static org.openhab.core.config.discovery.inbox.InboxPredicates.forThingTypeUID;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openhab.binding.hue.internal.HueBindingConstants.THING_TYPE_BRIDGE;
import static org.openhab.core.config.discovery.inbox.InboxPredicates.forThingTypeUID;
import java.io.IOException;
import java.util.Collection;
@@ -24,16 +25,16 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.core.config.discovery.DiscoveryListener;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.config.discovery.inbox.Inbox;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.junit.Before;
import org.junit.Test;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
/**
*
@@ -139,7 +140,7 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
}
}
@Before
@BeforeEach
public void setUp() {
registerService(volatileStorageService);

View File

@@ -12,33 +12,34 @@
*/
package org.openhab.binding.hue.internal.handler;
import static org.openhab.core.thing.Thing.PROPERTY_SERIAL_NUMBER;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.openhab.binding.hue.internal.HueBindingConstants.*;
import static org.openhab.binding.hue.internal.config.HueBridgeConfig.HTTP;
import static org.openhab.core.thing.Thing.PROPERTY_SERIAL_NUMBER;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.concurrent.ScheduledExecutorService;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.config.core.status.ConfigStatusMessage;
import org.openhab.core.common.ThreadPoolManager;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ThingRegistry;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.hue.internal.AbstractHueOSGiTestParent;
import org.openhab.binding.hue.internal.HueBridge;
import org.openhab.binding.hue.internal.HueConfigStatusMessage;
import org.openhab.binding.hue.internal.exceptions.ApiException;
import org.openhab.binding.hue.internal.exceptions.LinkButtonException;
import org.openhab.binding.hue.internal.exceptions.UnauthorizedException;
import org.openhab.core.common.ThreadPoolManager;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.config.core.status.ConfigStatusMessage;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ThingRegistry;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
/**
* Tests for {@link HueBridgeHandler}.
@@ -57,7 +58,7 @@ public class HueBridgeHandlerOSGiTest extends AbstractHueOSGiTestParent {
private ScheduledExecutorService scheduler;
@Before
@BeforeEach
public void setUp() {
registerVolatileStorageService();
thingRegistry = getService(ThingRegistry.class, ThingRegistry.class);

View File

@@ -13,10 +13,17 @@
package org.openhab.binding.max.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.openhab.binding.max.internal.MaxBindingConstants.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.max.internal.MaxBindingConstants;
import org.openhab.binding.max.internal.handler.MaxCubeBridgeHandler;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingRegistry;
@@ -24,13 +31,6 @@ import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openhab.binding.max.internal.MaxBindingConstants;
import org.openhab.binding.max.internal.handler.MaxCubeBridgeHandler;
/**
* Tests for {@link MaxCubeBridgeHandler}.
@@ -47,7 +47,7 @@ public class MaxCubeBridgeHandlerOSGiTest extends JavaOSGiTest {
private Bridge maxBridge;
@Before
@BeforeEach
public void setUp() {
registerService(volatileStorageService);
@@ -55,7 +55,7 @@ public class MaxCubeBridgeHandlerOSGiTest extends JavaOSGiTest {
assertThat(thingRegistry, is(notNullValue()));
}
@After
@AfterEach
public void tearDown() {
if (maxBridge != null) {
thingRegistry.remove(maxBridge.getUID());

View File

@@ -13,9 +13,10 @@
package org.openhab.binding.modbus.tests;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@@ -32,6 +33,15 @@ import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
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.modbus.internal.ModbusHandlerFactory;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventFilter;
import org.openhab.core.events.EventSubscriber;
@@ -41,6 +51,7 @@ import org.openhab.core.items.ItemRegistry;
import org.openhab.core.items.ManagedItemProvider;
import org.openhab.core.items.events.ItemStateEvent;
import org.openhab.core.library.CoreItemFactory;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ManagedThingProvider;
import org.openhab.core.thing.Thing;
@@ -52,12 +63,6 @@ import org.openhab.core.thing.link.ItemChannelLinkProvider;
import org.openhab.core.thing.link.ManagedItemChannelLinkProvider;
import org.openhab.core.transform.TransformationService;
import org.openhab.core.types.State;
import org.openhab.core.test.java.JavaOSGiTest;
import org.junit.After;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.openhab.binding.modbus.internal.ModbusHandlerFactory;
import org.openhab.io.transport.modbus.ModbusCommunicationInterface;
import org.openhab.io.transport.modbus.ModbusManager;
import org.slf4j.Logger;
@@ -66,6 +71,8 @@ import org.slf4j.LoggerFactory;
/**
* @author Sami Salonen - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
@NonNullByDefault
public abstract class AbstractModbusOSGiTest extends JavaOSGiTest {
@@ -99,8 +106,7 @@ public abstract class AbstractModbusOSGiTest extends JavaOSGiTest {
private final Logger logger = LoggerFactory.getLogger(AbstractModbusOSGiTest.class);
@Mock
protected @NonNullByDefault({}) ModbusManager mockedModbusManager;
protected @Mock @NonNullByDefault({}) ModbusManager mockedModbusManager;
protected @NonNullByDefault({}) ManagedThingProvider thingProvider;
protected @NonNullByDefault({}) ManagedItemProvider itemProvider;
protected @NonNullByDefault({}) ManagedItemChannelLinkProvider itemChannelLinkProvider;
@@ -113,8 +119,7 @@ public abstract class AbstractModbusOSGiTest extends JavaOSGiTest {
private Set<ItemChannelLink> addedLinks = new HashSet<>();
private StateSubscriber stateSubscriber = new StateSubscriber();
@Mock
protected @NonNullByDefault({}) ModbusCommunicationInterface comms;
protected @Mock @NonNullByDefault({}) ModbusCommunicationInterface comms;
public AbstractModbusOSGiTest() {
super();
@@ -123,7 +128,7 @@ public abstract class AbstractModbusOSGiTest extends JavaOSGiTest {
/**
* Before each test, configure mocked services
*/
@Before
@BeforeEach
public void setUpAbstractModbusOSGiTest() {
logger.debug("setUpAbstractModbusOSGiTest BEGIN");
registerVolatileStorageService();
@@ -150,7 +155,7 @@ public abstract class AbstractModbusOSGiTest extends JavaOSGiTest {
logger.debug("setUpAbstractModbusOSGiTest END");
}
@After
@AfterEach
public void tearDownAbstractModbusOSGiTest() {
logger.debug("tearDownAbstractModbusOSGiTest BEGIN");
swapModbusManagerToReal();

View File

@@ -13,7 +13,8 @@
package org.openhab.binding.modbus.tests;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@@ -30,6 +31,14 @@ import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.commons.lang.StringUtils;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openhab.binding.modbus.handler.EndpointNotInitializedException;
import org.openhab.binding.modbus.handler.ModbusPollerThingHandler;
import org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler;
import org.openhab.binding.modbus.internal.handler.ModbusTcpThingHandler;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.items.GenericItem;
import org.openhab.core.items.Item;
@@ -55,16 +64,6 @@ import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.openhab.binding.modbus.handler.EndpointNotInitializedException;
import org.openhab.binding.modbus.handler.ModbusPollerThingHandler;
import org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler;
import org.openhab.binding.modbus.internal.handler.ModbusTcpThingHandler;
import org.openhab.io.transport.modbus.AsyncModbusFailure;
import org.openhab.io.transport.modbus.AsyncModbusReadResult;
import org.openhab.io.transport.modbus.AsyncModbusWriteResult;
@@ -89,7 +88,6 @@ import org.osgi.framework.InvalidSyntaxException;
/**
* @author Sami Salonen - Initial contribution
*/
@RunWith(MockitoJUnitRunner.class)
public class ModbusDataHandlerTest extends AbstractModbusOSGiTest {
private final class MultiplyTransformation implements TransformationService {
@@ -115,7 +113,7 @@ public class ModbusDataHandlerTest extends AbstractModbusOSGiTest {
}
private List<ModbusWriteRequestBlueprint> writeRequests = new ArrayList<>();
@After
@AfterEach
public void tearDown() {
writeRequests.clear();
}

View File

@@ -13,8 +13,9 @@
package org.openhab.binding.modbus.tests;
import static org.hamcrest.CoreMatchers.equalTo;
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.assertNotNull;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
@@ -22,6 +23,17 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicReference;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.openhab.binding.modbus.handler.ModbusPollerThingHandler;
import org.openhab.binding.modbus.internal.ModbusBindingConstantsInternal;
import org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
@@ -31,19 +43,6 @@ import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.openhab.binding.modbus.handler.ModbusPollerThingHandler;
import org.openhab.binding.modbus.internal.ModbusBindingConstantsInternal;
import org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler;
import org.openhab.io.transport.modbus.AsyncModbusFailure;
import org.openhab.io.transport.modbus.AsyncModbusReadResult;
import org.openhab.io.transport.modbus.BitArray;
@@ -62,7 +61,6 @@ import org.slf4j.LoggerFactory;
/**
* @author Sami Salonen - Initial contribution
*/
@RunWith(MockitoJUnitRunner.class)
public class ModbusPollerThingHandlerTest extends AbstractModbusOSGiTest {
private static final String HOST = "thisishost";
@@ -73,8 +71,7 @@ public class ModbusPollerThingHandlerTest extends AbstractModbusOSGiTest {
private Bridge endpoint;
private Bridge poller;
@Mock
private ThingHandlerCallback thingCallback;
private @Mock ThingHandlerCallback thingCallback;
public static BridgeBuilder createTcpThingBuilder(String id) {
return BridgeBuilder
@@ -114,7 +111,7 @@ public class ModbusPollerThingHandlerTest extends AbstractModbusOSGiTest {
/**
* Before each test, setup TCP endpoint thing, configure mocked item registry
*/
@Before
@BeforeEach
public void setUp() {
mockCommsToModbusManager();
Configuration tcpConfig = new Configuration();
@@ -127,7 +124,7 @@ public class ModbusPollerThingHandlerTest extends AbstractModbusOSGiTest {
assertThat(endpoint.getStatus(), is(equalTo(ThingStatus.ONLINE)));
}
@After
@AfterEach
public void tearDown() {
if (endpoint != null) {
thingProvider.remove(endpoint.getUID());

View File

@@ -13,24 +13,23 @@
package org.openhab.binding.modbus.tests;
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.util.Objects;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;
import org.openhab.binding.modbus.handler.EndpointNotInitializedException;
import org.openhab.binding.modbus.internal.ModbusBindingConstantsInternal;
import org.openhab.binding.modbus.internal.handler.ModbusTcpThingHandler;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.openhab.binding.modbus.handler.EndpointNotInitializedException;
import org.openhab.binding.modbus.internal.ModbusBindingConstantsInternal;
import org.openhab.binding.modbus.internal.handler.ModbusTcpThingHandler;
import org.openhab.io.transport.modbus.endpoint.EndpointPoolConfiguration;
import org.openhab.io.transport.modbus.endpoint.ModbusSlaveEndpoint;
import org.openhab.io.transport.modbus.endpoint.ModbusTCPSlaveEndpoint;
@@ -38,7 +37,6 @@ import org.openhab.io.transport.modbus.endpoint.ModbusTCPSlaveEndpoint;
/**
* @author Sami Salonen - Initial contribution
*/
@RunWith(MockitoJUnitRunner.class)
public class ModbusTcpThingHandlerTest extends AbstractModbusOSGiTest {
private static BridgeBuilder createTcpThingBuilder(String id) {

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.openhab.addons.itests</groupId>
<artifactId>org.openhab.addons.reactor.itests</artifactId>
<version>2.5.9-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.openhab.binding.mqtt.homeassistant.tests</artifactId>

View File

@@ -14,7 +14,7 @@ package org.openhab.binding.mqtt;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.mockito.MockitoAnnotations.openMocks;
import java.util.Collections;
import java.util.HashSet;
@@ -26,10 +26,9 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
import org.openhab.core.test.java.JavaOSGiTest;
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.mockito.Mock;
import org.openhab.binding.mqtt.generic.AvailabilityTracker;
import org.openhab.binding.mqtt.generic.ChannelStateUpdateListener;
@@ -39,6 +38,8 @@ import org.openhab.binding.mqtt.homeassistant.internal.DiscoverComponents;
import org.openhab.binding.mqtt.homeassistant.internal.DiscoverComponents.ComponentDiscovered;
import org.openhab.binding.mqtt.homeassistant.internal.HaID;
import org.openhab.binding.mqtt.homeassistant.internal.HandlerConfiguration;
import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
import org.openhab.core.test.java.JavaOSGiTest;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -49,24 +50,19 @@ import com.google.gson.GsonBuilder;
* @author David Graeff - Initial contribution
*/
public class DiscoverComponentsTest extends JavaOSGiTest {
@Mock
MqttBrokerConnection connection;
@Mock
ComponentDiscovered discovered;
private AutoCloseable mocksCloseable;
@Mock
TransformationServiceProvider transformationServiceProvider;
private @Mock MqttBrokerConnection connection;
private @Mock ComponentDiscovered discovered;
private @Mock TransformationServiceProvider transformationServiceProvider;
private @Mock ChannelStateUpdateListener channelStateUpdateListener;
private @Mock AvailabilityTracker availabilityTracker;
@Mock
ChannelStateUpdateListener channelStateUpdateListener;
@BeforeEach
public void beforeEach() {
mocksCloseable = openMocks(this);
@Mock
AvailabilityTracker availabilityTracker;
@Before
public void setUp() {
initMocks(this);
CompletableFuture<Void> voidFutureComplete = new CompletableFuture<>();
voidFutureComplete.complete(null);
doReturn(voidFutureComplete).when(connection).unsubscribeAll();
@@ -78,6 +74,11 @@ public class DiscoverComponentsTest extends JavaOSGiTest {
doReturn(null).when(transformationServiceProvider).getTransformationService(any());
}
@AfterEach
public void afterEach() throws Exception {
mocksCloseable.close();
}
@Test
public void discoveryTimeTest() throws InterruptedException, ExecutionException, TimeoutException {
// Create a scheduler

View File

@@ -12,7 +12,7 @@
*/
package org.openhab.binding.mqtt;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@@ -63,7 +63,7 @@ public class EmbeddedBrokerTools {
};
mqttService.addBrokersListener(observer);
assertTrue("Wait for embedded connection client failed", semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
assertTrue(semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS), "Wait for embedded connection client failed");
}
MqttBrokerConnection embeddedConnection = this.embeddedConnection;
if (embeddedConnection == null) {
@@ -81,8 +81,8 @@ public class EmbeddedBrokerTools {
if (embeddedConnection.connectionState() == MqttConnectionState.CONNECTED) {
semaphore.release();
}
assertTrue("Connection " + embeddedConnection.getClientId() + " failed. State: "
+ embeddedConnection.connectionState(), semaphore.tryAcquire(500, TimeUnit.MILLISECONDS));
assertTrue(semaphore.tryAcquire(500, TimeUnit.MILLISECONDS), "Connection " + embeddedConnection.getClientId()
+ " failed. State: " + embeddedConnection.connectionState());
return embeddedConnection;
}

View File

@@ -13,12 +13,12 @@
package org.openhab.binding.mqtt;
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.any;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.mockito.MockitoAnnotations.openMocks;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -32,18 +32,9 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
import org.openhab.core.util.UIDUtils;
import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
import org.openhab.core.io.transport.mqtt.MqttConnectionState;
import org.openhab.core.io.transport.mqtt.MqttService;
import org.openhab.core.test.java.JavaOSGiTest;
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.mockito.Mock;
import org.openhab.binding.mqtt.generic.AvailabilityTracker;
import org.openhab.binding.mqtt.generic.ChannelStateUpdateListener;
@@ -55,6 +46,15 @@ import org.openhab.binding.mqtt.homeassistant.internal.ComponentSwitch;
import org.openhab.binding.mqtt.homeassistant.internal.DiscoverComponents;
import org.openhab.binding.mqtt.homeassistant.internal.DiscoverComponents.ComponentDiscovered;
import org.openhab.binding.mqtt.homeassistant.internal.HaID;
import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
import org.openhab.core.io.transport.mqtt.MqttConnectionState;
import org.openhab.core.io.transport.mqtt.MqttService;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
import org.openhab.core.util.UIDUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -72,14 +72,11 @@ public class HomeAssistantMQTTImplementationTest extends JavaOSGiTest {
private int registeredTopics = 100;
private Throwable failure = null;
@Mock
ChannelStateUpdateListener channelStateUpdateListener;
private AutoCloseable mocksCloseable;
@Mock
AvailabilityTracker availabilityTracker;
@Mock
TransformationServiceProvider transformationServiceProvider;
private @Mock ChannelStateUpdateListener channelStateUpdateListener;
private @Mock AvailabilityTracker availabilityTracker;
private @Mock TransformationServiceProvider transformationServiceProvider;
/**
* Create an observer that fails the test as soon as the broker client connection changes its connection state
@@ -89,10 +86,10 @@ public class HomeAssistantMQTTImplementationTest extends JavaOSGiTest {
is(MqttConnectionState.CONNECTED));
private String testObjectTopic;
@Before
public void setUp() throws InterruptedException, ExecutionException, TimeoutException, IOException {
@BeforeEach
public void beforeEach() throws Exception {
registerVolatileStorageService();
initMocks(this);
mocksCloseable = openMocks(this);
mqttService = getService(MqttService.class);
// Wait for the EmbeddedBrokerService internal connection to be connected
@@ -124,12 +121,14 @@ public class HomeAssistantMQTTImplementationTest extends JavaOSGiTest {
doReturn(null).when(transformationServiceProvider).getTransformationService(any());
}
@After
public void tearDown() throws InterruptedException, ExecutionException, TimeoutException {
@AfterEach
public void afterEach() throws Exception {
if (connection != null) {
connection.removeConnectionObserver(failIfChange);
connection.stop().get(1000, TimeUnit.MILLISECONDS);
}
mocksCloseable.close();
}
@Test
@@ -146,8 +145,8 @@ public class HomeAssistantMQTTImplementationTest extends JavaOSGiTest {
CountDownLatch c = new CountDownLatch(registeredTopics);
connection.subscribe("homeassistant/+/+/" + ThingChannelConstants.testHomeAssistantThing.getId() + "/#",
(topic, payload) -> c.countDown()).get(1000, TimeUnit.MILLISECONDS);
assertTrue("Connection " + connection.getClientId() + " not retrieving all topics",
c.await(1000, TimeUnit.MILLISECONDS));
assertTrue(c.await(1000, TimeUnit.MILLISECONDS),
"Connection " + connection.getClientId() + " not retrieving all topics");
}
@Test

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.addons.itests</groupId>
<artifactId>org.openhab.addons.reactor.itests</artifactId>
<version>2.5.9-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.openhab.binding.mqtt.homie.tests</artifactId>

View File

@@ -12,7 +12,7 @@
*/
package org.openhab.binding.mqtt;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@@ -65,7 +65,7 @@ public class EmbeddedBrokerTools {
}
};
mqttService.addBrokersListener(observer);
assertTrue("Wait for embedded connection client failed", semaphore.tryAcquire(700, TimeUnit.MILLISECONDS));
assertTrue(semaphore.tryAcquire(700, TimeUnit.MILLISECONDS), "Wait for embedded connection client failed");
}
MqttBrokerConnection embeddedConnection = this.embeddedConnection;
if (embeddedConnection == null) {
@@ -84,8 +84,8 @@ public class EmbeddedBrokerTools {
if (embeddedConnection.connectionState() == MqttConnectionState.CONNECTED) {
semaphore.release();
}
assertTrue("Connection " + embeddedConnection.getClientId() + " failed. State: "
+ embeddedConnection.connectionState(), semaphore.tryAcquire(500, TimeUnit.MILLISECONDS));
assertTrue(semaphore.tryAcquire(500, TimeUnit.MILLISECONDS), "Connection " + embeddedConnection.getClientId()
+ " failed. State: " + embeddedConnection.connectionState());
return embeddedConnection;
}
}

View File

@@ -13,10 +13,11 @@
package org.openhab.binding.mqtt;
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.*;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.mockito.MockitoAnnotations.openMocks;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
@@ -31,17 +32,9 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.types.UnDefType;
import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
import org.openhab.core.io.transport.mqtt.MqttConnectionState;
import org.openhab.core.io.transport.mqtt.MqttService;
import org.openhab.core.test.java.JavaOSGiTest;
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.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.openhab.binding.mqtt.generic.ChannelState;
@@ -58,6 +51,14 @@ import org.openhab.binding.mqtt.homie.internal.homie300.Property;
import org.openhab.binding.mqtt.homie.internal.homie300.PropertyAttributes;
import org.openhab.binding.mqtt.homie.internal.homie300.PropertyAttributes.DataTypeEnum;
import org.openhab.binding.mqtt.homie.internal.homie300.PropertyHelper;
import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
import org.openhab.core.io.transport.mqtt.MqttConnectionState;
import org.openhab.core.io.transport.mqtt.MqttService;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.types.UnDefType;
/**
* A full implementation test, that starts the embedded MQTT broker and publishes a homie device tree.
@@ -74,13 +75,13 @@ public class HomieImplementationTest extends JavaOSGiTest {
private MqttBrokerConnection connection;
private int registeredTopics = 100;
private AutoCloseable mocksCloseable;
// The handler is not tested here, so just mock the callback
@Mock
DeviceCallback callback;
private @Mock DeviceCallback callback;
// A handler mock is required to verify that channel value changes have been received
@Mock
HomieThingHandler handler;
private @Mock HomieThingHandler handler;
private ScheduledExecutorService scheduler;
@@ -93,10 +94,10 @@ public class HomieImplementationTest extends JavaOSGiTest {
private String propertyTestTopic;
@Before
public void setUp() throws InterruptedException, ExecutionException, TimeoutException {
@BeforeEach
public void beforeEach() throws Exception {
registerVolatileStorageService();
initMocks(this);
mocksCloseable = openMocks(this);
mqttService = getService(MqttService.class);
embeddedConnection = new EmbeddedBrokerTools().waitForConnection(mqttService);
@@ -152,13 +153,14 @@ public class HomieImplementationTest extends JavaOSGiTest {
scheduler = new ScheduledThreadPoolExecutor(6);
}
@After
public void tearDown() throws InterruptedException, ExecutionException, TimeoutException {
@AfterEach
public void afterEach() throws Exception {
if (connection != null) {
connection.removeConnectionObserver(failIfChange);
connection.stop().get(500, TimeUnit.MILLISECONDS);
}
scheduler.shutdownNow();
mocksCloseable.close();
}
@Test
@@ -167,8 +169,8 @@ public class HomieImplementationTest extends JavaOSGiTest {
CountDownLatch c = new CountDownLatch(registeredTopics - 4);
connection.subscribe(DEVICE_TOPIC + "/testnode/#", (topic, payload) -> c.countDown()).get(5000,
TimeUnit.MILLISECONDS);
assertTrue("Connection " + connection.getClientId() + " not retrieving all topics ",
c.await(5000, TimeUnit.MILLISECONDS));
assertTrue(c.await(5000, TimeUnit.MILLISECONDS),
"Connection " + connection.getClientId() + " not retrieving all topics ");
}
@Test
@@ -311,11 +313,8 @@ public class HomieImplementationTest extends JavaOSGiTest {
property.getChannelState().publishValue(OnOffType.ON).get();
// No value is expected to be retained on this MQTT topic
waitForAssert(() -> {
try {
WaitForTopicValue w = new WaitForTopicValue(embeddedConnection, propertyTestTopic + "/set");
assertNull(w.waitForTopicValue(50));
} catch (InterruptedException | ExecutionException e) {
}
WaitForTopicValue w = new WaitForTopicValue(embeddedConnection, propertyTestTopic + "/set");
assertNull(w.waitForTopicValue(50));
}, 500, 100);
}
}

View File

@@ -13,7 +13,8 @@
package org.openhab.binding.ntp.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@@ -26,6 +27,16 @@ import java.util.Locale;
import java.util.TimeZone;
import org.apache.commons.lang.StringUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.openhab.binding.ntp.internal.NtpBindingConstants;
import org.openhab.binding.ntp.internal.handler.NtpHandler;
import org.openhab.binding.ntp.server.SimpleNTPServer;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventSubscriber;
@@ -39,6 +50,8 @@ import org.openhab.core.library.items.DateTimeItem;
import org.openhab.core.library.items.StringItem;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ManagedThingProvider;
@@ -57,18 +70,6 @@ import org.openhab.core.thing.type.ChannelTypeBuilder;
import org.openhab.core.thing.type.ChannelTypeProvider;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.State;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentMatchers;
import org.openhab.binding.ntp.internal.NtpBindingConstants;
import org.openhab.binding.ntp.internal.handler.NtpHandler;
import org.openhab.binding.ntp.server.SimpleNTPServer;
/**
* OSGi tests for the {@link NtpHandler}
@@ -122,7 +123,7 @@ public class NtpOSGiTest extends JavaOSGiTest {
}
}
@BeforeClass
@BeforeAll
public static void setUpClass() {
// Initializing a new local server on this port
timeServer = new SimpleNTPServer(TEST_PORT);
@@ -144,7 +145,7 @@ public class NtpOSGiTest extends JavaOSGiTest {
Locale.setDefault(Locale.US);
}
@Before
@BeforeEach
public void setUp() {
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
@@ -165,7 +166,7 @@ public class NtpOSGiTest extends JavaOSGiTest {
registerService(channelTypeProvider);
}
@After
@AfterEach
public void tearDown() {
if (ntpThing != null) {
Thing removedThing = thingRegistry.forceRemove(ntpThing.getUID());
@@ -177,7 +178,7 @@ public class NtpOSGiTest extends JavaOSGiTest {
}
}
@AfterClass
@AfterAll
public static void tearDownClass() {
// Stopping the local time server
timeServer.stopServer();
@@ -274,7 +275,7 @@ public class NtpOSGiTest extends JavaOSGiTest {
}
@Test
@Ignore("https://github.com/eclipse/smarthome/issues/5224")
@Disabled("https://github.com/eclipse/smarthome/issues/5224")
public void testDateTimeChannelCalendarDefaultTimeZoneUpdate() {
Configuration configuration = new Configuration();
// Initialize with configuration with no time zone property set.

View File

@@ -15,7 +15,8 @@ package org.openhab.binding.systeminfo.test;
import static java.lang.Thread.sleep;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.*;
import java.math.BigDecimal;
@@ -23,6 +24,16 @@ import java.net.UnknownHostException;
import java.util.Hashtable;
import java.util.List;
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.openhab.binding.systeminfo.internal.SysteminfoBindingConstants;
import org.openhab.binding.systeminfo.internal.SysteminfoHandlerFactory;
import org.openhab.binding.systeminfo.internal.discovery.SysteminfoDiscoveryService;
import org.openhab.binding.systeminfo.internal.handler.SysteminfoHandler;
import org.openhab.binding.systeminfo.internal.model.DeviceNotFoundException;
import org.openhab.binding.systeminfo.internal.model.SysteminfoInterface;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryService;
@@ -35,6 +46,8 @@ import org.openhab.core.library.items.NumberItem;
import org.openhab.core.library.items.StringItem;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ManagedThingProvider;
@@ -55,18 +68,6 @@ import org.openhab.core.thing.type.ChannelKind;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.openhab.binding.systeminfo.internal.SysteminfoBindingConstants;
import org.openhab.binding.systeminfo.internal.SysteminfoHandlerFactory;
import org.openhab.binding.systeminfo.internal.discovery.SysteminfoDiscoveryService;
import org.openhab.binding.systeminfo.internal.handler.SysteminfoHandler;
import org.openhab.binding.systeminfo.internal.model.DeviceNotFoundException;
import org.openhab.binding.systeminfo.internal.model.SysteminfoInterface;
/**
* OSGi tests for the {@link SysteminfoHandler}
@@ -105,7 +106,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
private ItemRegistry itemRegistry;
private SysteminfoHandlerFactory systeminfoHandlerFactory;
@Before
@BeforeEach
public void setUp() {
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
@@ -138,7 +139,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
assertThat(itemRegistry, is(notNullValue()));
}
@After
@AfterEach
public void tearDown() {
if (systemInfoThing != null) {
// Remove the systeminfo thing. The handler will be also disposed automatically
@@ -658,7 +659,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
mockedDriveSerialNumber);
}
@Ignore
@Disabled
// There is a bug opened for this issue - https://github.com/dblock/oshi/issues/185
@Test
public void assertChannelSensorsCpuTempIsUpdated() {
@@ -927,7 +928,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
waitForAssert(() -> {
List<DiscoveryResult> results = inbox.stream().filter(InboxPredicates.forThingUID(computerUID))
.collect(toList());
assertFalse("No Thing with UID " + computerUID.getAsString() + " in inbox", results.isEmpty());
assertFalse(results.isEmpty(), "No Thing with UID " + computerUID.getAsString() + " in inbox");
});
inbox.approve(computerUID, SysteminfoDiscoveryService.DEFAULT_THING_LABEL);

View File

@@ -13,22 +13,24 @@
package org.openhab.binding.tradfri.internal.discovery;
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 static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.mockito.MockitoAnnotations.openMocks;
import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
import javax.jmdns.ServiceInfo;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultFlag;
import org.openhab.core.config.discovery.mdns.MDNSDiscoveryParticipant;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.test.java.JavaOSGiTest;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
/**
* Tests for {@link TradfriDiscoveryParticipant}.
@@ -39,15 +41,15 @@ public class TradfriDiscoveryParticipantOSGITest extends JavaOSGiTest {
private MDNSDiscoveryParticipant discoveryParticipant;
@Mock
private ServiceInfo tradfriGateway;
private AutoCloseable mocksCloseable;
@Mock
private ServiceInfo otherDevice;
private @Mock ServiceInfo tradfriGateway;
private @Mock ServiceInfo otherDevice;
@BeforeEach
public void beforeEach() {
mocksCloseable = openMocks(this);
@Before
public void setUp() {
initMocks(this);
discoveryParticipant = getService(MDNSDiscoveryParticipant.class, TradfriDiscoveryParticipant.class);
when(tradfriGateway.getType()).thenReturn("_coap._udp.local.");
@@ -63,6 +65,11 @@ public class TradfriDiscoveryParticipantOSGITest extends JavaOSGiTest {
when(otherDevice.getPropertyString("version")).thenReturn("1.1");
}
@AfterEach
public void afterEach() throws Exception {
mocksCloseable.close();
}
@Test
public void correctSupportedTypes() {
assertThat(discoveryParticipant.getSupportedThingTypeUIDs().size(), is(1));

View File

@@ -13,26 +13,26 @@
package org.openhab.binding.tradfri.internal.handler;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
import static org.openhab.binding.tradfri.internal.config.TradfriDeviceConfig.CONFIG_ID;
import java.util.HashMap;
import java.util.Map;
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.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ManagedThingProvider;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingProvider;
import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* Tests cases for {@link TradfriGatewayHandler}.
@@ -46,7 +46,7 @@ public class TradfriHandlerOSGiTest extends JavaOSGiTest {
private Bridge bridge;
private Thing thing;
@Before
@BeforeEach
public void setUp() {
registerService(volatileStorageService);
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
@@ -64,7 +64,7 @@ public class TradfriHandlerOSGiTest extends JavaOSGiTest {
.withConfiguration(new Configuration(properties)).build();
}
@After
@AfterEach
public void tearDown() {
managedThingProvider.remove(thing.getUID());
managedThingProvider.remove(bridge.getUID());

View File

@@ -12,9 +12,10 @@
*/
package org.openhab.binding.wemo.internal.discovery.test;
import static org.openhab.core.config.discovery.inbox.InboxPredicates.forThingUID;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openhab.core.config.discovery.inbox.InboxPredicates.forThingUID;
import java.io.IOException;
import java.net.MalformedURLException;
@@ -23,19 +24,19 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.inbox.Inbox;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
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.jupnp.model.ValidationException;
import org.jupnp.model.meta.Device;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.discovery.WemoDiscoveryService;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.inbox.Inbox;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
/**
* Tests for {@link WemoDiscoveryService}.
@@ -52,7 +53,7 @@ public class WemoDiscoveryOSGiTest extends GenericWemoOSGiTest {
private @NonNullByDefault({}) Inbox inbox;
@Before
@BeforeEach
public void setUp() throws IOException {
setUpServices();
@@ -60,7 +61,7 @@ public class WemoDiscoveryOSGiTest extends GenericWemoOSGiTest {
assertThat(inbox, is(notNullValue()));
}
@After
@AfterEach
public void tearDown() {
List<DiscoveryResult> results = inbox.getAll();
assertThat(results.size(), is(0));

View File

@@ -13,18 +13,15 @@
package org.openhab.binding.wemo.internal.discovery.test;
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.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.jupnp.model.meta.DeviceDetails;
import org.jupnp.model.meta.ManufacturerDetails;
@@ -37,6 +34,10 @@ import org.jupnp.model.types.UDN;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.discovery.WemoDiscoveryParticipant;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
/**
* Tests for {@link WemoDiscoveryParticipant}.

View File

@@ -12,7 +12,7 @@
*/
package org.openhab.binding.wemo.internal.discovery.test;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@@ -23,8 +23,8 @@ import java.util.List;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Bridge;
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.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -43,7 +43,7 @@ import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
*/
public class WemoLinkDiscoveryServiceOSGiTest extends GenericWemoLightOSGiTestParent {
@Before
@BeforeEach
public void setUp() throws IOException {
setUpServices();
}

View File

@@ -13,7 +13,8 @@
package org.openhab.binding.wemo.internal.handler.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@@ -22,16 +23,9 @@ import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.List;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
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.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -39,6 +33,13 @@ import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
/**
* Tests for {@link WemoHandler}.
@@ -58,12 +59,12 @@ public class WemoHandlerOSGiTest extends GenericWemoOSGiTest {
private final String SERVICE_ID = "basicevent";
private final String SERVICE_NUMBER = "1";
@Before
@BeforeEach
public void setUp() throws IOException {
setUpServices();
}
@After
@AfterEach
public void tearDown() {
removeThing();
}

View File

@@ -13,10 +13,16 @@
package org.openhab.binding.wemo.internal.handler.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.*;
import static org.openhab.binding.wemo.internal.WemoBindingConstants.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.Thing;
@@ -25,12 +31,6 @@ import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.types.State;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
/**
* Tests for {@link WemoHandler}.
@@ -60,7 +60,7 @@ public class WemoHandlerTest {
private final Thing thing = mock(Thing.class);
@Before
@BeforeEach
public void setUp() {
insightParams = new WemoInsightParams();
when(thing.getUID()).thenReturn(new ThingUID(THING_TYPE, THING_ID));
@@ -68,7 +68,7 @@ public class WemoHandlerTest {
when(thing.getStatus()).thenReturn(ThingStatus.ONLINE);
}
@After
@AfterEach
public void clear() {
handler.channelState = null;
handler.channelToWatch = null;

View File

@@ -13,7 +13,8 @@
package org.openhab.binding.wemo.internal.handler.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.any;
import static org.mockito.Mockito.*;
@@ -22,6 +23,16 @@ import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoLightHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.binding.wemo.internal.test.GenericWemoLightOSGiTestParent;
import org.openhab.core.library.types.IncreaseDecreaseType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
@@ -32,16 +43,6 @@ import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoLightHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.binding.wemo.internal.test.GenericWemoLightOSGiTestParent;
/**
* Tests for {@link WemoLightHandler}.
@@ -54,12 +55,12 @@ public class WemoLightHandlerOSGiTest extends GenericWemoLightOSGiTestParent {
private static final String GET_ACTION = "GetDeviceStatus";
private static final String SET_ACTION = "SetDeviceStatus";
@Before
@BeforeEach
public void setUp() throws IOException {
setUpServices();
}
@After
@AfterEach
public void tearDown() {
removeThing();
}

View File

@@ -13,7 +13,8 @@
package org.openhab.binding.wemo.internal.handler.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@@ -22,6 +23,16 @@ import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoMakerHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
@@ -30,16 +41,6 @@ import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoMakerHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
/**
* Tests for {@link WemoMakerHandler}.
@@ -59,12 +60,12 @@ public class WemoMakerHandlerOSGiTest extends GenericWemoOSGiTest {
private final String BASIC_EVENT_SERVICE_ID = "basicevent";
private final String SERVICE_NUMBER = "1";
@Before
@BeforeEach
public void setUp() throws IOException {
setUpServices();
}
@After
@AfterEach
public void tearDown() {
removeThing();
}

View File

@@ -13,8 +13,11 @@
package org.openhab.binding.wemo.internal.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.AbstractWemoHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Channel;
@@ -28,9 +31,6 @@ import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.thing.type.ChannelKind;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.AbstractWemoHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
/**
* Generic test class for all WemoLight related tests that contains methods and constants used across the different test

View File

@@ -13,7 +13,7 @@
package org.openhab.binding.wemo.internal.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@@ -24,25 +24,6 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.util.Locale;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.CoreItemFactory;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ManagedThingProvider;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingRegistry;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.thing.type.ChannelKind;
import org.openhab.core.thing.type.ChannelTypeBuilder;
import org.openhab.core.thing.type.ChannelTypeProvider;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.io.transport.upnp.UpnpIOService;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.jupnp.UpnpService;
import org.jupnp.mock.MockUpnpService;
import org.jupnp.model.ValidationException;
@@ -59,6 +40,25 @@ import org.jupnp.model.types.UDN;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.AbstractWemoHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.io.transport.upnp.UpnpIOService;
import org.openhab.core.library.CoreItemFactory;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ManagedThingProvider;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingRegistry;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.thing.type.ChannelKind;
import org.openhab.core.thing.type.ChannelTypeBuilder;
import org.openhab.core.thing.type.ChannelTypeProvider;
import org.openhab.core.thing.type.ChannelTypeUID;
/**
* Generic test class for all Wemo related tests that contains methods and constants used across the different test

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.openhab.addons.itests</groupId>
<artifactId>org.openhab.addons.reactor.itests</artifactId>
<version>2.5.9-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.openhab.io.mqttembeddedbroker.tests</artifactId>

View File

@@ -12,7 +12,7 @@
*/
package org.openhab.io.mqttembeddedbroker;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@@ -25,7 +25,6 @@ import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
import org.openhab.core.io.transport.mqtt.MqttConnectionState;
import org.openhab.core.io.transport.mqtt.MqttService;
import org.openhab.core.io.transport.mqtt.MqttServiceObserver;
import org.openhab.io.mqttembeddedbroker.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,7 +65,7 @@ public class EmbeddedBrokerTools {
};
mqttService.addBrokersListener(observer);
assertTrue("Wait for embedded connection client failed", semaphore.tryAcquire(700, TimeUnit.MILLISECONDS));
assertTrue(semaphore.tryAcquire(700, TimeUnit.MILLISECONDS), "Wait for embedded connection client failed");
}
MqttBrokerConnection embeddedConnection = this.embeddedConnection;
if (embeddedConnection == null) {
@@ -85,8 +84,8 @@ public class EmbeddedBrokerTools {
if (embeddedConnection.connectionState() == MqttConnectionState.CONNECTED) {
semaphore.release();
}
assertTrue("Connection " + embeddedConnection.getClientId() + " failed. State: "
+ embeddedConnection.connectionState(), semaphore.tryAcquire(500, TimeUnit.MILLISECONDS));
assertTrue(semaphore.tryAcquire(500, TimeUnit.MILLISECONDS), "Connection " + embeddedConnection.getClientId()
+ " failed. State: " + embeddedConnection.connectionState());
return embeddedConnection;
}

View File

@@ -13,8 +13,9 @@
package org.openhab.io.mqttembeddedbroker;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.MockitoAnnotations.openMocks;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -25,14 +26,14 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
import org.openhab.core.io.transport.mqtt.MqttConnectionState;
import org.openhab.core.io.transport.mqtt.MqttService;
import org.openhab.core.test.java.JavaOSGiTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* Moquette test
@@ -42,6 +43,8 @@ import org.junit.Test;
public class MoquetteTest extends JavaOSGiTest {
private static final String TEST_TOPIC = "testtopic";
private AutoCloseable mocksCloseable;
private MqttService mqttService;
private MqttBrokerConnection embeddedConnection;
private MqttBrokerConnection clientConnection;
@@ -53,10 +56,10 @@ public class MoquetteTest extends JavaOSGiTest {
private MqttConnectionObserver failIfChange = (state, error) -> assertThat(state,
is(MqttConnectionState.CONNECTED));
@Before
public void setUp() throws InterruptedException, ExecutionException, TimeoutException {
@BeforeEach
public void beforeEach() throws Exception {
registerVolatileStorageService();
initMocks(this);
mocksCloseable = openMocks(this);
mqttService = getService(MqttService.class);
// Wait for the EmbeddedBrokerService internal connection to be connected
@@ -72,12 +75,13 @@ public class MoquetteTest extends JavaOSGiTest {
clientConnection.addConnectionObserver(failIfChange);
}
@After
public void tearDown() throws InterruptedException, ExecutionException, TimeoutException {
@AfterEach
public void afterEach() throws Exception {
if (clientConnection != null) {
clientConnection.removeConnectionObserver(failIfChange);
clientConnection.stop().get(500, TimeUnit.MILLISECONDS);
}
mocksCloseable.close();
}
@Test
@@ -101,8 +105,10 @@ public class MoquetteTest extends JavaOSGiTest {
throws InterruptedException, ExecutionException, TimeoutException {
List<CompletableFuture<Boolean>> futures = new ArrayList<>();
futures.add(embeddedConnection.publish(TEST_TOPIC + "/1", "testPayload1".getBytes(StandardCharsets.UTF_8), 1, true));
futures.add(embeddedConnection.publish(TEST_TOPIC + "/2", "testPayload2".getBytes(StandardCharsets.UTF_8), 1, true));
futures.add(embeddedConnection.publish(TEST_TOPIC + "/1", "testPayload1".getBytes(StandardCharsets.UTF_8), 1,
true));
futures.add(embeddedConnection.publish(TEST_TOPIC + "/2", "testPayload2".getBytes(StandardCharsets.UTF_8), 1,
true));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(1000, TimeUnit.MILLISECONDS);
@@ -120,8 +126,10 @@ public class MoquetteTest extends JavaOSGiTest {
throws InterruptedException, ExecutionException, TimeoutException {
List<CompletableFuture<Boolean>> futures = new ArrayList<>();
futures.add(embeddedConnection.publish(TEST_TOPIC + "/1", "testPayload1".getBytes(StandardCharsets.UTF_8), 1, true));
futures.add(embeddedConnection.publish(TEST_TOPIC + "/2", "testPayload2".getBytes(StandardCharsets.UTF_8), 1, true));
futures.add(embeddedConnection.publish(TEST_TOPIC + "/1", "testPayload1".getBytes(StandardCharsets.UTF_8), 1,
true));
futures.add(embeddedConnection.publish(TEST_TOPIC + "/2", "testPayload2".getBytes(StandardCharsets.UTF_8), 1,
true));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(1000, TimeUnit.MILLISECONDS);
@@ -138,8 +146,10 @@ public class MoquetteTest extends JavaOSGiTest {
throws InterruptedException, ExecutionException, TimeoutException {
List<CompletableFuture<Boolean>> futures = new ArrayList<>();
futures.add(embeddedConnection.publish(TEST_TOPIC + "/1", "testPayload1".getBytes(StandardCharsets.UTF_8), 1, true));
futures.add(embeddedConnection.publish(TEST_TOPIC + "/2", "testPayload2".getBytes(StandardCharsets.UTF_8), 1, true));
futures.add(embeddedConnection.publish(TEST_TOPIC + "/1", "testPayload1".getBytes(StandardCharsets.UTF_8), 1,
true));
futures.add(embeddedConnection.publish(TEST_TOPIC + "/2", "testPayload2".getBytes(StandardCharsets.UTF_8), 1,
true));
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(1000, TimeUnit.MILLISECONDS);