@@ -0,0 +1,2270 @@
+/*%0A * To change this license header, choose License Headers in Project Properties.%0A * To change this template file, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0Apackage ships.controller;%0A%0Aimport java.io.ByteArrayInputStream;%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.net.Socket;%0Aimport org.junit.After;%0Aimport org.junit.AfterClass;%0Aimport org.junit.Before;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0Aimport static org.junit.Assert.*;%0Aimport org.mockito.InjectMocks;%0Aimport org.mockito.Mock;%0Aimport static org.mockito.Mockito.when;%0Aimport org.mockito.MockitoAnnotations;%0Aimport ships.model.Field;%0Aimport ships.model.FieldImpl;%0A%0A/**%0A *%0A * @author r4pt0r%0A */%0Apublic class TCPClientConnectionTest %7B%0A%0A    public TCPClientConnectionTest() %7B%0A    %7D%0A%0A    @BeforeClass%0A    public static void setUpClass() %7B%0A    %7D%0A%0A    @AfterClass%0A    public static void tearDownClass() %7B%0A    %7D%0A%0A    @Before%0A    public void setUp() %7B%0A        MockitoAnnotations.initMocks(this);%0A    %7D%0A%0A    @After%0A    public void tearDown() %7B%0A    %7D%0A%0A    @Mock%0A    Socket sock;%0A%0A    @InjectMocks%0A    TCPClientConnection sut = new TCPClientConnection(sock);%0A%0A    @Test%0A    public void shouldSendAndReceiveMovePacket() throws IOException %7B%0A        //given%0A        String expected = %22%7B%22%0A                + %22%5C%22field%5C%22:%5B%22%0A                + %22%5C%22ships.model.FieldImpl%5C%22,%7B%22%0A                + %22%5C%22attacked%5C%22:false,%22%0A                + %22%5C%22state%5C%22:%5C%22EMPTY%5C%22,%22%0A                + %22%5C%22row%5C%22:1,%5C%22col%5C%22:2,%22 + %22%5C%22shipHere%5C%22:false%22%0A                + %22%7D%5D%7D%22;%0A        Field f = new FieldImpl(1, 2);%0A        ByteArrayOutputStream baos = new ByteArrayOutputStream();%0A        ByteArrayInputStream bais;%0A        when(sock.getOutputStream()).thenReturn(baos);%0A        when(sock.getInputStream()).thenReturn(null);%0A        MovePacket mp = new MovePacket(new FieldImpl(1, 2));%0A        //when%0A        sut.sendPacket(mp);%0A        String s = baos.toString();/////////////////////////////////////////////%0A//        bais = new ByteArrayInputStream(baos.toByteArray());%0A//        MovePacket packet = (MovePacket) sut.receivePacket();%0A//        Field receivedField = packet.getField();%0A        //then%0A        assertEquals(expected, s);%0A//        assertEquals(f, receivedField);%0A    %7D%0A%0A%7D%0A

Add tests for TCP connection