@Test public final void testLookup() throws NamingException { final List<Person> primaryList = new ArrayList<Person>(); final List<Person> secondaryList = new ArrayList<Person>(); primaryList.add(new Person("lastf", "Primary", "M", "Last", "F")); primaryList.add(new Person("other", "other", "M", "Last", "F")); secondaryList.add(new Person("lastf", "Secondar", "M", "Last", "F")); context.checking(new Expectations() { { oneOf(primaryMock).findPeople("searchString", 0); will(returnValue(primaryList)); oneOf(secondaryMock).findPeople("searchString", 0); will(returnValue(secondaryList)); } }); List<Person> results = sut.findPeople("searchString", 0); assertEquals(2, results.size()); context.assertIsSatisfied(); }
public List<Person> findPeople(final String searchString, final int searchLimit) { List<Person> primaryList = primary.findPeople(searchString, searchLimit); List<Person> secondaryList = secondary.findPeople(searchString, searchLimit); HashMap<String, Person> personMap = new HashMap<String, Person>(); if (null != primaryList) { for (Person p : primaryList) { personMap.put(p.getAccountId(), p); } } if (null != secondaryList) { for (Person p : secondaryList) { if (!(personMap.containsKey(p.getAccountId()))) { personMap.put(p.getAccountId(), p); } } } List<Person> mergedList = new ArrayList<Person>(); mergedList.addAll(personMap.values()); return mergedList; }
MultiSourcePersonLookup implements PersonLookupStrategy { public List<Person> findPeople(final String searchString, final int searchLimit) { List<Person> primaryList = primary.findPeople(searchString, searchLimit); List<Person> secondaryList = secondary.findPeople(searchString, searchLimit); HashMap<String, Person> personMap = new HashMap<String, Person>(); if (null != primaryList) { for (Person p : primaryList) { personMap.put(p.getAccountId(), p); } } if (null != secondaryList) { for (Person p : secondaryList) { if (!(personMap.containsKey(p.getAccountId()))) { personMap.put(p.getAccountId(), p); } } } List<Person> mergedList = new ArrayList<Person>(); mergedList.addAll(personMap.values()); return mergedList; } }
MultiSourcePersonLookup implements PersonLookupStrategy { public List<Person> findPeople(final String searchString, final int searchLimit) { List<Person> primaryList = primary.findPeople(searchString, searchLimit); List<Person> secondaryList = secondary.findPeople(searchString, searchLimit); HashMap<String, Person> personMap = new HashMap<String, Person>(); if (null != primaryList) { for (Person p : primaryList) { personMap.put(p.getAccountId(), p); } } if (null != secondaryList) { for (Person p : secondaryList) { if (!(personMap.containsKey(p.getAccountId()))) { personMap.put(p.getAccountId(), p); } } } List<Person> mergedList = new ArrayList<Person>(); mergedList.addAll(personMap.values()); return mergedList; } MultiSourcePersonLookup(final PersonLookupStrategy inPrimary, final PersonLookupStrategy inSecondary); }
MultiSourcePersonLookup implements PersonLookupStrategy { public List<Person> findPeople(final String searchString, final int searchLimit) { List<Person> primaryList = primary.findPeople(searchString, searchLimit); List<Person> secondaryList = secondary.findPeople(searchString, searchLimit); HashMap<String, Person> personMap = new HashMap<String, Person>(); if (null != primaryList) { for (Person p : primaryList) { personMap.put(p.getAccountId(), p); } } if (null != secondaryList) { for (Person p : secondaryList) { if (!(personMap.containsKey(p.getAccountId()))) { personMap.put(p.getAccountId(), p); } } } List<Person> mergedList = new ArrayList<Person>(); mergedList.addAll(personMap.values()); return mergedList; } MultiSourcePersonLookup(final PersonLookupStrategy inPrimary, final PersonLookupStrategy inSecondary); List<Person> findPeople(final String searchString, final int searchLimit); }
MultiSourcePersonLookup implements PersonLookupStrategy { public List<Person> findPeople(final String searchString, final int searchLimit) { List<Person> primaryList = primary.findPeople(searchString, searchLimit); List<Person> secondaryList = secondary.findPeople(searchString, searchLimit); HashMap<String, Person> personMap = new HashMap<String, Person>(); if (null != primaryList) { for (Person p : primaryList) { personMap.put(p.getAccountId(), p); } } if (null != secondaryList) { for (Person p : secondaryList) { if (!(personMap.containsKey(p.getAccountId()))) { personMap.put(p.getAccountId(), p); } } } List<Person> mergedList = new ArrayList<Person>(); mergedList.addAll(personMap.values()); return mergedList; } MultiSourcePersonLookup(final PersonLookupStrategy inPrimary, final PersonLookupStrategy inSecondary); List<Person> findPeople(final String searchString, final int searchLimit);  }