### Question:
CommonUtil { public static boolean updateHandler(Registry configSystemRegistry, String oldName, String payload) throws RegistryException, XMLStreamException { if (isHandlerNameInUse(oldName)) throw new RegistryException("Could not update handler since it is already in use!"); String newName = null; OMElement element = AXIOMUtil.stringToOM(payload); if (element != null) { newName = element.getAttributeValue(new QName("class")); } if (newName == null || newName.equals("")) return false; if (oldName == null || oldName.equals("")) { String path = getContextRoot() + newName; Resource resource; if (handlerExists(configSystemRegistry, newName)) { return false; } else { resource = new ResourceImpl(); } resource.setContent(payload); try { configSystemRegistry.beginTransaction(); configSystemRegistry.put(path, resource); generateHandler(configSystemRegistry, path); configSystemRegistry.commitTransaction(); } catch (Exception e) { configSystemRegistry.rollbackTransaction(); throw new RegistryException("Unable to generate handler", e); } return true; } if (newName.equals(oldName)) { String oldPath = getContextRoot() + oldName; Resource resource; if (handlerExists(configSystemRegistry, oldName)) { resource = configSystemRegistry.get(oldPath); } else { resource = new ResourceImpl(); } resource.setContent(payload); try { configSystemRegistry.beginTransaction(); removeHandler(configSystemRegistry, oldName); configSystemRegistry.put(oldPath, resource); generateHandler(configSystemRegistry, oldPath); configSystemRegistry.commitTransaction(); } catch (Exception e) { configSystemRegistry.rollbackTransaction(); throw new RegistryException("Unable to generate handler", e); } return true; } else { String oldPath = getContextRoot() + oldName; String newPath = getContextRoot() + newName; if (handlerExists(configSystemRegistry, newName)) { return false; } Resource resource; if (handlerExists(configSystemRegistry, oldName)) { resource = configSystemRegistry.get(oldPath); } else { resource = new ResourceImpl(); } resource.setContent(payload); try { configSystemRegistry.beginTransaction(); configSystemRegistry.put(newPath, resource); generateHandler(configSystemRegistry, newPath); removeHandler(configSystemRegistry, oldName); configSystemRegistry.delete(oldPath); configSystemRegistry.commitTransaction(); } catch (Exception e) { configSystemRegistry.rollbackTransaction(); throw new RegistryException("Unable to renew handler", e); } return true; } }  static synchronized void setRegistryService(RegistryService service); static RegistryService getRegistryService(); static void simulateRegistryOperation(Registry rootRegistry, SimulationRequest simulationRequest); static SimulationResponse getSimulationResponse(); static boolean updateHandler(Registry configSystemRegistry, String oldName, String payload); static boolean addHandler(Registry configSystemRegistry, String payload); static boolean handlerExists(Registry configSystemRegistry, String name); static boolean deleteHandler(Registry configSystemRegistry, String name); static String getHandlerConfiguration(Registry configSystemRegistry, String name); static String[] getHandlerList(Registry configSystemRegistry); static String getContextRoot(); static void setContextRoot(String contextRoot); static boolean generateHandler(Registry configSystemRegistry, String resourceFullPath); static boolean removeHandler(Registry configSystemRegistry, String handlerName); static boolean isHandlerNameInUse(String name); static boolean addDefaultHandlersIfNotAvailable(Registry configSystemRegistry); static SimulationService getSimulationService(); static void setSimulationService(SimulationService simulationService); static HandlerConfigurationBean deserializeHandlerConfiguration(OMElement configurationElement); static OMElement serializeHandlerConfiguration(HandlerConfigurationBean bean);  }### Answer:
@Test public void testUpdateHandler() throws Exception { String handlerName = "org.wso2.carbon.registry.extensions.handlers.ServiceMediaTypeHandler"; assertTrue(CommonUtil.updateHandler(registry, null, handlerConfiguration)); String[] handlerList = CommonUtil.getHandlerList(registry); assertArrayEquals(new String[]{handlerName}, handlerList); String handlerConfig = CommonUtil.getHandlerConfiguration(registry, handlerName); assertEquals(handlerConfiguration, handlerConfig); assertTrue(CommonUtil.deleteHandler(registry, handlerName)); handlerList = CommonUtil.getHandlerList(registry); assertArrayEquals(null, handlerList); }