### Question:
ViewInstanceOperationHandler { public void uninstallViewInstance(ViewInstanceEntity instanceEntity) { LOG.info("uninstalling ViewInstance : {} ", instanceEntity); ViewEntity viewEntity = viewDAO.findByName(instanceEntity.getViewName()); LOG.info("viewEntity received corresponding to the view entity : {} ", viewEntity); if (viewEntity != null) { String instanceName = instanceEntity.getName(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); ViewInstanceEntity instanceDefinition = instanceDAO.findByName(instanceEntity.getViewName(), instanceEntity.getName()); LOG.debug("view instance entity received from database : {}", instanceDefinition); if (instanceDefinition != null) { if (instanceDefinition.isXmlDriven()) { throw new IllegalStateException("View instances defined via xml can't be deleted through api requests"); } List<PrivilegeEntity> instancePrivileges = privilegeDAO.findByResourceId(instanceEntity.getResource().getId()); LOG.info("Removing privilege entities : {}", instancePrivileges); for (PrivilegeEntity privilegeEntity : instancePrivileges) { removePrivilegeEntity(privilegeEntity); } LOG.info("Deleting view instance : view name : {}, version : {}, instanceName : {}", viewName, version, instanceName); instanceDAO.remove(instanceDefinition); }else{ throw new IllegalStateException("View instance '" + instanceEntity.getName() + "' not found."); } }else{ throw new IllegalStateException("View '" + instanceEntity.getViewName() + "' not found corresponding to view instance '" + instanceEntity.getName() + "'"); } }  void uninstallViewInstance(ViewInstanceEntity instanceEntity);  }### Answer:
@Test public void uninstallViewInstance() throws Exception { ViewInstanceOperationHandler viewInstanceOperationHandler = getViewInstanceOperationHandler(); ResourceEntity resourceEntity = new ResourceEntity(); resourceEntity.setId(3L); ViewInstanceEntity instanceEntity = new ViewInstanceEntity(); instanceEntity.setName("VIEW_INSTANCE_NAME"); instanceEntity.setViewName("VIEW_NAME"); instanceEntity.setResource(resourceEntity); ViewDAO viewDAO = viewInstanceOperationHandler.viewDAO; ViewEntity viewEntity = EasyMock.createNiceMock(ViewEntity.class); expect(viewDAO.findByName(instanceEntity.getViewName())).andReturn(viewEntity); expect(viewEntity.getCommonName()).andReturn("view-common-name"); expect(viewEntity.getVersion()).andReturn("0.0.1"); ViewInstanceDAO viewInstanceDAO = viewInstanceOperationHandler.instanceDAO; ViewInstanceEntity viewInstanceEntity = createNiceMock(ViewInstanceEntity.class); expect(viewInstanceDAO.findByName(instanceEntity.getViewName(), instanceEntity.getName())).andReturn(viewInstanceEntity); expect(viewInstanceEntity.isXmlDriven()).andReturn(false); expect(viewInstanceEntity.isXmlDriven()).andReturn(false); PrivilegeEntity privilege1 = createNiceMock(PrivilegeEntity.class); PrivilegeEntity privilege2 = createNiceMock(PrivilegeEntity.class); List<PrivilegeEntity> privileges = Arrays.asList(privilege1, privilege2); PrivilegeDAO privilegeDAO = viewInstanceOperationHandler.privilegeDAO; PrincipalEntity principalEntity = createNiceMock(PrincipalEntity.class); expect(privilege1.getPrincipal()).andReturn(principalEntity); expect(privilege2.getPrincipal()).andReturn(principalEntity); principalEntity.removePrivilege(privilege1); principalEntity.removePrivilege(privilege2); expect(privilegeDAO.findByResourceId(3L)).andReturn(privileges); privilegeDAO.remove(privilege1); privilegeDAO.remove(privilege2); viewInstanceDAO.remove(viewInstanceEntity); replay(privilegeDAO, viewDAO, viewInstanceDAO, principalEntity, privilege1, privilege2,viewInstanceEntity, viewEntity); viewInstanceOperationHandler.uninstallViewInstance(instanceEntity); verify(privilegeDAO, viewDAO, viewInstanceDAO); }