ServiceByDateFilter extends AbstractTrustedServiceFilter { @Override boolean isAcceptable(TrustedServiceWrapper service) { Date startDate = service.getStartDate(); Date endDate = service.getEndDate(); if (date == null) { return false; } boolean afterStartRange = (startDate != null && (date.compareTo(startDate) >= 0)); boolean beforeEndRange = (endDate == null || (date.compareTo(endDate) <= 0)); return afterStartRange && beforeEndRange; } ServiceByDateFilter(Date date);   }
@Test public void testInRange() { ServiceByDateFilter filter = new ServiceByDateFilter(DATE2); TrustedServiceWrapper service = new TrustedServiceWrapper(); service.setStartDate(DATE1); service.setEndDate(DATE3); assertTrue(filter.isAcceptable(service)); }
@Test public void testNoEndRange() { ServiceByDateFilter filter = new ServiceByDateFilter(DATE2); TrustedServiceWrapper service = new TrustedServiceWrapper(); service.setStartDate(DATE1); assertTrue(filter.isAcceptable(service)); }
@Test public void testNoDateRange() { ServiceByDateFilter filter = new ServiceByDateFilter(DATE2); TrustedServiceWrapper service = new TrustedServiceWrapper(); assertFalse(filter.isAcceptable(service)); }
@Test public void testNotInRange() { ServiceByDateFilter filter = new ServiceByDateFilter(DATE3); TrustedServiceWrapper service = new TrustedServiceWrapper(); service.setStartDate(DATE1); service.setEndDate(DATE2); assertFalse(filter.isAcceptable(service)); }
@Test public void testInRangeSameStartDate() { ServiceByDateFilter filter = new ServiceByDateFilter(DATE1); TrustedServiceWrapper service = new TrustedServiceWrapper(); service.setStartDate(DATE1); service.setEndDate(DATE3); assertTrue(filter.isAcceptable(service)); }
@Test public void testInRangeSameEndDate() { ServiceByDateFilter filter = new ServiceByDateFilter(DATE3); TrustedServiceWrapper service = new TrustedServiceWrapper(); service.setStartDate(DATE1); service.setEndDate(DATE3); assertTrue(filter.isAcceptable(service)); }