@Test public void testSetChars() { final char[] testData = {'A', 'B', '\0', 'C', 'D'}; final MessageData hd = new HeaderData("test_data", new MemoryResource(new byte[5], 0, 5)); final StringElement sut = new StringElement(null, "test string element", hd, 0, 0, 8 * 5 - 1); assertEquals("Empty string to start", "", sut.getValue()); sut.setChars(testData); assertEquals("New value is cut off by the null", "AB", sut.getValue()); char[] result = new char[5]; assertEquals("Five bytes in, five bytes back", 5, sut.getChars(result)); assertEquals( "Exact same array comes back with getChars()", Arrays.toString(testData), Arrays.toString(result)); }