Update Mockito, JUnit and use MockitoExtensions in itests (#9702)

* Updates Mockito to 3.7.0
* Updates JUnit to 5.7.0
* Use MockitoExtensions where possible

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2021-01-06 14:30:40 +01:00 committed by GitHub
parent 8f84646ed1
commit 0816045a59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 148 additions and 165 deletions

View File

@ -14,7 +14,6 @@ package org.openhab.binding.tr064.internal.phonebook;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.openMocks;
import static org.openhab.binding.tr064.internal.Tr064BindingConstants.*;
import java.math.BigDecimal;
@ -27,11 +26,14 @@ import java.util.Set;
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.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.StringListType;
import org.openhab.core.library.types.StringType;
@ -47,6 +49,8 @@ import org.openhab.core.util.UIDUtils;
*
* @author Christoph Weitkamp - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
class PhonebookProfileTest {
private static final String INTERNAL_PHONE_NUMBER = "999";
@ -97,8 +101,6 @@ class PhonebookProfileTest {
});
}
private AutoCloseable mocksCloseable;
private @Mock ProfileCallback mockCallback;
private @Mock ProfileContext mockContext;
private @Mock PhonebookProvider mockPhonebookProvider;
@ -123,17 +125,10 @@ class PhonebookProfileTest {
@BeforeEach
public void setup() {
mocksCloseable = openMocks(this);
when(mockPhonebookProvider.getPhonebookByName(any(String.class))).thenReturn(Optional.of(phonebook));
when(mockPhonebookProvider.getPhonebooks()).thenReturn(Set.of(phonebook));
}
@AfterEach
public void afterEach() throws Exception {
mocksCloseable.close();
}
@ParameterizedTest
@MethodSource("parameters")
public void testPhonebookProfileResolvesPhoneNumber(ParameterSet parameterSet) {

View File

@ -16,22 +16,12 @@ Fragment-Host: org.openhab.binding.astro
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
org.osgi.service.event;version='[1.4.0,1.4.1)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
org.objenesis;version='[2.6.0,2.6.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
com.google.gson;version='[2.8.2,2.8.3)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\
tec.uom.se;version='[1.0.10,1.0.11)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-jupiter-params;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\
org.mockito.mockito-core;version='[3.4.6,3.4.7)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
@ -44,4 +34,14 @@ Fragment-Host: org.openhab.binding.astro
org.openhab.core.config.discovery;version='[3.1.0,3.1.1)',\
org.openhab.core.io.console;version='[3.1.0,3.1.1)',\
org.openhab.core.storage.json;version='[3.1.0,3.1.1)',\
org.openhab.core.thing;version='[3.1.0,3.1.1)'
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-jupiter-params;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)',\
net.bytebuddy.byte-buddy;version='[1.10.19,1.10.20)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.19,1.10.20)',\
org.mockito.mockito-core;version='[3.7.0,3.7.1)',\
org.objenesis;version='[3.1.0,3.1.1)'

View File

@ -18,7 +18,6 @@ Fragment-Host: org.openhab.binding.avmfritz
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
org.osgi.service.event;version='[1.4.0,1.4.1)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
org.objenesis;version='[2.6.0,2.6.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.jupnp;version='[2.5.2,2.5.3)',\
@ -39,15 +38,7 @@ Fragment-Host: org.openhab.binding.avmfritz
org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.mockito.mockito-core;version='[3.4.6,3.4.7)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
@ -68,4 +59,13 @@ Fragment-Host: org.openhab.binding.avmfritz
org.openhab.core.io.console;version='[3.1.0,3.1.1)',\
org.openhab.core.io.net;version='[3.1.0,3.1.1)',\
org.openhab.core.test;version='[3.1.0,3.1.1)',\
org.openhab.core.thing;version='[3.1.0,3.1.1)'
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)',\
net.bytebuddy.byte-buddy;version='[1.10.19,1.10.20)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.19,1.10.20)',\
org.mockito.mockito-core;version='[3.7.0,3.7.1)',\
org.objenesis;version='[3.1.0,3.1.1)'

