package de.zh32.teleportsigns.server.status;

import org.junit.Before;
import org.junit.Test;

import java.io.*;
import java.net.InetSocketAddress;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
 * @author zh32
 */
public class QueryHandlerTest {

	//This is the response send by the official 1.9.2 server.
	private static final byte[] bytesSendByServer = new byte[]{
			0x79, 0x00, 0x77, 0x7b, 0x22, 0x64, 0x65, 0x73,
			0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
			0x22, 0x3a, 0x7b, 0x22, 0x74, 0x65, 0x78, 0x74,
			0x22, 0x3a, 0x22, 0x41, 0x20, 0x4d, 0x69, 0x6e,
			0x65, 0x63, 0x72, 0x61, 0x66, 0x74, 0x20, 0x53,
			0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0x7d, 0x2c,
			0x22, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73,
			0x22, 0x3a, 0x7b, 0x22, 0x6d, 0x61, 0x78, 0x22,
			0x3a, 0x32, 0x30, 0x2c, 0x22, 0x6f, 0x6e, 0x6c,
			0x69, 0x6e, 0x65, 0x22, 0x3a, 0x30, 0x7d, 0x2c,
			0x22, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
			0x22, 0x3a, 0x7b, 0x22, 0x6e, 0x61, 0x6d, 0x65,
			0x22, 0x3a, 0x22, 0x31, 0x2e, 0x39, 0x2e, 0x32,
			0x22, 0x2c, 0x22, 0x70, 0x72, 0x6f, 0x74, 0x6f,
			0x63, 0x6f, 0x6c, 0x22, 0x3a, 0x31, 0x30, 0x39,
			0x7d, 0x7d, 0x09, 0x01, 0x00, 0x00, 0x01, 0x53,
			(byte) 0xff, (byte) 0xdb,
			(byte) 0xf9, (byte) 0xea
	};

	private QueryHandler testee;

	@Before
	public void setup() {
		ServerListPing.ServerConnection connection = mock(ServerListPing.ServerConnection.class);
		when(connection.getDataOutputStream()).thenReturn(new DataOutputStream(mock(OutputStream.class)));
		when(connection.getDataInputStream()).thenReturn(new DataInputStream(new ByteArrayInputStream(bytesSendByServer)));
		when(connection.getHost()).thenReturn(new InetSocketAddress("localhost", 25555));
		testee = new QueryHandler(connection);
	}

	@Test
	public void can_handle_minecraft_protocol() throws IOException {
		testee.doHandShake();
		StatusResponse response = testee.doStatusQuery();
		assertThat(
				response,
				allOf(
						hasProperty("description",
								hasProperty("text",
										is(equalTo("A Minecraft Server"))
								)
						),
						hasProperty("version", allOf(
								hasProperty("name", is(equalTo("1.9.2"))),
								hasProperty("protocol", is(equalTo(109)))
						))
				)
		);
	}

}

@@ -1926,10 +1926,8 @@
 ows 
-IO
 Exce

Fix compiling of tests