Added RaceStartStatusEncoder.
Added RaceStartTypeEnum. Refactored RaceStartStatusDecoder to implement the MessageDecoder interface. Documented RaceStartStatus, and it actually exposes its properties now. Updated RaceStartStatusDecoderTest. issue #35 #36 #story[1095]
This commit is contained in:
+46
-13
@@ -1,29 +1,62 @@
|
||||
package network.MessageDecoders;
|
||||
|
||||
import network.MessageEncoders.RaceVisionByteEncoder;
|
||||
import network.Messages.Enums.RaceStartTypeEnum;
|
||||
import network.Messages.RaceStartStatus;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by hba56 on 23/04/17.
|
||||
* Tests for the RaceStartStatus encoder and decoder.
|
||||
*/
|
||||
public class RaceStartStatusDecoderTest {
|
||||
|
||||
|
||||
/**
|
||||
* Tests if a RaceStartStatus message can be encoded and decoded correctly.
|
||||
* @throws Exception Thrown when an error occurs.
|
||||
*/
|
||||
@Test
|
||||
public void getByteArrayTest(){
|
||||
long time = System.currentTimeMillis();
|
||||
public void raceStartStatusEncodeDecodeTest() throws Exception {
|
||||
|
||||
long time2 = System.currentTimeMillis();
|
||||
byte[] encodedRaceStartStatus = RaceVisionByteEncoder.raceStartStatus(time, (short)1,
|
||||
time2, 2, (char)3);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
RaceStartStatusDecoder testDecoder = new RaceStartStatusDecoder(encodedRaceStartStatus);
|
||||
long startTime = System.currentTimeMillis() + 10 * 1000;
|
||||
|
||||
Assert.assertEquals(0b1, testDecoder.getMessageVersion());
|
||||
Assert.assertEquals(time, testDecoder.getTime());
|
||||
Assert.assertEquals(1, testDecoder.getAck());
|
||||
Assert.assertEquals(time2, testDecoder.getStartTime());
|
||||
Assert.assertEquals(2, testDecoder.getRaceID());
|
||||
Assert.assertEquals((char)3, testDecoder.getNotification());
|
||||
RaceStartStatus raceStartStatus = new RaceStartStatus(
|
||||
RaceStartStatus.currentMessageVersionNumber,
|
||||
timestamp,
|
||||
55,
|
||||
startTime,
|
||||
35,
|
||||
RaceStartTypeEnum.SET_RACE_START
|
||||
);
|
||||
|
||||
byte[] encodedRaceStartStatus = RaceVisionByteEncoder.encode(raceStartStatus);
|
||||
|
||||
RaceStartStatusDecoder testDecoder = new RaceStartStatusDecoder();
|
||||
testDecoder.decode(encodedRaceStartStatus);
|
||||
RaceStartStatus raceStartStatusDecoded = testDecoder.getMessage();
|
||||
|
||||
compareRaceStartStatusMessages(raceStartStatus, raceStartStatusDecoded);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two RaceStartStatus messages to check that they are the same.
|
||||
* @param original The original message.
|
||||
* @param decoded The decoded message.
|
||||
*/
|
||||
public static void compareRaceStartStatusMessages(RaceStartStatus original, RaceStartStatus decoded) {
|
||||
|
||||
Assert.assertEquals(original.getMessageVersionNumber(), decoded.getMessageVersionNumber());
|
||||
Assert.assertEquals(original.getTimestamp(), decoded.getTimestamp());
|
||||
Assert.assertEquals(original.getAckNum(), decoded.getAckNum());
|
||||
Assert.assertEquals(original.getRaceStartTime(), decoded.getRaceStartTime());
|
||||
Assert.assertEquals(original.getRaceID(), decoded.getRaceID());
|
||||
Assert.assertEquals(original.getNotificationType(), decoded.getNotificationType());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user