View File

@ -39,11 +39,6 @@ Fragment-Host: org.openhab.binding.feed
org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\
org.ops4j.pax.swissbox.optional.jcl;version='[1.8.3,1.8.4)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
@ -71,4 +66,9 @@ Fragment-Host: org.openhab.binding.feed
org.openhab.core.test;version='[3.1.0,3.1.1)',\
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
org.openhab.core.thing.xml;version='[3.1.0,3.1.1)',\
xstream;version='[1.4.15,1.4.16)'
xstream;version='[1.4.15,1.4.16)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)'

View File

@ -41,11 +41,6 @@ Fragment-Host: org.openhab.binding.hue
org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
org.eclipse.jdt.annotation;version='[2.2.100,2.2.101)',\
@ -72,4 +67,9 @@ Fragment-Host: org.openhab.binding.hue
org.openhab.core.test;version='[3.1.0,3.1.1)',\
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
org.openhab.core.thing.xml;version='[3.1.0,3.1.1)',\
xstream;version='[1.4.15,1.4.16)'
xstream;version='[1.4.15,1.4.16)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)'

View File

@ -36,11 +36,6 @@ Fragment-Host: org.openhab.binding.max
org.eclipse.jetty.servlet;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.util;version='[9.4.20,9.4.21)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
@ -58,4 +53,9 @@ Fragment-Host: org.openhab.binding.max
org.openhab.core.test;version='[3.1.0,3.1.1)',\
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
org.openhab.core.thing.xml;version='[3.1.0,3.1.1)',\
xstream;version='[1.4.15,1.4.16)'
xstream;version='[1.4.15,1.4.16)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)'

View File

@ -33,7 +33,6 @@ Fragment-Host: org.openhab.binding.modbus
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
org.osgi.service.event;version='[1.4.0,1.4.1)',\
org.objenesis;version='[2.6.0,2.6.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
com.google.gson;version='[2.8.2,2.8.3)',\
tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\
@ -48,16 +47,8 @@ Fragment-Host: org.openhab.binding.modbus
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\
nrjavaserial;version='[5.2.1,5.2.2)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.mockito.mockito-core;version='[3.4.6,3.4.7)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
@ -76,4 +67,14 @@ Fragment-Host: org.openhab.binding.modbus
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
org.openhab.core.thing.xml;version='[3.1.0,3.1.1)',\
org.openhab.core.transform;version='[3.1.0,3.1.1)',\
xstream;version='[1.4.15,1.4.16)'
xstream;version='[1.4.15,1.4.16)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)',\
net.bytebuddy.byte-buddy;version='[1.10.19,1.10.20)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.19,1.10.20)',\
org.mockito.mockito-core;version='[3.7.0,3.7.1)',\
org.objenesis;version='[3.1.0,3.1.1)',\
org.mockito.junit-jupiter;version='[3.7.0,3.7.1)'

View File

