/* * Short Tests */ @Test public void testGetAndSetShort() throws Exception { WrappedByteBuffer buf = new WrappedByteBuffer(); buf.putShort((short) 0); buf.putShort((short) 1); buf.putShort((short) 32767); buf.putShort((short) -32768); buf.flip(); assertEquals(buf.position(), 0); assertEquals(buf.limit(), 8); assertEquals((short) 0, buf.getShort()); assertEquals((short) 1, buf.getShort()); assertEquals((short) 32767, buf.getShort()); assertEquals((short) -32768, buf.getShort()); assertEquals(buf.position(), 8); buf.putShortAt(0, (short) 121); buf.putShortAt(2, (short) 1000); assertEquals((short) 121, buf.getShortAt(0)); assertEquals((short) 1000, buf.getShortAt(2)); assertEquals((int) buf.position(), 8); }
@Test public void testGetAndSetShorts() throws Exception { // tests reallocation of buffer automatically. WrappedByteBuffer buf = WrappedByteBuffer.allocate(2); buf.putShort((short) 1); buf.putShort((short) 2); buf.putShort((short) 3); buf.putShort((short) 4); buf.putShort((short) 5); buf.flip(); assertEquals((short) 1, buf.getShort()); assertEquals((short) 1, buf.getShortAt(0)); assertEquals((short) 2, buf.getShortAt(2)); assertEquals((short) 3, buf.getShortAt(4)); assertEquals((short) 2, buf.getShort()); assertEquals((short) 3, buf.getShort()); assertEquals((short) 4, buf.getShort()); assertEquals((short) 5, buf.getShort()); }
@Test(expected = IndexOutOfBoundsException.class) public void testGetAndSetGetShortAtException4() { WrappedByteBuffer buf = new WrappedByteBuffer(); buf.getShortAt(128); }