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.test.java.JavaTest;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusInfo;
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
-public class BrokerHandlerTest {
+public class BrokerHandlerTest extends JavaTest {
private ScheduledExecutorService scheduler;
private @Mock ThingHandlerCallback callback;
private BrokerHandler handler;
@BeforeEach
- public void setUp() throws ConfigurationException, MqttException {
+ public void setUp() {
scheduler = new ScheduledThreadPoolExecutor(1);
connection = spy(new MqttBrokerConnectionEx("10.10.0.10", 80, false, "BrokerHandlerTest"));
- connection.setTimeoutExecutor(scheduler, 10);
+ connection.setTimeoutExecutor(scheduler, 10000);
connection.setConnectionCallback(connection);
Configuration config = new Configuration();
}
@Test
- public void handlerInitWithoutUrl()
- throws InterruptedException, IllegalArgumentException, MqttException, ConfigurationException {
+ public void handlerInitWithoutUrl() throws IllegalArgumentException {
// Assume it is a real handler and not a mock as defined above
handler = new BrokerHandler(thing);
assertThrows(IllegalArgumentException.class, () -> initializeHandlerWaitForTimeout());
}
@Test
- public void handlerInit()
- throws InterruptedException, IllegalArgumentException, MqttException, ConfigurationException {
+ public void handlerInit() throws InterruptedException, IllegalArgumentException {
assertThat(initializeHandlerWaitForTimeout(), is(true));
ArgumentCaptor<ThingStatusInfo> statusInfoCaptor = ArgumentCaptor.forClass(ThingStatusInfo.class);
* @throws MqttException
* @throws ConfigurationException
*/
- boolean initializeHandlerWaitForTimeout()
- throws InterruptedException, IllegalArgumentException, MqttException, ConfigurationException {
+ boolean initializeHandlerWaitForTimeout() throws InterruptedException, IllegalArgumentException {
MqttBrokerConnection c = connection;
MqttConnectionObserverEx o = new MqttConnectionObserverEx();
assertThat(connection.connectionState(), is(MqttConnectionState.DISCONNECTED));
handler.initialize();
- verify(connection, times(2)).addConnectionObserver(any());
- verify(connection, times(1)).start();
+ waitForAssert(() -> verify(connection, times(2)).addConnectionObserver(any()));
+ waitForAssert(() -> verify(connection, times(1)).start());
// First we expect a CONNECTING state and then a CONNECTED unique state change
- assertThat(o.counter, is(2));
+ waitForAssert(() -> assertThat(o.counter, is(2)));
// First we expect a CONNECTING state and then a CONNECTED state change
// (and other CONNECTED after the future completes)
- verify(handler, times(3)).connectionStateChanged(any(), any());
+ waitForAssert(() -> verify(handler, times(3)).connectionStateChanged(any(), any()));
return true;
}
}