Added tests for reading and writing
This commit is contained in:
parent
243f44ef23
commit
2e4bd8289e
@ -1,6 +1,9 @@
|
||||
package Main;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ProtocolMessageTest {
|
||||
@ -33,4 +36,20 @@ public class ProtocolMessageTest {
|
||||
int result = ProtocolMessage.charArrayToInt(out);
|
||||
assertEquals(testedInt, result, "Integers not equal!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputReadingOutputWritingTest() throws IOException {
|
||||
ProtocolMessage message = new ProtocolMessage("This is a text");
|
||||
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
Writer writer = new PrintWriter(stream);
|
||||
message.sendToStream(writer);
|
||||
byte[] buffer = stream.toByteArray();
|
||||
|
||||
ByteArrayInputStream istream = new ByteArrayInputStream(buffer);
|
||||
ProtocolMessage newMessage = new ProtocolMessage();
|
||||
Reader reader = new BufferedReader(new InputStreamReader(istream));
|
||||
newMessage.readFromStream(reader);
|
||||
assertArrayEquals(message.getRaw(), newMessage.getRaw());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user