Field implements Comparable<Field> { public void write(ByteBuffer buffer) { write(null, buffer); } Field(String id, Integer start, Integer length);  Field(String id, Integer start, Integer length, boolean composite);  Field(String id, Integer start, Integer length, boolean composite, boolean input, String alias);  Field(String id, Integer start, Integer length, boolean composite, boolean input, String alias,
            boolean whitespace); void write(ByteBuffer buffer); void write(Object value, ByteBuffer buffer); String read(ByteBuffer buffer); boolean isComposite(); String getAlias(); boolean isAliased(); boolean isInput(); boolean isWhitespaceSignificant(); @Override int compareTo(Field o); @Override int hashCode(); @Override boolean equals(Object obj); Integer getLength(); String getId(); Integer getStart(); @Override String toString(); final static Comparator<Field> DEFAULT_SORT; final static Comparator<Field> NAME_SORT; }
@Test public void testWrite_withParams() throws Exception { field.write("abc", buffer); byte[] expectedBytes = new byte[8]; expectedBytes[0] = (byte) '\u0000'; expectedBytes[1] = (byte) '\u0000'; expectedBytes[2] = (byte) 'a'; expectedBytes[3] = (byte) 'b'; expectedBytes[4] = (byte) 'c'; expectedBytes[5] = (byte) ' '; expectedBytes[6] = (byte) '\u0000'; expectedBytes[7] = (byte) '\u0000'; byte[] actualBytes = new byte[8]; buffer.position(0); buffer.get(actualBytes); assertEquals(new String(expectedBytes), new String(actualBytes)); }
@Test public void testWrite_withoutParams() { field.write(buffer); byte[] expectedBytes = new byte[8]; expectedBytes[0] = (byte) '\u0000'; expectedBytes[1] = (byte) '\u0000'; expectedBytes[2] = (byte) ' '; expectedBytes[3] = (byte) ' '; expectedBytes[4] = (byte) ' '; expectedBytes[5] = (byte) ' '; expectedBytes[6] = (byte) '\u0000'; expectedBytes[7] = (byte) '\u0000'; byte[] actualBytes = new byte[8]; buffer.position(0); buffer.get(actualBytes); assertEquals(new String(expectedBytes), new String(actualBytes)); }