mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Began fixing bugs with caused by asynchronous listener calls.
#bug
This commit is contained in:
@@ -5,9 +5,6 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import seng302.model.Colors;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ColorsTest {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package seng302;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test Class for the GeometryUtils class
|
||||
* Created by wmu16 on 24/05/17.
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package seng302;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.visualiser.controllers.RaceViewController;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class TestRaceTimer {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package seng302.model.mark;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Haoming on 17/3/17.
|
||||
*/
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
package seng302.model.stream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.Socket;
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
import seng302.model.stream.packets.StreamPacket;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Created by ptg19 on 26/04/17.
|
||||
*/
|
||||
public class StreamReceiverTest {
|
||||
|
||||
private PriorityBlockingQueue pq;
|
||||
private byte[] brokenPacket = {0x47, (byte) 0x83, 37, // sync1 sync2 and message type
|
||||
0b00000000, 0b01000000, 0b00100010, 0b00100100, 0b00011000, 0b00000000, //timestamp
|
||||
0b00000000, 0b00010000, 0b01000000, 0b00000000, //source id
|
||||
0b00100010, 0b00101000, // message length
|
||||
0b00010010, 0b00010010, 0b00010010}; //random start of payload
|
||||
|
||||
private byte[] workingPacket = {0x47, (byte) 0x83, 37, // sync1 sync2 and message type
|
||||
0b00000000, 0b01000000, 0b00100010, 0b00100100, 0b00011000, 0b00000000, //timestamp
|
||||
0b00000000, 0b00010000, 0b01000000, 0b00000000, //source id
|
||||
0b00000010, 0b00000000, // message length
|
||||
0b00010010, 0b00010010, // payload
|
||||
0b00100110, (byte)0b10000111, 0b00110101, 0b01111000}; //crc
|
||||
|
||||
private byte[] crcMismatchPacket = {0x47, (byte) 0x83, 37, // sync1 sync2 and message type
|
||||
0b00000000, 0b01000000, 0b00100010, 0b00100100, 0b00011000, 0b00000000, //timestamp
|
||||
0b00000000, 0b00000000, 0b01000000, 0b00000000, //source id
|
||||
0b00000010, 0b00000000, // message length
|
||||
0b00010010, 0b00010010, // payload
|
||||
0b00100110, (byte)0b10000111, 0b00110101, 0b01111000}; //crc
|
||||
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
pq = new PriorityBlockingQueue<>(256, new Comparator<StreamPacket>() {
|
||||
@Override
|
||||
public int compare(StreamPacket s1, StreamPacket s2) {
|
||||
return (int) (s1.getTimeStamp() - s2.getTimeStamp());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectExitsOnUnexpectedStreamEnd() throws Exception {
|
||||
Socket host=mock(Socket.class);
|
||||
InputStream stream = new ByteArrayInputStream(brokenPacket);
|
||||
when(host.getInputStream()).thenReturn(stream);
|
||||
StreamReceiver streamReceiver = new StreamReceiver(host, pq);
|
||||
|
||||
streamReceiver.connect();
|
||||
assert pq.size() == 0;
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void connectReadsAPacket() throws Exception {
|
||||
// Socket host=mock(Socket.class);
|
||||
// InputStream stream = new ByteArrayInputStream(workingPacket);
|
||||
// when(host.getInputStream()).thenReturn(stream);
|
||||
// StreamReceiver streamReceiver = new StreamReceiver(host, pq);
|
||||
//
|
||||
// streamReceiver.connect();
|
||||
// assert pq.size() == 1;
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void connectDropsAMismatchedCrc() throws Exception {
|
||||
Socket host=mock(Socket.class);
|
||||
InputStream stream = new ByteArrayInputStream(crcMismatchPacket);
|
||||
when(host.getInputStream()).thenReturn(stream);
|
||||
StreamReceiver streamReceiver = new StreamReceiver(host, pq);
|
||||
|
||||
streamReceiver.connect();
|
||||
assert pq.size() == 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bytestoLongTest() {
|
||||
Socket host=mock(Socket.class);
|
||||
StreamReceiver streamReceiver = new StreamReceiver(host, pq);
|
||||
try {
|
||||
Class[] args = new Class[1];
|
||||
args[0] = byte[].class;
|
||||
Method bytesToLong = streamReceiver.getClass().getDeclaredMethod("bytesToLong", args);
|
||||
bytesToLong.setAccessible(true);
|
||||
byte[] sevenBtyeNumber = {0b01100100, 0b00110100, 0b00010100, 0b00000000, 0b00000000, 0b00000000, (byte)0b10000000};
|
||||
assert bytesToLong.invoke(streamReceiver, sevenBtyeNumber).equals(36028797020288100L);
|
||||
byte[] eightByteNumber = {0b01100100, 0b00110100, 0b00010100, 0b00000000, 0b00000000, 0b00000000, (byte)0b10000000, 0b00100101};
|
||||
assert bytesToLong.invoke(streamReceiver, eightByteNumber).equals(-1L);
|
||||
byte[] emptyArray = {};
|
||||
assert bytesToLong.invoke(streamReceiver, emptyArray).equals(0L);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package seng302.server;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.server.messages.BoatLocationMessage;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
/**
|
||||
* Test conversions used by the boat location messages
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package seng302.server;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.server.messages.*;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.server.messages.Header;
|
||||
import seng302.server.messages.MessageType;
|
||||
|
||||
/**
|
||||
* Tests message header
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package seng302.server;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.server.messages.*;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.server.messages.Message;
|
||||
import seng302.server.messages.XMLMessage;
|
||||
import seng302.server.messages.XMLMessageSubType;
|
||||
|
||||
public class TestMessage {
|
||||
private static int XML_MESSAGE_LEN = 14;
|
||||
private static int CRC_LEN = 4;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package seng302.server.simulator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.utilities.GeoPoint;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* To test methods in GeoUtility.
|
||||
* Created by Haoming on 28/04/17.
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
package seng302.model.map;
|
||||
package seng302.visualiser.map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.utilities.GeoPoint;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit test for Mercator Project class.
|
||||
* Created by hyi25 on 15/05/17.
|
||||
@@ -1,13 +1,13 @@
|
||||
package seng302.visualizer.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.visualiser.controllers.annotations.Annotation;
|
||||
import seng302.visualiser.controllers.annotations.ImportantAnnotationsState;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestImportantAnnotationState {
|
||||
private ImportantAnnotationsState importantAnnotationsState;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user