### Question:
EncodingUtils { public static String encodeErrorMessage(AckValue ack, ErrorMessage errMsg) { StringBuilder sb = new StringBuilder(); sb.append("ack=").append(String.valueOf(ack)).append(";"); if (errMsg != null) { for (ErrorData errData : errMsg.getError()) { sb.append(';'); sb .append("severity:").append(errData.getSeverity()) .append(',') .append("errorId:").append(errData.getErrorId()) .append(',') .append("exceptionId:").append(errData.getExceptionId()) .append(',') .append("domain:").append(errData.getDomain()) .append(',') .append("subdomain:").append(errData.getSubdomain()) .append(',') .append("message:").append(errData.getMessage()); } } return sb.toString(); }  static String encodeErrorMessage(AckValue ack, ErrorMessage errMsg);  }### Answer:
@Test public void testEncodeErrorMessageContentNull() { String encodeErrorMessage = EncodingUtils.encodeErrorMessage(AckValue.SUCCESS, null); assertNotNull("encodeErrorMessage returns null", encodeErrorMessage); assertTrue("encodeErrorMessage should start with 'ack='", encodeErrorMessage.startsWith("ack=") ); assertFalse("encodeErrorMessage should contains Severity'", encodeErrorMessage.contains("severity") ); assertFalse("encodeErrorMessage should contains errorId'", encodeErrorMessage.contains("errorId") ); assertFalse("encodeErrorMessage should contains exceptionId'", encodeErrorMessage.contains("exceptionId") ); assertFalse("encodeErrorMessage should contains domain'", encodeErrorMessage.contains("domain") ); assertFalse("encodeErrorMessage should contains subdomain'", encodeErrorMessage.contains("subdomain") ); assertFalse("encodeErrorMessage should contains message'", encodeErrorMessage.contains("message") ); }
@Test public void testEncodeErrorMessageContent() { ErrorMessage em = new ErrorMessage(); CommonErrorData error = new CommonErrorData(); error.setErrorId(500); error.setSeverity(ErrorSeverity.ERROR); error.setExceptionId("exception_id"); error.setDomain("turmeric"); error.setSubdomain("rl"); error.setMessage("testError"); em.getError().add(error); String encodeErrorMessage = EncodingUtils.encodeErrorMessage(AckValue.SUCCESS, em); assertNotNull("encodeErrorMessage returns null", encodeErrorMessage); assertTrue("encodeErrorMessage should start with 'ack='", encodeErrorMessage.startsWith("ack=") ); assertTrue("encodeErrorMessage should contains Severity'", encodeErrorMessage.contains("severity") ); assertTrue("encodeErrorMessage should contains errorId'", encodeErrorMessage.contains("errorId") ); assertTrue("encodeErrorMessage should contains exceptionId'", encodeErrorMessage.contains("exceptionId") ); assertTrue("encodeErrorMessage should contains domain'", encodeErrorMessage.contains("domain") ); assertTrue("encodeErrorMessage should contains subdomain'", encodeErrorMessage.contains("subdomain") ); assertTrue("encodeErrorMessage should contains message'", encodeErrorMessage.contains("message") ); assertTrue("severity value does not match", encodeErrorMessage.contains(ErrorSeverity.ERROR.value())); assertTrue("errorId value does not match", encodeErrorMessage.contains("500")); assertTrue("exceptionId value does not match", encodeErrorMessage.contains("exception_id")); assertTrue("domain value does not match", encodeErrorMessage.contains("turmeric")); assertTrue("subdomain value does not match", encodeErrorMessage.contains("rl")); assertTrue("message value does not match", encodeErrorMessage.contains("testError")); }