### Question:
RangerPolicyServiceBase extends
		RangerBaseModelService<T, V> { @Override @SuppressWarnings("unchecked") protected XXPolicyBase mapViewToEntityBean(RangerPolicy vObj, XXPolicyBase xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); xObj.setVersion(vObj.getVersion()); XXService xService = daoMgr.getXXService().findByName(vObj.getService()); if (xService == null) { throw restErrorUtil.createRESTException("No corresponding service found for policyName: " + vObj.getName() + "Service Not Found : " + vObj.getName(), MessageEnums.INVALID_INPUT_DATA); } xObj.setService(xService.getId()); xObj.setName(vObj.getName()); xObj.setPolicyType(vObj.getPolicyType()); xObj.setDescription(vObj.getDescription()); xObj.setResourceSignature(vObj.getResourceSignature()); xObj.setIsAuditEnabled(vObj.getIsAuditEnabled()); xObj.setIsEnabled(vObj.getIsEnabled()); return xObj; } RangerPolicyServiceBase(); @SuppressWarnings("unchecked") RangerPolicyList searchRangerPolicies(SearchFilter searchFilter);  }### Answer:
@Test public void test1mapViewToEntityBean() { XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class); XXService xService = Mockito.mock(XXService.class); RangerPolicy rangerPolicy = rangerPolicy(); XXPolicy policy = policy(); int OPERATION_CONTEXT = 0; Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao); Mockito.when(xServiceDao.findByName(rangerPolicy.getService())) .thenReturn(xService); XXPolicy dbPolicy = policyService.mapViewToEntityBean(rangerPolicy, policy, OPERATION_CONTEXT); Assert.assertNotNull(dbPolicy); Assert.assertEquals(dbPolicy.getId(), policy.getId()); Assert.assertEquals(dbPolicy.getGuid(), policy.getGuid()); Assert.assertEquals(dbPolicy.getName(), policy.getName()); Assert.assertEquals(dbPolicy.getAddedByUserId(), policy.getAddedByUserId()); Assert.assertEquals(dbPolicy.getIsEnabled(), policy.getIsEnabled()); Assert.assertEquals(dbPolicy.getVersion(), policy.getVersion()); Assert.assertEquals(dbPolicy.getDescription(), policy.getDescription()); Mockito.verify(daoManager).getXXService(); }
@Test public void test2mapViewToEntityBeanNullValue() { XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class); RangerPolicy rangerPolicy = rangerPolicy(); XXPolicy policy = policy(); int OPERATION_CONTEXT = 0; Mockito.when( restErrorUtil.createRESTException( "No corresponding service found for policyName: " + rangerPolicy.getName() + "Service Not Found : " + rangerPolicy.getName(), MessageEnums.INVALID_INPUT_DATA)).thenThrow( new WebApplicationException()); thrown.expect(WebApplicationException.class); Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao); Mockito.when(xServiceDao.findByName(rangerPolicy.getService())) .thenReturn(null); XXPolicy dbPolicy = policyService.mapViewToEntityBean(rangerPolicy, policy, OPERATION_CONTEXT); Assert.assertNotNull(dbPolicy); Assert.assertEquals(dbPolicy.getId(), policy.getId()); Assert.assertEquals(dbPolicy.getGuid(), policy.getGuid()); Assert.assertEquals(dbPolicy.getName(), policy.getName()); Assert.assertEquals(dbPolicy.getAddedByUserId(), policy.getAddedByUserId()); Assert.assertEquals(dbPolicy.getIsEnabled(), policy.getIsEnabled()); Assert.assertEquals(dbPolicy.getVersion(), policy.getVersion()); Assert.assertEquals(dbPolicy.getDescription(), policy.getDescription()); Mockito.verify(daoManager).getXXService(); }