EepDataField { public void write(int value, EepData data) throws EepOutOfRangeException { checkDataParameter(data); checkValueParameter(value); int curSize = this.size; int curDataByteIndex = getLSBIndex(); int curDataBitIndex = getLSBStartBitIndex(); int curDataBitLength = 0; int curValueBitIndex = 0; while(curSize > 0) { if(curSize >= (Byte.SIZE - curDataBitIndex)) { curDataBitLength = Byte.SIZE - curDataBitIndex; } else { curDataBitLength = curSize; } int mask = 0xFFFFFFFF >>> (Integer.SIZE - curDataBitLength); int subValue = (value >> curValueBitIndex) & mask; writeSubValue(subValue, data, curDataByteIndex, curDataBitIndex); curDataByteIndex--; curDataBitIndex = 0; curValueBitIndex += curDataBitLength; curSize -= curDataBitLength; } } EepDataField(String name, int offset, int size); @Override String toString(); int read(EepData data); void write(int value, EepData data); boolean isValid(int value);  }
@Test public void testWriteOutOfRangeValue() throws Exception { int offset = 0; int size = 4; EepDataField df = new EepDataField("EDF1", offset, size); EepData data = new EepData(EepType.EEP_TYPE_F60201, 1, (EepDataListener)null); df.write(0x0F, data); try { df.write(0x1F, data); Assert.fail(); } catch (EepOutOfRangeException e) { } }