Migrate tests to JUnit 5 (#8519)
Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user