package com.truphone.cascades;

import java.io.PrintStream;

import org.junit.Assert;
import org.junit.Test;

import com.truphone.cascades.FakeDevice.FakeDeviceListener;
import com.truphone.cascades.commands.TouchCommand;
import com.truphone.cascades.commands.TouchCommand.TouchLocation;
import com.truphone.cascades.commands.TouchCommand.Type;
import com.truphone.cascades.replys.IReply;

/**
 * Test class.
 * @author STruscott
 *
 */
public final class TestTouchCommand {

	/**
	 * Test the Touch command.
	 * @throws TimeoutException Thrown if the command times out
	 */
	@Test
	public void testTouchUpCommand() throws TimeoutException {
		final FakeDeviceListener response = new FakeDeviceListener() {
			@Override
			public void messageReceived(String message, PrintStream replyStream) {
				if ("touch 1 2 3 4 5 6 2 receiver target".equals(message)) {
					replyStream.println(FakeDevice.OK_MESSAGE);
				} else {
					Assert.fail(message);
				}
			}
		};
		FakeDevice.DEVICE.getProcess().addListener(response);
		final IReply reply = FakeDevice.CONN.transmit(new TouchCommand(new TouchLocation(1, 2, 3, 4, 5, 6), Type.UP, "receiver", "target"), FakeDevice.DEFAULT_TIMEOUT);
		FakeDevice.DEVICE.getProcess().removeListener(response);
		Assert.assertTrue(reply.isSuccess());
	}

	/**
	 * Test the Touch command.
	 * @throws TimeoutException Thrown if the command times out
	 */
	@Test
	public void testTouchDownCommand() throws TimeoutException {
		final FakeDeviceListener response = new FakeDeviceListener() {
			@Override
			public void messageReceived(String message, PrintStream replyStream) {
				if ("touch 1 2 3 4 5 6 0 receiver target".equals(message)) {
					replyStream.println(FakeDevice.OK_MESSAGE);
				} else {
					Assert.fail(message);
				}
			}
		};
		FakeDevice.DEVICE.getProcess().addListener(response);
		final IReply reply = FakeDevice.CONN.transmit(new TouchCommand(new TouchLocation(1, 2, 3, 4, 5, 6), Type.DOWN, "receiver", "target"), FakeDevice.DEFAULT_TIMEOUT);
		FakeDevice.DEVICE.getProcess().removeListener(response);
		Assert.assertTrue(reply.isSuccess());
	}

	/**
	 * Test the Touch command.
	 * @throws TimeoutException Thrown if the command times out
	 */
	@Test
	public void testTouchMoveCommand() throws TimeoutException {
		final FakeDeviceListener response = new FakeDeviceListener() {
			@Override
			public void messageReceived(String message, PrintStream replyStream) {
				if ("touch 1 2 3 4 5 6 1 receiver target".equals(message)) {
					replyStream.println(FakeDevice.OK_MESSAGE);
				} else {
					Assert.fail(message);
				}
			}
		};
		FakeDevice.DEVICE.getProcess().addListener(response);
		final IReply reply = FakeDevice.CONN.transmit(new TouchCommand(new TouchLocation(1, 2, 3, 4, 5, 6), Type.MOVE, "receiver", "target"), FakeDevice.DEFAULT_TIMEOUT);
		FakeDevice.DEVICE.getProcess().removeListener(response);
		Assert.assertTrue(reply.isSuccess());
	}

	/**
	 * Test the Touch command.
	 * @throws TimeoutException Thrown if the command times out
	 */
	@Test
	public void testTouchCancelCommand() throws TimeoutException {
		final FakeDeviceListener response = new FakeDeviceListener() {
			@Override
			public void messageReceived(String message, PrintStream replyStream) {
				if ("touch 1 2 3 4 5 6 3 receiver target".equals(message)) {
					replyStream.println(FakeDevice.OK_MESSAGE);
				} else {
					Assert.fail(message);
				}
			}
		};
		FakeDevice.DEVICE.getProcess().addListener(response);
		final IReply reply = FakeDevice.CONN.transmit(new TouchCommand(new TouchLocation(1, 2, 3, 4, 5, 6), Type.CANCEL, "receiver", "target"), FakeDevice.DEFAULT_TIMEOUT);
		FakeDevice.DEVICE.getProcess().removeListener(response);
		Assert.assertTrue(reply.isSuccess());
	}
}

Add unit tests for the touch command.