SecurityZoneDBStore implements SecurityZoneStore { @Override public List<RangerSecurityZone> getSecurityZones(SearchFilter filter) throws Exception { List<RangerSecurityZone> ret = new ArrayList<>(); List<XXSecurityZone> xxSecurityZones = daoMgr.getXXSecurityZoneDao().getAll(); for (XXSecurityZone xxSecurityZone : xxSecurityZones) { if (!xxSecurityZone.getId().equals(RangerSecurityZone.RANGER_UNZONED_SECURITY_ZONE_ID)) { ret.add(securityZoneService.read(xxSecurityZone.getId())); } } if (CollectionUtils.isNotEmpty(ret) && filter != null && !filter.isEmpty()) { List<RangerSecurityZone> copy = new ArrayList<>(ret); predicateUtil.applyFilter(copy, filter); ret = copy; } return ret; }  void init(); @PostConstruct void initStore(); @Override RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone); @Override RangerSecurityZone updateSecurityZoneById(RangerSecurityZone securityZone); @Override void deleteSecurityZoneByName(String zoneName); @Override void deleteSecurityZoneById(Long zoneId); @Override RangerSecurityZone getSecurityZone(Long id); @Override RangerSecurityZone getSecurityZoneByName(String name); @Override List<RangerSecurityZone> getSecurityZones(SearchFilter filter); @Override Map<String, RangerSecurityZone.RangerSecurityZoneService> getSecurityZonesForService(String serviceName);  }
@Test public void test6getSecurityZones() throws Exception { SearchFilter filter = new SearchFilter(); filter.setParam(SearchFilter.ZONE_NAME, "sz1"); List<RangerSecurityZone> ret = new ArrayList<>(); List<XXSecurityZone> xxSecurityZones = new ArrayList<XXSecurityZone>(); XXSecurityZone xxSecurityZone = new XXSecurityZone(); xxSecurityZone.setId(2L); xxSecurityZone.setName("sz1"); xxSecurityZones.add(xxSecurityZone); RangerSecurityZone rangerSecurityZone = new RangerSecurityZone(); rangerSecurityZone.setId(3L); ret.add(rangerSecurityZone); List<RangerSecurityZone> copy = new ArrayList<>(ret); XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class); Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao); Mockito.when(xXSecurityZoneDao.getAll()).thenReturn(xxSecurityZones); Mockito.when(securityZoneService.read(xxSecurityZone.getId())).thenReturn(rangerSecurityZone); Mockito.doNothing().when(predicateUtil).applyFilter(copy, filter); securityZoneDBStore.getSecurityZones(filter); Assert.assertNotNull(xxSecurityZone); Assert.assertNotNull(xxSecurityZones); Mockito.verify(daoManager).getXXSecurityZoneDao(); Mockito.verify(securityZoneService).read(xxSecurityZone.getId()); Mockito.verify(predicateUtil).applyFilter(copy, filter); }