### Question:
JmsStreamMessage extends JmsMessage implements StreamMessage { @Override public String readString() throws JMSException { initializeReading(); try { checkEndOfStream(); Object value = stream.get(index++); if (value == null) { return null; } if (value instanceof String) { return (String) value; } if (value instanceof Double) { return ((Double) value).toString(); } if (value instanceof Float) { return ((Float) value).toString(); } if (value instanceof Long) { return ((Long) value).toString(); } if (value instanceof Integer) { return ((Integer) value).toString(); } if (value instanceof Short) { return ((Short) value).toString(); } if (value instanceof Byte) { return ((Byte) value).toString(); } if (value instanceof Character) { return ((Character) value).toString(); } if (value instanceof Boolean) { return ((Boolean) value).toString(); } index--; throw new MessageFormatException("Cannot convert byte array to String."); } catch (NumberFormatException nfe) { index--; throw nfe; } } 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 testReadString() { JmsStreamMessage msg = factory.createStreamMessage(); try { byte testByte = (byte) 2; msg.writeString(new Byte(testByte).toString()); msg.reset(); assertTrue(msg.readByte() == testByte); msg.clearBody(); short testShort = 3; msg.writeString(new Short(testShort).toString()); msg.reset(); assertTrue(msg.readShort() == testShort); msg.clearBody(); int testInt = 4; msg.writeString(new Integer(testInt).toString()); msg.reset(); assertTrue(msg.readInt() == testInt); msg.clearBody(); long testLong = 6L; msg.writeString(new Long(testLong).toString()); msg.reset(); assertTrue(msg.readLong() == testLong); msg.clearBody(); float testFloat = 6.6f; msg.writeString(new Float(testFloat).toString()); msg.reset(); assertTrue(msg.readFloat() == testFloat); msg.clearBody(); double testDouble = 7.7d; msg.writeString(new Double(testDouble).toString()); msg.reset(); assertTrue(msg.readDouble() == testDouble); msg.clearBody(); msg.writeString("true"); msg.reset(); assertTrue(msg.readBoolean()); msg.clearBody(); msg.writeString("a"); msg.reset(); try { msg.readChar(); fail("Should have thrown exception"); } catch (MessageFormatException e) { } msg.clearBody(); msg.writeString("777"); msg.reset(); try { msg.readBytes(new byte[3]); fail("Should have thrown exception"); } catch (MessageFormatException e) { } } catch (JMSException jmsEx) { jmsEx.printStackTrace(); assertTrue(false); } }