assertEquals(1.23,msg.readDouble(),0);
}
public void testStringConversion() throws Exception
{
StreamMessageImpl msg;
// Boolean
msg = new StreamMessageImpl();
msg.writeString("foobar");
msg.markAsReadOnly();
assertFalse(msg.readBoolean());
// Byte
msg = new StreamMessageImpl();
msg.writeString("foobar");
msg.markAsReadOnly();
try { msg.readByte(); fail("Should have failed"); } catch (NumberFormatException e) { /* OK */ }
assertEquals("foobar",msg.readString());
// Short
msg = new StreamMessageImpl();
msg.writeString("foobar");
msg.markAsReadOnly();
try { msg.readShort(); fail("Should have failed"); } catch (NumberFormatException e) { /* OK */ }
assertEquals("foobar",msg.readString());
// Char
msg = new StreamMessageImpl();
msg.writeString("foobar");
msg.markAsReadOnly();
try { msg.readChar(); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals("foobar",msg.readString());
// Int
msg = new StreamMessageImpl();
msg.writeString("foobar");
msg.markAsReadOnly();
try { msg.readInt(); fail("Should have failed"); } catch (NumberFormatException e) { /* OK */ }
assertEquals("foobar",msg.readString());
// Long
msg = new StreamMessageImpl();
msg.writeString("foobar");
msg.markAsReadOnly();
try { msg.readLong(); fail("Should have failed"); } catch (NumberFormatException e) { /* OK */ }
assertEquals("foobar",msg.readString());
// Float
msg = new StreamMessageImpl();
msg.writeString("foobar");
msg.markAsReadOnly();
try { msg.readFloat(); fail("Should have failed"); } catch (NumberFormatException e) { /* OK */ }
assertEquals("foobar",msg.readString());
// Double
msg = new StreamMessageImpl();
msg.writeString("foobar");
msg.markAsReadOnly();
try { msg.readDouble(); fail("Should have failed"); } catch (NumberFormatException e) { /* OK */ }
assertEquals("foobar",msg.readString());
// String
msg = new StreamMessageImpl();
msg.writeString("foobar");
msg.markAsReadOnly();
assertEquals("foobar",msg.readString());
// Bytes
msg = new StreamMessageImpl();
msg.writeString("foobar");
msg.markAsReadOnly();
try { msg.readBytes(new byte[1]); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals("foobar",msg.readString());
}