### Question:
CommonUtil { public static UserRegistry getRegistry(HttpSession session) throws RegistryException { if (session == null) { return org.wso2.carbon.registry.common.utils.CommonUtil.getUserRegistry(registryService); } return org.wso2.carbon.registry.common.utils.CommonUtil.getUserRegistry( registryService, session); }  static synchronized void setRegistryService(RegistryService service); static RegistryService getRegistryService(); static UserRegistry getRegistry(HttpSession session);  }### Answer:
@Test public void getRegistry() throws Exception { UserRegistry userRegistry = mock(UserRegistry.class); HttpSession session = mock(HttpSession.class); when(session.getAttribute(RegistryConstants.USER_REGISTRY)).thenReturn(userRegistry); Assert.assertEquals(userRegistry, CommonUtil.getRegistry(session)); }
@Test public void getRegistryWithoutSession() throws Exception { UserRegistry userRegistry = mock(UserRegistry.class); MessageContext messageContext = new MessageContext(); HttpServletRequest servletRequest = mock(HttpServletRequest.class); HttpSession session = mock(HttpSession.class); when(session.getAttribute(RegistryConstants.USER_REGISTRY)).thenReturn(userRegistry); when(servletRequest.getSession()).thenReturn(session); messageContext.setProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST, servletRequest); MessageContext.setCurrentMessageContext(messageContext); assertEquals(userRegistry, CommonUtil.getRegistry(null)); }