package no.ntnu.okse.protocol.mqtt;

import org.testng.annotations.Test;

import static org.testng.Assert.*;


public class MQTTProtocolServerTest {

	@Test
	public void boot_changeState() {
		MQTTProtocolServer mqtt = getInstance();
		assertFalse(mqtt.isRunning());
		mqtt.boot();
		assertTrue(mqtt.isRunning());
		assertTrue(mqtt.isRunning());
	}

	@Test
	public void stopServer_startAndStop() throws InterruptedException {
		MQTTProtocolServer mqtt = getInstance();
		mqtt.boot();
		// Wait for server to boot
		Thread.sleep(1000);
		assertTrue(mqtt.isRunning());
		mqtt.stopServer();
		assertFalse(mqtt.isRunning());
	}

	@Test
	public void getProtocolServerType() {
		assertNotNull(getInstance().getProtocolServerType());
	}

	private MQTTProtocolServer getInstance() {
		return new MQTTProtocolServer("localhost", 1234);
	}


}

@@ -26,24 +26,239 @@
 ocol.mqtt;%0A%0A
+import no.ntnu.okse.core.messaging.Message;%0Aimport org.junit.Before;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.*;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0Aimport org.testng.annotations.BeforeMethod;%0A
 import org.t
@@ -318,17 +318,16 @@
 ert.*;%0A%0A
-%0A
 public c
@@ -363,89 +363,274 @@
 %0A%0A%09@
-Test%0A%09public void boot_changeState() %7B%0A%09%09MQTTProtocolServer mqtt = getInstance();
+InjectMocks%0A%09MQTTProtocolServer mqtt = new MQTTProtocolServer(%22localhost%22, 1234);%0A%09@Mock(name = %22server%22)%0A%09private MQTTServer mqttServerSpy;%0A%0A%09@BeforeMethod%0A%09public void initMocks() %7B%0A%09%09MockitoAnnotations.initMocks(this);%0A%09%7D%0A%0A%09@Test%0A%09public void boot_changeState() %7B
 %0A%09%09a
@@ -710,40 +710,8 @@
 ));%0A
-%09%09assertTrue(mqtt.isRunning());%0A
 %09%7D%0A%0A
@@ -790,51 +790,8 @@
 n %7B%0A
-%09%09MQTTProtocolServer mqtt = getInstance();%0A
 %09%09mq
@@ -1004,29 +1004,20 @@
 NotNull(
-getInstance()
+mqtt
 .getProt
@@ -1044,106 +1044,259 @@
 %7D%0A%0A%09
-private MQTTProtocolServer getInstance() %7B%0A%09%09return new MQTTProtocolServer(%22localhost%22, 1234
+@Test%0A%09public void sendMessage() %7B%0A%09%09Message message = createMessage();%0A%09%09mqtt.sendMessage(message);%0A%09%09Mockito.verify(mqttServerSpy).sendMessage(message);%0A%09%7D%0A%0A%09private Message createMessage() %7B%0A%09%09return new Message(%22Message%22, %22Topic%22, null, %22mqtt%22
 );%0A%09%7D%0A
-%0A%0A
 %7D%0A

Rewrite MQTTProtocolServerTest and add InjectMocks