### Question:
IOSample { @Override public String toString() { StringBuilder sb = new StringBuilder("{"); if (hasDigitalValues()) { for (IOLine line : digitalValuesMap.keySet()) { sb.append("[").append(line).append(": ").append(digitalValuesMap.get(line)).append("], "); } } if (hasAnalogValues()) { for (IOLine line : analogValuesMap.keySet()) { sb.append("[").append(line).append(": ").append(analogValuesMap.get(line)).append("], "); } } if (hasPowerSupplyValue()) { try { sb.append("[").append("Power supply voltage: ").append(getPowerSupplyValue()).append("], "); } catch (OperationNotSupportedException e) {} } String s = sb.toString(); if (s.endsWith(", ")) s = s.substring(0, s.length() - 2); return s + "}"; } IOSample(byte[] ioSamplePayload); int getDigitalHSBMask(); int getDigitalLSBMask(); int getDigitalMask(); boolean hasDigitalValues(); boolean hasDigitalValue(IOLine ioLine); HashMap<IOLine, IOValue> getDigitalValues(); IOValue getDigitalValue(IOLine ioLine); int getAnalogMask(); boolean hasAnalogValues(); boolean hasAnalogValue(IOLine ioLine); HashMap<IOLine, Integer> getAnalogValues(); Integer getAnalogValue(IOLine ioLine); boolean hasPowerSupplyValue(); int getPowerSupplyValue(); static ArrayList<IOSample> parseIOSamples(byte[] samplePayload); @Override String toString(); @Override boolean equals(Object obj);  }### Answer:
@Test public void testToString() throws OperationNotSupportedException { IOSample[] samples = new IOSample[] {new IOSample(IO_DATA_ONLY_DIGITAL), new IOSample(IO_DATA_ONLY_ANALOG), new IOSample(IO_DATA_MIXED)}; for (IOSample s:samples) { String result = s.toString(); if(s.hasDigitalValues()) { HashMap<IOLine, IOValue> map = s.getDigitalValues(); for (IOLine l: map.keySet()) { String entry = "[" + l + ": " + map.get(l) + "]"; assertEquals("toString() method does not produce the expected output", true, result.contains(entry)); } } if(s.hasAnalogValues()) { HashMap<IOLine, Integer> map = s.getAnalogValues(); for (IOLine l: map.keySet()) { String entry = "[" + l + ": " + map.get(l) + "]"; assertEquals("toString() method does not produce the expected output", true, result.contains(entry)); } } if(s.hasPowerSupplyValue()) { String entry = "[Power supply voltage: " + s.getPowerSupplyValue() + "]"; assertEquals("toString() method does not produce the expected output", true, result.contains(entry)); } assertEquals("toString() method does not produce the expected output", true, result.startsWith("{") & result.endsWith("}")); } }