### Question:
GenericConverter { public static byte[] convertStringToArray(int length, String value) { byte[] byteArray = String.format( "%-" + length + "s", value == null ? "" : value ).getBytes(charsetISO_8859); return byteArray.length != length ? Arrays.copyOf(byteArray, length) : byteArray; }  static byte[] convertStringToArray(int length, String value); static byte[] convertSignedNumericToArray(int length, T value ); static byte[] convertSignedNumericToArray(int length, T value, int precision ); static byte[] convertUnsignedNumericToArray(int length, T value ); static byte[] convertUnsignedNumericToArray(int length, T value, int precision ); static String convertByteArrayToString( int length, byte[] byteArray ); static Integer convertByteArrayToAnyInteger( int length, byte[] byteArray ); static Long convertByteArrayToAnyLong( int length, byte[] byteArray ); static Double convertByteArrayToAnyDouble( int length, byte[] byteArray, int precision ); static BigDecimal convertByteArrayToAnyDecimal( int length, byte[] byteArray, int precision );  }### Answer:
@Test public void testConvertStringToArray() throws Exception { int length = 150; String testString = "This is a String to test FromStringToArray() method of GenericConverter class"; logger.info("Test of GenericConverter.FromStringToArray() - with string [{}] for length [{}].", testString, length); try { byte[] encoded = GenericConverter.convertStringToArray(length, testString); DumpAsString(encoded); String model = String.format( "%-" + length + "s", testString ); ByteBuffer byteBuffer = charsetEncoder.encode( CharBuffer.wrap(model.toCharArray()) ) ; Assert.assertTrue( encoded.length == length ); for(int i = 0 ; i < length; i++ ) { String msg = String.format( "Character at index [%d]. ", i ); Assert.assertTrue(msg, byteBuffer.array()[i] == encoded[i]); } logger.info("Test of GenericConverter.FromStringToArray(): PASSED."); } catch(AssertionFailedError aseEx) { logger.error("Test of GenericConverter.FromStringToArray(): FAILED."); logger.error(aseEx.getMessage(), aseEx); throw aseEx; } catch ( Exception ex ) { logger.error(ex.getMessage(), ex); ex.printStackTrace(); throw ex; } }