RequestToJoinEnum contains an int instead of a byte.
Added requestToJoin and joinAcceptance encoding functions to RaceVisionByteEncoder. Implemented JoinAcceptanceDecoder. Implemented RequestToJoinDecoder. Added tests for encoding/decoding RequestToJoin and JoinAcceptance messages. issue #35 #story[1095]
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package network.MessageDecoders;
|
||||
|
||||
import network.MessageEncoders.RaceVisionByteEncoder;
|
||||
import network.Messages.Enums.RequestToJoinEnum;
|
||||
import network.Messages.RequestToJoin;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
/**
|
||||
* Test for the RequestToJoin encoder and decoder
|
||||
*/
|
||||
public class RequestToJoinDecoderTest {
|
||||
|
||||
|
||||
/**
|
||||
* Encodes and decodes a given message.
|
||||
* @param message Message to encode/decode.
|
||||
* @return The decoded message.
|
||||
*/
|
||||
private RequestToJoin encodeDecodeMessage(RequestToJoin message) {
|
||||
|
||||
//Encode.
|
||||
byte [] testEncodedMessage = RaceVisionByteEncoder.requestToJoin(message);
|
||||
|
||||
//Decode.
|
||||
RequestToJoinDecoder testDecoder = new RequestToJoinDecoder(testEncodedMessage);
|
||||
RequestToJoin decodedMessage = testDecoder.getMessage();
|
||||
|
||||
return decodedMessage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if a specific request type message can be encoded and decoded correctly.
|
||||
* @param type The type of join request.
|
||||
*/
|
||||
private void requestTypeTest(RequestToJoinEnum type) throws Exception {
|
||||
|
||||
//Prepare message.
|
||||
RequestToJoin beforeMessage = new RequestToJoin(type);
|
||||
|
||||
|
||||
//Encode/decode it.
|
||||
RequestToJoin afterMessage = encodeDecodeMessage(beforeMessage);
|
||||
|
||||
|
||||
//Compare.
|
||||
assertEquals(beforeMessage.getRequestType().getValue(), afterMessage.getRequestType().getValue());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if a spectator request message can be encoded and decoded correctly.
|
||||
*/
|
||||
@Test
|
||||
public void spectatorTest() throws Exception {
|
||||
requestTypeTest(RequestToJoinEnum.SPECTATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a participant request message can be encoded and decoded correctly.
|
||||
*/
|
||||
@Test
|
||||
public void participantTest() throws Exception {
|
||||
requestTypeTest(RequestToJoinEnum.PARTICIPANT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a ghost request message can be encoded and decoded correctly.
|
||||
*/
|
||||
@Test
|
||||
public void ghostTest() throws Exception {
|
||||
requestTypeTest(RequestToJoinEnum.GHOST);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user