@ -19,7 +19,6 @@ import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.openMocks;
import java.util.ArrayList;
import java.util.Collections;
@ -36,8 +35,12 @@ 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;
@ -68,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 {
@ -101,8 +106,6 @@ public abstract class AbstractModbusOSGiTest extends JavaOSGiTest {
private final Logger logger = LoggerFactory.getLogger(AbstractModbusOSGiTest.class);
private @NonNullByDefault({}) AutoCloseable mocksCloseable;
protected @Mock @NonNullByDefault({}) ModbusManager mockedModbusManager;
protected @NonNullByDefault({}) ManagedThingProvider thingProvider;
protected @NonNullByDefault({}) ManagedItemProvider itemProvider;
@ -128,7 +131,6 @@ public abstract class AbstractModbusOSGiTest extends JavaOSGiTest {
@BeforeEach
public void setUpAbstractModbusOSGiTest() {
logger.debug("setUpAbstractModbusOSGiTest BEGIN");
mocksCloseable = openMocks(this);
registerVolatileStorageService();
registerService(mockedModbusManager);
registerService(stateSubscriber);
@ -167,7 +169,6 @@ public abstract class AbstractModbusOSGiTest extends JavaOSGiTest {
logger.debug("Unlinking {} <-> {}", link.getItemName(), link.getLinkedUID());
assertNotNull(itemChannelLinkProvider.remove(link.getUID()));
}
mocksCloseable.close();
logger.debug("tearDownAbstractModbusOSGiTest END");
}

View File

@ -14,7 +14,6 @@ package org.openhab.binding.mqtt;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.openMocks;
import java.util.Collections;
import java.util.HashSet;
@ -28,10 +27,13 @@ import java.util.concurrent.TimeoutException;
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.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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.mqtt.generic.AvailabilityTracker;
import org.openhab.binding.mqtt.generic.ChannelStateUpdateListener;
import org.openhab.binding.mqtt.generic.TransformationServiceProvider;
@ -51,11 +53,11 @@ import com.google.gson.GsonBuilder;
*
* @author David Graeff - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
@NonNullByDefault
public class DiscoverComponentsTest extends JavaOSGiTest {
private @NonNullByDefault({}) AutoCloseable mocksCloseable;
private @Mock @NonNullByDefault({}) MqttBrokerConnection connection;
private @Mock @NonNullByDefault({}) ComponentDiscovered discovered;
private @Mock @NonNullByDefault({}) TransformationServiceProvider transformationServiceProvider;
@ -64,8 +66,6 @@ public class DiscoverComponentsTest extends JavaOSGiTest {
@BeforeEach
public void beforeEach() {
mocksCloseable = openMocks(this);
CompletableFuture<@Nullable Void> voidFutureComplete = new CompletableFuture<>();
voidFutureComplete.complete(null);
doReturn(voidFutureComplete).when(connection).unsubscribeAll();
@ -76,11 +76,6 @@ 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

@ -17,7 +17,6 @@ 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.openMocks;
import java.util.ArrayList;
import java.util.Collections;
@ -37,7 +36,11 @@ import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.openhab.binding.mqtt.generic.AvailabilityTracker;
import org.openhab.binding.mqtt.generic.ChannelStateUpdateListener;
import org.openhab.binding.mqtt.generic.MqttChannelTypeProvider;
@ -68,6 +71,8 @@ import com.google.gson.GsonBuilder;
*
* @author David Graeff - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
@NonNullByDefault
public class HomeAssistantMQTTImplementationTest extends JavaOSGiTest {
private @NonNullByDefault({}) ConfigurationAdmin configurationAdmin;
@ -77,8 +82,6 @@ public class HomeAssistantMQTTImplementationTest extends JavaOSGiTest {
private int registeredTopics = 100;
private @Nullable Throwable failure;
private @NonNullByDefault({}) AutoCloseable mocksCloseable;
private @Mock @NonNullByDefault({}) ChannelStateUpdateListener channelStateUpdateListener;
private @Mock @NonNullByDefault({}) AvailabilityTracker availabilityTracker;
private @Mock @NonNullByDefault({}) TransformationServiceProvider transformationServiceProvider;
@ -95,7 +98,6 @@ public class HomeAssistantMQTTImplementationTest extends JavaOSGiTest {
@BeforeEach
public void beforeEach() throws Exception {
registerVolatileStorageService();
mocksCloseable = openMocks(this);
configurationAdmin = getService(ConfigurationAdmin.class);
mqttService = getService(MqttService.class);
@ -133,8 +135,6 @@ public class HomeAssistantMQTTImplementationTest extends JavaOSGiTest {
connection.removeConnectionObserver(failIfChange);
connection.stop().get(2, TimeUnit.SECONDS);
}
mocksCloseable.close();
}
@Test

View File

@ -17,7 +17,6 @@ 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.openMocks;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@ -35,8 +34,12 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.openhab.binding.mqtt.generic.ChannelState;
import org.openhab.binding.mqtt.generic.tools.ChildMap;
import org.openhab.binding.mqtt.generic.tools.WaitForTopicValue;
@ -66,6 +69,8 @@ import org.osgi.service.cm.ConfigurationAdmin;
*
* @author David Graeff - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
@NonNullByDefault
public class HomieImplementationTest extends JavaOSGiTest {
private static final String BASE_TOPIC = "homie";
@ -78,8 +83,6 @@ public class HomieImplementationTest extends JavaOSGiTest {
private @NonNullByDefault({}) MqttBrokerConnection connection;
private int registeredTopics = 100;
private @NonNullByDefault({}) AutoCloseable mocksCloseable;
// The handler is not tested here, so just mock the callback
private @Mock @NonNullByDefault({}) DeviceCallback callback;
@ -100,7 +103,6 @@ public class HomieImplementationTest extends JavaOSGiTest {
@BeforeEach
public void beforeEach() throws Exception {
registerVolatileStorageService();
mocksCloseable = openMocks(this);
configurationAdmin = getService(ConfigurationAdmin.class);
mqttService = getService(MqttService.class);
@ -168,7 +170,6 @@ public class HomieImplementationTest extends JavaOSGiTest {
if (scheduler != null) {
scheduler.shutdownNow();
}
mocksCloseable.close();
}
@Test

View File

@ -39,7 +39,6 @@ Fragment-Host: org.openhab.binding.nest
org.eclipse.jetty.websocket.client;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.websocket.common;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\
org.objenesis;version='[2.6.0,2.6.1)',\
org.ops4j.pax.swissbox.optional.jcl;version='[1.8.3,1.8.4)',\
org.osgi.service.event;version='[1.4.0,1.4.1)',\
org.osgi.service.jaxrs;version='[1.0.0,1.0.1)',\
@ -49,15 +48,7 @@ Fragment-Host: org.openhab.binding.nest
tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\
tec.uom.se;version='[1.0.10,1.0.11)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.mockito.mockito-core;version='[3.4.6,3.4.7)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
org.apache.aries.jax.rs.whiteboard;version='[1.0.9,1.0.10)',\
@ -86,4 +77,14 @@ Fragment-Host: org.openhab.binding.nest
org.openhab.core.test;version='[3.1.0,3.1.1)',\
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
org.openhab.core.thing.xml;version='[3.1.0,3.1.1)',\
xstream;version='[1.4.15,1.4.16)'
xstream;version='[1.4.15,1.4.16)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)',\
net.bytebuddy.byte-buddy;version='[1.10.19,1.10.20)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.19,1.10.20)',\
org.mockito.junit-jupiter;version='[3.7.0,3.7.1)',\
org.mockito.mockito-core;version='[3.7.0,3.7.1)',\
org.objenesis;version='[3.1.0,3.1.1)'

View File

@ -10,7 +10,7 @@
<appender-ref ref="STDOUT" />
</logger>
<root level="debug">
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -16,15 +16,15 @@ import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.openMocks;
import javax.ws.rs.client.ClientBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openhab.binding.nest.internal.config.NestBridgeConfiguration;
import org.openhab.binding.nest.internal.handler.NestBridgeHandler;
import org.openhab.binding.nest.internal.handler.NestRedirectUrlSupplier;
@ -42,12 +42,11 @@ import org.osgi.service.jaxrs.client.SseEventSourceFactory;
*
* @author David Bennett - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
public class NestBridgeHandlerTest {
private ThingHandler handler;
private AutoCloseable mocksCloseable;
private @Mock Bridge bridge;
private @Mock ThingHandlerCallback callback;
private @Mock ClientBuilder clientBuilder;
@ -57,16 +56,10 @@ public class NestBridgeHandlerTest {
@BeforeEach
public void beforeEach() {
mocksCloseable = openMocks(this);
handler = new NestTestBridgeHandler(bridge, clientBuilder, eventSourceFactory, "http://localhost");
handler.setCallback(callback);
}
@AfterEach
public void afterEach() throws Exception {
mocksCloseable.close();
}
@SuppressWarnings("null")
@Test
public void initializeShouldCallTheCallback() {

View File

@ -26,7 +26,6 @@ Fragment-Host: org.openhab.binding.ntp
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
org.objenesis;version='[2.6.0,2.6.1)',\
org.osgi.service.event;version='[1.4.0,1.4.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\
@ -38,15 +37,7 @@ Fragment-Host: org.openhab.binding.ntp
org.eclipse.jetty.servlet;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.util;version='[9.4.20,9.4.21)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.mockito.mockito-core;version='[3.4.6,3.4.7)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
@ -63,4 +54,13 @@ Fragment-Host: org.openhab.binding.ntp
org.openhab.core.test;version='[3.1.0,3.1.1)',\
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
org.openhab.core.thing.xml;version='[3.1.0,3.1.1)',\
xstream;version='[1.4.15,1.4.16)'
xstream;version='[1.4.15,1.4.16)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)',\
net.bytebuddy.byte-buddy;version='[1.10.19,1.10.20)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.19,1.10.20)',\
org.mockito.mockito-core;version='[3.7.0,3.7.1)',\
org.objenesis;version='[3.1.0,3.1.1)'

View File

@ -25,7 +25,6 @@ Fragment-Host: org.openhab.binding.systeminfo
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
org.osgi.service.event;version='[1.4.0,1.4.1)',\
org.objenesis;version='[2.6.0,2.6.1)',\
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
slf4j.api;version='[1.7.25,1.7.26)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
@ -41,15 +40,7 @@ Fragment-Host: org.openhab.binding.systeminfo
org.eclipse.jetty.servlet;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.util;version='[9.4.20,9.4.21)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.mockito.mockito-core;version='[3.4.6,3.4.7)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
@ -66,4 +57,13 @@ Fragment-Host: org.openhab.binding.systeminfo
org.openhab.core.test;version='[3.1.0,3.1.1)',\
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
org.openhab.core.thing.xml;version='[3.1.0,3.1.1)',\
xstream;version='[1.4.15,1.4.16)'
xstream;version='[1.4.15,1.4.16)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)',\
net.bytebuddy.byte-buddy;version='[1.10.19,1.10.20)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.19,1.10.20)',\
org.mockito.mockito-core;version='[3.7.0,3.7.1)',\
org.objenesis;version='[3.1.0,3.1.1)'

View File

@ -26,7 +26,6 @@ Fragment-Host: org.openhab.binding.tradfri
com.google.gson;version='[2.8.2,2.8.3)',\
javax.jmdns;version='[3.5.6,3.5.7)',\
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.objenesis;version='[2.6.0,2.6.1)',\
tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\
tec.uom.se;version='[1.0.10,1.0.11)',\
org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\
@ -40,15 +39,7 @@ Fragment-Host: org.openhab.binding.tradfri
org.eclipse.californium.scandium;version='[2.0.0,2.0.1)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.mockito.mockito-core;version='[3.4.6,3.4.7)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
@ -67,4 +58,14 @@ Fragment-Host: org.openhab.binding.tradfri
org.openhab.core.test;version='[3.1.0,3.1.1)',\
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
org.openhab.core.thing.xml;version='[3.1.0,3.1.1)',\
xstream;version='[1.4.15,1.4.16)'
xstream;version='[1.4.15,1.4.16)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)',\
net.bytebuddy.byte-buddy;version='[1.10.19,1.10.20)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.19,1.10.20)',\
org.mockito.junit-jupiter;version='[3.7.0,3.7.1)',\
org.mockito.mockito-core;version='[3.7.0,3.7.1)',\
org.objenesis;version='[3.1.0,3.1.1)'

View File

@ -16,15 +16,17 @@ import static org.hamcrest.CoreMatchers.*;
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.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.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultFlag;
import org.openhab.core.config.discovery.mdns.MDNSDiscoveryParticipant;
@ -37,19 +39,17 @@ import org.openhab.core.thing.ThingUID;
*
* @author Kai Kreuzer - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
public class TradfriDiscoveryParticipantOSGITest extends JavaOSGiTest {
private MDNSDiscoveryParticipant discoveryParticipant;
private AutoCloseable mocksCloseable;
private @Mock ServiceInfo tradfriGateway;
private @Mock ServiceInfo otherDevice;
@BeforeEach
public void beforeEach() {
mocksCloseable = openMocks(this);
discoveryParticipant = getService(MDNSDiscoveryParticipant.class, TradfriDiscoveryParticipant.class);
when(tradfriGateway.getType()).thenReturn("_coap._udp.local.");
@ -65,11 +65,6 @@ 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

@ -25,7 +25,6 @@ Fragment-Host: org.openhab.binding.wemo
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
org.jupnp;version='[2.5.2,2.5.3)',\
org.objenesis;version='[2.6.0,2.6.1)',\
org.osgi.service.event;version='[1.4.0,1.4.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\
@ -43,15 +42,7 @@ Fragment-Host: org.openhab.binding.wemo
org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
net.bytebuddy.byte-buddy;version='[1.10.13,1.10.14)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.13,1.10.14)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.mockito.mockito-core;version='[3.4.6,3.4.7)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
@ -77,4 +68,13 @@ Fragment-Host: org.openhab.binding.wemo
org.openhab.core.test;version='[3.1.0,3.1.1)',\
org.openhab.core.thing;version='[3.1.0,3.1.1)',\
org.openhab.core.thing.xml;version='[3.1.0,3.1.1)',\
xstream;version='[1.4.15,1.4.16)'
xstream;version='[1.4.15,1.4.16)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)',\
net.bytebuddy.byte-buddy;version='[1.10.19,1.10.20)',\
net.bytebuddy.byte-buddy-agent;version='[1.10.19,1.10.20)',\
org.mockito.mockito-core;version='[3.7.0,3.7.1)',\
org.objenesis;version='[3.1.0,3.1.1)'

View File

@ -34,11 +34,6 @@ Fragment-Host: org.openhab.persistence.mapdb
org.eclipse.jetty.servlet;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.util;version='[9.4.20,9.4.21)',\
biz.aQute.tester.junit-platform;version='[5.1.2,5.1.3)',\
junit-jupiter-api;version='[5.6.2,5.6.3)',\
junit-jupiter-engine;version='[5.6.2,5.6.3)',\
junit-platform-commons;version='[1.6.2,1.6.3)',\
junit-platform-engine;version='[1.6.2,1.6.3)',\
junit-platform-launcher;version='[1.6.2,1.6.3)',\
org.hamcrest;version='[2.2.0,2.2.1)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
@ -50,4 +45,9 @@ Fragment-Host: org.openhab.persistence.mapdb
org.openhab.core.persistence;version='[3.1.0,3.1.1)',\
org.openhab.core.test;version='[3.1.0,3.1.1)',\
org.openhab.persistence.mapdb;version='[3.1.0,3.1.1)',\
org.openhab.persistence.mapdb.tests;version='[3.1.0,3.1.1)'
org.openhab.persistence.mapdb.tests;version='[3.1.0,3.1.1)',\
junit-jupiter-api;version='[5.7.0,5.7.1)',\
junit-jupiter-engine;version='[5.7.0,5.7.1)',\
junit-platform-commons;version='[1.7.0,1.7.1)',\
junit-platform-engine;version='[1.7.0,1.7.1)',\
junit-platform-launcher;version='[1.7.0,1.7.1)'