RangerTagDefService extends RangerTagDefServiceBase<XXTagDef, RangerTagDef> { public RangerTagDef getTagDefByName(String name) { RangerTagDef ret = null; XXTagDef xxTagDef = daoMgr.getXXTagDef().findByName(name); if(xxTagDef != null) { ret = populateViewBean(xxTagDef); } return ret; } RangerTagDefService(); RangerTagDef getPopulatedViewObject(XXTagDef xObj); RangerTagDef getTagDefByGuid(String guid); RangerTagDef getTagDefByName(String name); List<RangerTagDef> getTagDefsByServiceId(Long serviceId); @Override List<RangerTagDef.RangerTagAttributeDef> getAttributeDefForTagDef(XXTagDef xtagDef);  }
@Test public void test6getTagDefByName(){ RangerTagDef oldTagDef = new RangerTagDef(); oldTagDef.setId(id); oldTagDef.setName(name); XXTagDef xxTagDef = new XXTagDef(); xxTagDef.setId(id); xxTagDef.setName(name); xxTagDef.setUpdateTime(new Date()); XXTagDefDao xXTagDefDao = Mockito.mock(XXTagDefDao.class); Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao); Mockito.when(xXTagDefDao.findByName(name)).thenReturn(xxTagDef); List<XXTagAttributeDef> tagAttrDefList = new ArrayList<XXTagAttributeDef>(); XXTagAttributeDef xxTagAttributeDef = new XXTagAttributeDef(); xxTagAttributeDef.setId(id); xxTagAttributeDef.setName(name); tagAttrDefList.add(xxTagAttributeDef); RangerTagDef result = rangerTagDefService.getTagDefByName(name); Assert.assertEquals(result.getId(), tagAttrDefList.get(0).getId()); Assert.assertEquals(result.getName(), tagAttrDefList.get(0).getName()); Mockito.verify(daoMgr).getXXTagDef(); Mockito.verify(xXTagDefDao).findByName(name); }
@Test public void test7getTagDefByName(){ XXTagDef xxTagDef = null; XXTagDefDao xXTagDefDao = Mockito.mock(XXTagDefDao.class); Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao); Mockito.when(xXTagDefDao.findByName(name)).thenReturn(xxTagDef); RangerTagDef result = rangerTagDefService.getTagDefByName(name); Assert.assertNull(result); Mockito.verify(daoMgr).getXXTagDef(); Mockito.verify(xXTagDefDao).findByName(name); }