### Question:
MqttProtocolServer implements ProtocolServer { @Override public CompletableFuture<Void> expose(ExposedThing thing) { String baseUrl = createUrl(); log.info("MqttServer exposes '{}' at '{}{}/*'", thing.getId(), baseUrl, thing.getId()); if (settingsClientPair == null) { return failedFuture(new ProtocolServerException("Unable to expose thing before MqttServer has been started")); } things.put(thing.getId(), thing); exposeProperties(thing, baseUrl); exposeActions(thing, baseUrl); exposeEvents(thing, baseUrl); exposeTD(thing); listenOnMqttMessages(); return completedFuture(null); } MqttProtocolServer(RefCountResource<Pair<MqttProtocolSettings, MqttClient>> mqttClientProvider,
                       Multimap<String, Disposable> subscriptions,
                       Pair<MqttProtocolSettings, MqttClient> settingsClientPair);  MqttProtocolServer(Config config); @Override CompletableFuture<Void> start(Servient servient); @Override CompletableFuture<Void> stop(); @Override CompletableFuture<Void> expose(ExposedThing thing); @Override CompletableFuture<Void> destroy(ExposedThing thing);  }### Answer:
@Test public void exposeShouldPublishThingDescription() throws MqttException { when(thing.getId()).thenReturn("counter"); when(settingsClientPair.first()).thenReturn(settings); when(settingsClientPair.second()).thenReturn(mqttClient); when(settings.getBroker()).thenReturn("tcp: server = new MqttProtocolServer(refCountResource, subcriptions, settingsClientPair); server.expose(thing); verify(mqttClient).publish(eq("counter"), any()); }
@Test public void exposeShouldExposeProperties() { when(thing.getId()).thenReturn("counter"); when(thing.getProperties()).thenReturn(Map.of("count", property)); when(property.observer()).thenReturn(PublishSubject.create()); when(settingsClientPair.first()).thenReturn(settings); when(settingsClientPair.second()).thenReturn(mqttClient); when(settings.getBroker()).thenReturn("tcp: server = new MqttProtocolServer(refCountResource, subcriptions, settingsClientPair); server.expose(thing); verify(property).addForm(any()); }
@Test public void exposeShouldExposeActions() { when(thing.getId()).thenReturn("counter"); when(thing.getActions()).thenReturn(Map.of("increment", action)); when(settingsClientPair.first()).thenReturn(settings); when(settingsClientPair.second()).thenReturn(mqttClient); when(settings.getBroker()).thenReturn("tcp: server = new MqttProtocolServer(refCountResource, subcriptions, settingsClientPair); server.expose(thing); verify(action).addForm(any()); }
@Test public void exposeShouldExposeEvents() { when(thing.getId()).thenReturn("counter"); when(thing.getEvents()).thenReturn(Map.of("changed", event)); when(event.observer()).thenReturn(PublishSubject.create()); when(settingsClientPair.first()).thenReturn(settings); when(settingsClientPair.second()).thenReturn(mqttClient); when(settings.getBroker()).thenReturn("tcp: server = new MqttProtocolServer(refCountResource, subcriptions, settingsClientPair); server.expose(thing); verify(event).addForm(any()); }