]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mqtt.generic] Fix JUnit tests (#8921)
authorJochen Klein <git@jochen.susca.de>
Sun, 1 Nov 2020 21:51:51 +0000 (22:51 +0100)
committerGitHub <noreply@github.com>
Sun, 1 Nov 2020 21:51:51 +0000 (13:51 -0800)
* Fix JUnit tests
* remove extra character in copyright comment
* Cleanup mockito warnings

Signed-off-by: Jochen Klein <git@jochen.susca.de>
bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/handler/AbstractBrokerHandlerTest.java
bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/handler/BrokerHandlerTest.java
bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/handler/MqttAsyncClientWrapperEx.java [new file with mode: 0644]
bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/handler/MqttBrokerConnectionEx.java
bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java [new file with mode: 0644]
bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java.tobefixed [deleted file]
bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/discovery/ServiceDiscoveryServiceTest.java

index f6ff6355877a916249e9b826f6aff0b252bfbe8b..3bebbfa3adb5733d5a0b54f51d6df5656ba34f79 100644 (file)
@@ -15,7 +15,7 @@ package org.openhab.binding.mqtt.handler;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.*;
 
 import java.util.Collections;
@@ -30,7 +30,6 @@ import org.mockito.quality.Strictness;
 import org.openhab.binding.mqtt.internal.MqttThingID;
 import org.openhab.core.config.core.Configuration;
 import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
-import org.openhab.core.io.transport.mqtt.MqttConnectionState;
 import org.openhab.core.io.transport.mqtt.MqttException;
 import org.openhab.core.io.transport.mqtt.MqttService;
 import org.openhab.core.thing.Bridge;
@@ -56,7 +55,6 @@ public class AbstractBrokerHandlerTest {
 
     @BeforeEach
     public void setUp() {
-        doReturn(MqttThingID.getThingUID(HOST, PORT)).when(thing).getUID();
         doReturn(new Configuration(Collections.singletonMap("brokerid", MqttThingID.getThingUID(HOST, PORT).getId())))
                 .when(thing).getConfiguration();
         handler = new SystemBrokerHandler(thing, service);
@@ -68,7 +66,6 @@ public class AbstractBrokerHandlerTest {
     @Test
     public void brokerAddedWrongID() throws ConfigurationException, MqttException {
         MqttBrokerConnection brokerConnection = mock(MqttBrokerConnection.class);
-        when(brokerConnection.connectionState()).thenReturn(MqttConnectionState.CONNECTED);
         handler.brokerAdded("nonsense_id", brokerConnection);
         assertNull(handler.connection);
         // We do not expect a status change, because brokerAdded will do nothing with invalid connections.
@@ -89,7 +86,6 @@ public class AbstractBrokerHandlerTest {
     public void brokerAdded() throws ConfigurationException, MqttException {
         MqttBrokerConnectionEx connection = spy(
                 new MqttBrokerConnectionEx("10.10.0.10", 80, false, "BrokerHandlerTest"));
-        doReturn(connection).when(service).getBrokerConnection(eq(handler.brokerID));
 
         verify(callback, times(0)).statusUpdated(any(), any());
         handler.brokerAdded(handler.brokerID, connection);
index b56ebf508ed68b9eb90db44440571acce65458f8..6498ccf54189ca2fc25ce3c4e727b9d2f97b5fc1 100644 (file)
@@ -30,7 +30,6 @@ 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.internal.MqttThingID;
 import org.openhab.core.config.core.Configuration;
 import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
 import org.openhab.core.io.transport.mqtt.MqttConnectionState;
@@ -63,7 +62,6 @@ public class BrokerHandlerTest {
     @BeforeEach
     public void setUp() throws ConfigurationException, MqttException {
         scheduler = new ScheduledThreadPoolExecutor(1);
-        when(thing.getUID()).thenReturn(MqttThingID.getThingUID("10.10.0.10", 80));
         connection = spy(new MqttBrokerConnectionEx("10.10.0.10", 80, false, "BrokerHandlerTest"));
         connection.setTimeoutExecutor(scheduler, 10);
         connection.setConnectionCallback(connection);
diff --git a/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/handler/MqttAsyncClientWrapperEx.java b/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/handler/MqttAsyncClientWrapperEx.java
new file mode 100644 (file)
index 0000000..e320996
--- /dev/null
@@ -0,0 +1,88 @@
+/**
+ * Copyright (c) 2010-2020 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.mqtt.handler;
+
+import java.util.concurrent.CompletableFuture;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.core.io.transport.mqtt.MqttConnectionState;
+import org.openhab.core.io.transport.mqtt.MqttWillAndTestament;
+import org.openhab.core.io.transport.mqtt.internal.Subscription;
+import org.openhab.core.io.transport.mqtt.internal.client.MqttAsyncClientWrapper;
+
+import com.hivemq.client.mqtt.MqttClientState;
+
+/**
+ * We need an extended MqttAsyncClientWrapper, that will, in respect to the success flags of the connection, immediately
+ * succeed or fail with publish, subscribe, unsubscribe, connect, disconnect.
+ *
+ * @author Jochen Klein - Initial contribution
+ */
+@NonNullByDefault
+public class MqttAsyncClientWrapperEx extends MqttAsyncClientWrapper {
+
+    private final MqttBrokerConnectionEx connection;
+
+    public MqttAsyncClientWrapperEx(MqttBrokerConnectionEx connection) {
+        super();
+        this.connection = connection;
+    }
+
+    @Override
+    public CompletableFuture<?> connect(@Nullable MqttWillAndTestament lwt, int keepAliveInterval,
+            @Nullable String username, @Nullable String password) {
+        if (!connection.connectTimeout) {
+            connection.getCallback().onConnected(null);
+            connection.connectionStateOverwrite = MqttConnectionState.CONNECTED;
+            return CompletableFuture.completedFuture(null);
+        }
+        return new CompletableFuture<>();
+    }
+
+    @Override
+    public CompletableFuture<@Nullable Void> disconnect() {
+        if (connection.disconnectSuccess) {
+            connection.getCallback().onDisconnected(new Throwable("disconnect called"));
+            connection.connectionStateOverwrite = MqttConnectionState.DISCONNECTED;
+            return CompletableFuture.completedFuture(null);
+        }
+        return new CompletableFuture<>();
+    }
+
+    @Override
+    public MqttClientState getState() {
+        return MqttClientState.CONNECTED;
+    }
+
+    @Override
+    public CompletableFuture<?> publish(String topic, byte[] payload, boolean retain, int qos) {
+        return CompletableFuture.completedFuture(null);
+    }
+
+    @Override
+    public CompletableFuture<?> subscribe(String topic, int qos, Subscription subscription) {
+        if (connection.subscribeSuccess) {
+            return CompletableFuture.completedFuture(null);
+        }
+        return CompletableFuture.failedFuture(new Throwable("subscription failed"));
+    }
+
+    @Override
+    public CompletableFuture<?> unsubscribe(String topic) {
+        if (connection.unsubscribeSuccess) {
+            return CompletableFuture.completedFuture(null);
+        }
+        return CompletableFuture.failedFuture(new Throwable("unsubscription failed"));
+    }
+}
index f09a110327fd7e2b950b82bfd7a20d09ce8e1248..fe895a27d174d9aee35337ac7d0b9b7c017d5868 100644 (file)
  */
 package org.openhab.binding.mqtt.handler;
 
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.spy;
 
 import java.util.Map;
-import java.util.concurrent.CompletableFuture;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -26,8 +24,6 @@ import org.openhab.core.io.transport.mqtt.MqttConnectionState;
 import org.openhab.core.io.transport.mqtt.internal.Subscription;
 import org.openhab.core.io.transport.mqtt.internal.client.MqttAsyncClientWrapper;
 
-import com.hivemq.client.mqtt.MqttClientState;
-
 /**
  * We need an extended MqttBrokerConnection to overwrite the protected `connectionCallbacks` with
  * an instance that takes the mocked version of `MqttBrokerConnection` and overwrite the connection state.
@@ -59,51 +55,13 @@ public class MqttBrokerConnectionEx extends MqttBrokerConnection {
         return subscribers;
     }
 
+    public ConnectionCallback getCallback() {
+        return connectionCallback;
+    }
+
     @Override
     protected MqttAsyncClientWrapper createClient() {
-        MqttAsyncClientWrapper mockedClient = mock(MqttAsyncClientWrapper.class);
-        // connect
-        doAnswer(i -> {
-            if (!connectTimeout) {
-                connectionCallback.onConnected(null);
-                connectionStateOverwrite = MqttConnectionState.CONNECTED;
-                return CompletableFuture.completedFuture(null);
-            }
-            return new CompletableFuture<>();
-        }).when(mockedClient).connect(any(), anyInt(), any(), any());
-        doAnswer(i -> {
-            if (disconnectSuccess) {
-                connectionCallback.onDisconnected(new Throwable("disconnect called"));
-                connectionStateOverwrite = MqttConnectionState.DISCONNECTED;
-                return CompletableFuture.completedFuture(null);
-            }
-            return new CompletableFuture<>();
-        }).when(mockedClient).disconnect();
-        // subscribe
-        doAnswer(i -> {
-            if (subscribeSuccess) {
-                return CompletableFuture.completedFuture(null);
-            } else {
-                CompletableFuture<Void> future = new CompletableFuture<>();
-                future.completeExceptionally(new Throwable("subscription failed"));
-                return future;
-            }
-        }).when(mockedClient).subscribe(any(), anyInt(), any());
-        // unsubscribe
-        doAnswer(i -> {
-            if (unsubscribeSuccess) {
-                return CompletableFuture.completedFuture(null);
-            } else {
-                CompletableFuture<Void> future = new CompletableFuture<>();
-                future.completeExceptionally(new Throwable("unsubscription failed"));
-                return future;
-            }
-        }).when(mockedClient).unsubscribe(any());
-        // state
-        doAnswer(i -> {
-            return MqttClientState.CONNECTED;
-        }).when(mockedClient).getState();
-        return mockedClient;
+        return new MqttAsyncClientWrapperEx(this);
     }
 
     @Override
diff --git a/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java b/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java
new file mode 100644 (file)
index 0000000..8688293
--- /dev/null
@@ -0,0 +1,153 @@
+/**
+ * Copyright (c) 2010-2020 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.mqtt.internal;
+
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
+
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+
+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.discovery.MQTTTopicDiscoveryParticipant;
+import org.openhab.binding.mqtt.discovery.MQTTTopicDiscoveryService;
+import org.openhab.binding.mqtt.handler.BrokerHandler;
+import org.openhab.binding.mqtt.handler.BrokerHandlerEx;
+import org.openhab.binding.mqtt.handler.MqttBrokerConnectionEx;
+import org.openhab.core.config.core.Configuration;
+import org.openhab.core.io.transport.mqtt.MqttService;
+import org.openhab.core.thing.Bridge;
+import org.openhab.core.thing.binding.ThingHandlerCallback;
+
+/**
+ * Test cases for the {@link MQTTTopicDiscoveryService} service.
+ *
+ * @author David Graeff - Initial contribution
+ */
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.WARN)
+public class MQTTTopicDiscoveryServiceTest {
+    private ScheduledExecutorService scheduler;
+
+    private MqttBrokerHandlerFactory subject;
+
+    @Mock
+    private MqttService mqttService;
+
+    @Mock
+    private Bridge thing;
+
+    @Mock
+    private ThingHandlerCallback callback;
+
+    @Mock
+    MQTTTopicDiscoveryParticipant listener;
+
+    private MqttBrokerConnectionEx connection;
+
+    private BrokerHandler handler;
+
+    @BeforeEach
+    public void setUp() {
+        scheduler = new ScheduledThreadPoolExecutor(1);
+
+        when(thing.getUID()).thenReturn(MqttThingID.getThingUID("10.10.0.10", 80));
+        connection = spy(new MqttBrokerConnectionEx("10.10.0.10", 80, false, "BrokerHandlerTest"));
+        connection.setTimeoutExecutor(scheduler, 10);
+        connection.setConnectionCallback(connection);
+
+        Configuration config = new Configuration();
+        config.put("host", "10.10.0.10");
+        config.put("port", 80);
+        when(thing.getConfiguration()).thenReturn(config);
+
+        handler = spy(new BrokerHandlerEx(thing, connection));
+        handler.setCallback(callback);
+
+        subject = new MqttBrokerHandlerFactory(mqttService);
+    }
+
+    @AfterEach
+    public void tearDown() {
+        scheduler.shutdownNow();
+    }
+
+    @Test
+    public void firstSubscribeThenHandler() {
+        handler.initialize();
+        BrokerHandlerEx.verifyCreateBrokerConnection(handler, 1);
+
+        subject.subscribe(listener, "topic");
+        subject.createdHandler(handler);
+        assertThat(subject.discoveryTopics.get("topic"), hasItem(listener));
+        // Simulate receiving
+        final byte[] bytes = "TEST".getBytes();
+        connection.getSubscribers().get("topic").messageArrived("topic", bytes, false);
+        verify(listener).receivedMessage(eq(thing.getUID()), eq(connection), eq("topic"), eq(bytes));
+    }
+
+    @Test
+    public void firstHandlerThenSubscribe() {
+        handler.initialize();
+        BrokerHandlerEx.verifyCreateBrokerConnection(handler, 1);
+
+        subject.createdHandler(handler);
+        subject.subscribe(listener, "topic");
+        assertThat(subject.discoveryTopics.get("topic"), hasItem(listener));
+
+        // Simulate receiving
+        final byte[] bytes = "TEST".getBytes();
+        connection.getSubscribers().get("topic").messageArrived("topic", bytes, false);
+        verify(listener).receivedMessage(eq(thing.getUID()), eq(connection), eq("topic"), eq(bytes));
+    }
+
+    @Test
+    public void handlerInitializeAfterSubscribe() {
+        subject.createdHandler(handler);
+        subject.subscribe(listener, "topic");
+        assertThat(subject.discoveryTopics.get("topic"), hasItem(listener));
+
+        // Init handler -> create connection
+        handler.initialize();
+        BrokerHandlerEx.verifyCreateBrokerConnection(handler, 1);
+
+        // Simulate receiving
+        final byte[] bytes = "TEST".getBytes();
+        connection.getSubscribers().get("topic").messageArrived("topic", bytes, false);
+        verify(listener).receivedMessage(eq(thing.getUID()), eq(connection), eq("topic"), eq(bytes));
+    }
+
+    @Test
+    public void topicVanished() {
+        handler.initialize();
+        BrokerHandlerEx.verifyCreateBrokerConnection(handler, 1);
+
+        subject.createdHandler(handler);
+        subject.subscribe(listener, "topic");
+        assertThat(subject.discoveryTopics.get("topic"), hasItem(listener));
+
+        // Simulate receiving
+        final byte[] bytes = "".getBytes();
+        connection.getSubscribers().get("topic").messageArrived("topic", bytes, false);
+        verify(listener).topicVanished(eq(thing.getUID()), eq(connection), eq("topic"));
+    }
+}
diff --git a/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java.tobefixed b/bundles/org.openhab.binding.mqtt/src/test/java/org/openhab/binding/mqtt/internal/MQTTTopicDiscoveryServiceTest.java.tobefixed
deleted file mode 100644 (file)
index a05cd5e..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * Copyright (c) 2010-2020 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.mqtt.internal;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.*;
-
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-
-import org.openhab.core.config.core.Configuration;
-import org.openhab.core.thing.Bridge;
-import org.openhab.core.thing.binding.ThingHandlerCallback;
-import org.openhab.core.io.transport.mqtt.MqttException;
-import org.openhab.core.io.transport.mqtt.MqttService;
-import org.openhab.core.io.transport.mqtt.internal.Subscription;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.openhab.binding.mqtt.discovery.MQTTTopicDiscoveryParticipant;
-import org.openhab.binding.mqtt.discovery.MQTTTopicDiscoveryService;
-import org.openhab.binding.mqtt.handler.BrokerHandler;
-import org.openhab.binding.mqtt.handler.BrokerHandlerEx;
-import org.openhab.binding.mqtt.handler.MqttBrokerConnectionEx;
-import org.osgi.service.cm.ConfigurationException;
-
-/**
- * Test cases for the {@link MQTTTopicDiscoveryService} service.
- *
- * @author David Graeff - Initial contribution
- */
-public class MQTTTopicDiscoveryServiceTest {
-    private ScheduledExecutorService scheduler;
-
-    private MqttBrokerHandlerFactory subject;
-
-    @Mock
-    private MqttService mqttService;
-
-    @Mock
-    private Bridge thing;
-
-    @Mock
-    private ThingHandlerCallback callback;
-
-    @Mock
-    MQTTTopicDiscoveryParticipant listener;
-
-    private MqttBrokerConnectionEx connection;
-
-    private BrokerHandler handler;
-
-    @Before
-    public void setUp() throws ConfigurationException, MqttException {
-        scheduler = new ScheduledThreadPoolExecutor(1);
-        MockitoAnnotations.initMocks(this);
-
-        when(thing.getUID()).thenReturn(MqttThingID.getThingUID("10.10.0.10", 80));
-        connection = spy(new MqttBrokerConnectionEx("10.10.0.10", 80, false, "BrokerHandlerTest"));
-        connection.setTimeoutExecutor(scheduler, 10);
-        connection.setConnectionCallback(connection);
-
-        Configuration config = new Configuration();
-        config.put("host", "10.10.0.10");
-        config.put("port", 80);
-        when(thing.getConfiguration()).thenReturn(config);
-
-        handler = spy(new BrokerHandlerEx(thing, connection));
-        handler.setCallback(callback);
-
-        subject = new MqttBrokerHandlerFactory(mqttService);
-    }
-
-    @After
-    public void tearDown() {
-        scheduler.shutdownNow();
-    }
-
-    @Test
-    public void firstSubscribeThenHandler() {
-        handler.initialize();
-        BrokerHandlerEx.verifyCreateBrokerConnection(handler, 1);
-
-        subject.subscribe(listener, "topic");
-        subject.createdHandler(handler);
-        assertTrue(subject.discoveryTopics.get("topic").contains(listener));
-        // Simulate receiving
-        final byte[] bytes = "TEST".getBytes();
-        connection.getSubscribers().get("topic").forEach(s -> s.processMessage("topic", bytes));
-        verify(listener).receivedMessage(eq(thing.getUID()), eq(connection), eq("topic"), eq(bytes));
-    }
-
-    @Test
-    public void firstHandlerThenSubscribe() {
-        handler.initialize();
-        BrokerHandlerEx.verifyCreateBrokerConnection(handler, 1);
-
-        subject.createdHandler(handler);
-        subject.subscribe(listener, "topic");
-        assertTrue(subject.discoveryTopics.get("topic").contains(listener));
-
-        // Simulate receiving
-        final byte[] bytes = "TEST".getBytes();
-        connection.getSubscribers().get("topic").forEach(s -> s.processMessage("topic", bytes));
-        verify(listener).receivedMessage(eq(thing.getUID()), eq(connection), eq("topic"), eq(bytes));
-    }
-
-    @Test
-    public void handlerInitializeAfterSubscribe() {
-        subject.createdHandler(handler);
-        subject.subscribe(listener, "topic");
-        assertTrue(subject.discoveryTopics.get("topic").contains(listener));
-
-        // Init handler -> create connection
-        handler.initialize();
-        BrokerHandlerEx.verifyCreateBrokerConnection(handler, 1);
-
-        // Simulate receiving
-        final byte[] bytes = "TEST".getBytes();
-
-        connection.getSubscribers().getOrDefault("topic", new Subscription("topic"))
-                .forEach(s -> s.processMessage("topic", bytes));
-        verify(listener).receivedMessage(eq(thing.getUID()), eq(connection), eq("topic"), eq(bytes));
-    }
-
-    @Test
-    public void topicVanished() {
-        handler.initialize();
-        BrokerHandlerEx.verifyCreateBrokerConnection(handler, 1);
-
-        subject.createdHandler(handler);
-        subject.subscribe(listener, "topic");
-        assertTrue(subject.discoveryTopics.get("topic").contains(listener));
-
-        // Simulate receiving
-        final byte[] bytes = "".getBytes();
-        connection.getSubscribers().getOrDefault("topic", new Subscription("topic"))
-                .forEach(s -> s.processMessage("topic", bytes));
-        verify(listener).topicVanished(eq(thing.getUID()), eq(connection), eq("topic"));
-    }
-}
index cf342e3ddc9ea7a8d12d753e210e2ae13eb737e0..b4839b84d72f8da44d18e1c31916bdc7ca43f202 100644 (file)
@@ -21,8 +21,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
-import javax.naming.ConfigurationException;
-
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -50,7 +48,7 @@ public class ServiceDiscoveryServiceTest {
     private @Mock DiscoveryListener discoverListener;
 
     @BeforeEach
-    public void initMocks() throws ConfigurationException {
+    public void initMocks() {
         Map<String, MqttBrokerConnection> brokers = new TreeMap<>();
         brokers.put("testname", new MqttBrokerConnection("tcp://123.123.123.123", null, false, null));
         brokers.put("textual", new MqttBrokerConnection("tcp://123.123.123.123", null, true, null));
@@ -58,7 +56,7 @@ public class ServiceDiscoveryServiceTest {
     }
 
     @Test
-    public void testDiscovery() throws ConfigurationException {
+    public void testDiscovery() {
         // Setting the MqttService will enable the background scanner
         MqttServiceDiscoveryService d = new MqttServiceDiscoveryService();
         d.addDiscoveryListener(discoverListener);