SmartRegisterClients extends ArrayList<SmartRegisterClient> { public SmartRegisterClients applyFilter(final FilterOption villageFilter, final ServiceModeOption serviceModeOption, final FilterOption searchFilter, SortOption sortOption) { SmartRegisterClients results = new SmartRegisterClients(); Iterables.addAll(results, Iterables.filter(this, new Predicate<SmartRegisterClient>() { @Override public boolean apply(SmartRegisterClient client) { return villageFilter.filter(client) && searchFilter.filter(client); } })); serviceModeOption.apply(); return sortOption.sort(results); }  SmartRegisterClients applyFilter(final FilterOption villageFilter, final ServiceModeOption serviceModeOption,
                                            final FilterOption searchFilter, SortOption sortOption); SmartRegisterClients applyFilterWithFP(final ServiceModeOption serviceModeOption, SortOption sortOption, final FilterOption... filterOptions);  }
@Test public void emptyStringSearchShouldReturnAllTheResults() { SmartRegisterClients originalClients = getUniformSmartRegisterClients(10); SmartRegisterClients filteredClients = originalClients.applyFilter( new AllClientsFilter(), allEligibleCoupleServiceMode, new ECSearchOption(""), new NameSort()); assertEquals(originalClients, filteredClients); }
@Test public void ShouldReturnFilteredResultsForSearchString() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new AllClientsFilter(), allEligibleCoupleServiceMode, new ECSearchOption("a"), new NameSort()); assertEquals(3, filteredClients.size()); for (int i = 0; i < 3; i++) { assertTrue(filteredClients.get(i).name().startsWith("A")); } }
@Test public void ShouldReturnSortedResultsForNameSortOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new AllClientsFilter(), allEligibleCoupleServiceMode, new ECSearchOption(""), new NameSort()); ECClients expectedClients = new ECClients(); expectedClients.addAll( asList( new ECClient("abcd1", "Adhiti", "Rama", "Battiganahalli", 69).withIsHighPriority(true).withIsOutOfArea(true), new ECClient("abcd2", "Akshara", "Rajesh", "Half bherya", 500).withCaste("SC").withEconomicStatus("BPL").withIsHighPriority(true).withFPMethod("condom"), new ECClient("abcd3", "Anitha", "Chandan", "Half bherya", 87).withCaste("SC").withIsOutOfArea(true).withFPMethod("ocp").withFPMethod("ocp"), new ECClient("abcd6", "Bhagya", "Ramesh", "Hosa agrahara", 93).withIsHighPriority(true).withCaste("ST").withFPMethod("condom"), new ECClient("abcd4", "Bhavani", "Ravi", "Gowrikoppalu", 140).withEconomicStatus("BPL").withFPMethod("female_sterilization"), new ECClient("abcd5", "Chaitra", "Rams", "Somanahalli colony", 36).withCaste("ST").withFPMethod("ocp") )); assertEquals(expectedClients, filteredClients); }
@Test public void ShouldReturnSortedResultsForECNumberSortOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new AllClientsFilter(), allEligibleCoupleServiceMode, new ECSearchOption(""), new ECNumberSort()); assertEquals(6, filteredClients.size()); assertEquals("Adhiti", filteredClients.get(1).name()); assertEquals("Akshara", filteredClients.get(5).name()); assertEquals("Anitha", filteredClients.get(2).name()); assertEquals("Bhagya", filteredClients.get(3).name()); assertEquals("Bhavani", filteredClients.get(4).name()); assertEquals("Chaitra", filteredClients.get(0).name()); }
@Test public void ShouldReturnSortedResultsForBPLSortOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new AllClientsFilter(), allEligibleCoupleServiceMode, new ECSearchOption(""), new BPLSort()); assertEquals(6, filteredClients.size()); assertEquals("Adhiti", filteredClients.get(2).name()); assertEquals("Akshara", filteredClients.get(0).name()); assertEquals("Anitha", filteredClients.get(3).name()); assertEquals("Bhagya", filteredClients.get(4).name()); assertEquals("Bhavani", filteredClients.get(1).name()); assertEquals("Chaitra", filteredClients.get(5).name()); }
@Test public void ShouldReturnSortedResultsForHPSortOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new AllClientsFilter(), allEligibleCoupleServiceMode, new ECSearchOption(""), new HighPrioritySort()); assertEquals(6, filteredClients.size()); assertEquals("Adhiti", filteredClients.get(0).name()); assertEquals("Akshara", filteredClients.get(1).name()); assertEquals("Bhagya", filteredClients.get(2).name()); assertEquals("Chaitra", filteredClients.get(5).name()); assertEquals("Bhavani", filteredClients.get(4).name()); assertEquals("Anitha", filteredClients.get(3).name()); }
@Test public void ShouldReturnSortedResultsForSCSortOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new AllClientsFilter(), allEligibleCoupleServiceMode, new ECSearchOption(""), new SCSort()); assertEquals(6, filteredClients.size()); assertEquals("Adhiti", filteredClients.get(2).name()); assertEquals("Akshara", filteredClients.get(0).name()); assertEquals("Anitha", filteredClients.get(1).name()); assertEquals("Bhagya", filteredClients.get(3).name()); assertEquals("Bhavani", filteredClients.get(4).name()); assertEquals("Chaitra", filteredClients.get(5).name()); }
@Test public void ShouldReturnSortedResultsForSTSortOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new AllClientsFilter(), allEligibleCoupleServiceMode, new ECSearchOption(""), new STSort()); assertEquals(6, filteredClients.size()); assertEquals("Adhiti", filteredClients.get(2).name()); assertEquals("Akshara", filteredClients.get(3).name()); assertEquals("Anitha", filteredClients.get(4).name()); assertEquals("Bhagya", filteredClients.get(0).name()); assertEquals("Bhavani", filteredClients.get(5).name()); assertEquals("Chaitra", filteredClients.get(1).name()); }
@Test public void ShouldReturn2ResultsFor_Half_Bherya_VillageFilterOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new VillageFilter("Half bherya"), allEligibleCoupleServiceMode, new ECSearchOption(""), new NameSort()); assertEquals(2, filteredClients.size()); assertEquals("Akshara", filteredClients.get(0).name()); assertEquals("Anitha", filteredClients.get(1).name()); }
@Test public void ShouldReturn2ResultsFor_Hosa_agrahara_VillageFilterOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new VillageFilter("Hosa agrahara"), allEligibleCoupleServiceMode, new ECSearchOption(""), new NameSort()); assertEquals(1, filteredClients.size()); assertEquals("Bhagya", filteredClients.get(0).name()); }
@Test public void ShouldReturn1ResultsFor_Battiganahalli_VillageFilterOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new VillageFilter("Battiganahalli"), allEligibleCoupleServiceMode, new ECSearchOption(""), new NameSort()); assertEquals(1, filteredClients.size()); assertEquals("Adhiti", filteredClients.get(0).name()); }
@Test public void ShouldReturn1ResultsFor_Somanahalli_colony_VillageFilterOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new VillageFilter("Somanahalli colony"), allEligibleCoupleServiceMode, new ECSearchOption(""), new NameSort()); assertEquals(1, filteredClients.size()); assertEquals("Chaitra", filteredClients.get(0).name()); }
@Test public void ShouldReturn1ResultsForOutOfAreaFilterOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new OutOfAreaFilter(), allEligibleCoupleServiceMode, new ECSearchOption(""), new NameSort()); assertEquals(2, filteredClients.size()); assertEquals("Adhiti", filteredClients.get(0).name()); assertEquals("Anitha", filteredClients.get(1).name()); }
@Test public void ShouldReturnCascadedResultsApplyingMultipleFilterOption() { SmartRegisterClients originalClients = getSmartRegisterClientsWithProperDetails(); SmartRegisterClients filteredClients = originalClients.applyFilter( new VillageFilter("Hosa agrahara"), allEligibleCoupleServiceMode, new ECSearchOption("bh"), new NameSort()); assertEquals(1, filteredClients.size()); assertEquals("Bhagya", filteredClients.get(0).name()); }