### Question:
DataUtil { public static void setValue(DataType d, byte[] inValue) throws DataException { byte[] value = inValue; d.setDataBytesStore(new byte[0]); d.setReadDataBytes(false); d.setShortData(null); if(d.getVaulted() == false){ d.setDataHash(SecurityUtil.getDigestAsString(value, new byte[0])); d.setCompressed(false); } d.setCompressionType(CompressionEnumType.NONE); d.setBlob(true); if (d.getVaulted() == false && value.length > 512 && tryCompress(d)) { value = ZipUtil.gzipBytes(value); d.setCompressed(true); d.setCompressionType(CompressionEnumType.GZIP); } if (d.getPasswordProtect()) { if (d.getPassKey() == null || d.getPassKey().length == 0) { throw new DataException("Pass key not specified for password protected data."); } else { SecurityBean bean = SecurityFactory.getSecurityFactory().createSecurityBean(d.getPassKey(), false); value = SecurityUtil.encipher(bean, value); d.setPasswordProtected(true); d.setPassKey(null); } } if (d.getEncipher()) { if(d.getCipherKey() == null || d.getCipherKey().length == 0){ throw new DataException("Cipher key not specified for enciphered data"); } else{ SecurityBean bean = SecurityFactory.getSecurityFactory().createSecurityBean(d.getCipherKey(), false); value = SecurityUtil.encipher(bean, value); d.setEnciphered(true); d.setCipherKey(null); } } d.setSize(value.length); d.setDataBytesStore(value); d.setBlob(true); } private  DataUtil(); static void clearCipher(DataType data); static void setCipher(DataType data); static void setCipher(DataType data, SecurityBean bean); static void clearPassword(DataType data); static void setPassword(DataType data, String password); static void setValueString(DataType d, String value); static String getValueString(DataType d); static void setValue(DataType d, byte[] inValue); static byte[] getValue(DataType d); static boolean tryCompress(DataType d); static final Logger logger; }### Answer:
@Test public void testSetData(){ logger.info("Setting data"); DataType data = new DataType(); boolean error = false; String value = "Example text"; try{ DataUtil.setValue(data, value.getBytes()); } catch(DataException de){ error = true; } }
@Test public void testSetProtectedData(){ logger.info("Setting protected data"); SecurityFactory sf = SecurityFactory.getSecurityFactory(); SecurityBean ciphBean = new SecurityBean(); sf.generateSecretKey(ciphBean); DataType data = new DataType(); data.setPassKey(SecurityUtil.serializeToXml(ciphBean, false, false, true).getBytes()); data.setPasswordProtect(true); boolean error = false; String value = "Example text"; try{ DataUtil.setValue(data, value.getBytes()); } catch(DataException de){ error = true; } assertTrue("Data was not protected",data.getPasswordProtected()); }