### Question:
JmsStreamMessage extends JmsMessage implements StreamMessage { @Override public int readBytes(byte[] value) throws JMSException { initializeReading(); try { if (value == null) { throw new NullPointerException(); } checkEndOfStream(); if (remainingBytes == -1) { Object data = stream.get(index++); if (!(data instanceof Buffer)) { throw new MessageFormatException("Not a byte array"); } bytes = (Buffer) data; remainingBytes = bytes.length(); } else if (remainingBytes == 0) { remainingBytes = -1; bytes = null; return -1; } if (value.length <= remainingBytes) { remainingBytes -= value.length; System.arraycopy(bytes.data, bytes.offset, value, 0, value.length); bytes.offset += value.length; return value.length; } else { System.arraycopy(bytes.data, bytes.offset, value, 0, remainingBytes); remainingBytes = 0; return bytes.length(); } } catch (Throwable e) { throw JmsExceptionSupport.createMessageFormatException(e); } } JmsStreamMessage(JmsMessageFacade facade); @Override JmsMessage copy(); @Override void onSend(); @Override void clearBody(); @Override boolean readBoolean(); @Override byte readByte(); @Override short readShort(); @Override char readChar(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override String readString(); @Override int readBytes(byte[] value); @Override Object readObject(); @Override void writeBoolean(boolean value); @Override void writeByte(byte value); @Override void writeShort(short value); @Override void writeChar(char value); @Override void writeInt(int value); @Override void writeLong(long value); @Override void writeFloat(float value); @Override void writeDouble(double value); @Override void writeString(String value); @Override void writeBytes(byte[] value); @Override void writeBytes(byte[] value, int offset, int length); @Override void writeObject(Object value); @Override void reset(); @Override String toString();  }### Answer:
@Test public void testReadBytes() { JmsStreamMessage msg = factory.createStreamMessage(); try { byte[] test = new byte[50]; for (int i = 0; i < test.length; i++) { test[i] = (byte) i; } msg.writeBytes(test); msg.reset(); byte[] valid = new byte[test.length]; msg.readBytes(valid); for (int i = 0; i < valid.length; i++) { assertTrue(valid[i] == test[i]); } msg.reset(); try { msg.readByte(); fail("Should have thrown exception"); } catch (MessageFormatException mfe) { } msg.reset(); try { msg.readShort(); fail("Should have thrown exception"); } catch (MessageFormatException mfe) { } msg.reset(); try { msg.readInt(); fail("Should have thrown exception"); } catch (MessageFormatException mfe) { } msg.reset(); try { msg.readLong(); fail("Should have thrown exception"); } catch (MessageFormatException mfe) { } msg.reset(); try { msg.readFloat(); fail("Should have thrown exception"); } catch (MessageFormatException mfe) { } msg.reset(); try { msg.readChar(); fail("Should have thrown exception"); } catch (MessageFormatException mfe) { } msg.reset(); try { msg.readString(); fail("Should have thrown exception"); } catch (MessageFormatException mfe) { } } catch (JMSException jmsEx) { jmsEx.printStackTrace(); assertTrue(false); } }