EepData { public String dataAsString() { StringBuilder builder = new StringBuilder(256); try { byte[] eepData = asByteArray(); for (byte b : eepData) { builder.append(Strings.byteToUnsignedHexString(b)); builder.append(" "); } } catch (EepOutOfRangeException e) { for(int i = 0; i < length(); i++) { builder.append("-- "); } } return builder.toString().trim(); } EepData(EepType type, int length, Set<EepDataListener> dataListeners);  EepData(EepType type, int length, EepDataListener...dataListeners); @Override String toString(); int length(); void setValue(int index, int value); int getValue(int index); byte[] asByteArray(); String dataAsString(); void update(byte[] eepData);  }
@Test public void testDataAsString() throws Exception { EepData data = new EepData(EepType.EEP_TYPE_A50205, 4, dataListeners); dataListener1.index = 0; dataListener1.value = 0x01; dataListener2.index = 3; dataListener2.value = 0x04; Assert.assertEquals("0x01 0x00 0x00 0x04", data.dataAsString()); dataListener1.throwException = true; Assert.assertEquals("-- -- -- --", data.dataAsString()); }