package communication;

import static org.junit.Assert.*;

import java.lang.reflect.Method;

import org.junit.Test;

import communication.messages.InitializeMessage;
import communication.messages.Message;

public class CommunicationTest {

	@Test
	public void testMessageToByteAndBack() throws Exception {
		MessageSender messageSender = new MessageSender();
		int numFloors = 5;
		int numElevators = 6;
		int floorMoveTime = 3000;
		int doorOperationDelay = 3000;
		InitializeMessage initializeMessage = new InitializeMessage(numFloors, numElevators, floorMoveTime, doorOperationDelay);

		Method messageToByteArray = MessageSender.class.getDeclaredMethod("messageToByteArray", Message.class);
		messageToByteArray.setAccessible(true);
		byte[] data = (byte[]) messageToByteArray.invoke(messageSender, initializeMessage);

		InitializeMessage returnMessage = (InitializeMessage) MessageUtil.byteArrayToMessage(data);
		assertEquals(numFloors, returnMessage.getNumFloors());
		assertEquals(numElevators, returnMessage.getNumElevators());
	}

}
