ContributorsListProvider implements ResourceListProvider { @Override public Map<String, String> getList(String listName, ResourceListQuery query) { if (listName.equalsIgnoreCase(USERNAMES)) { return getListWithUserNames(query); } else if (listName.equalsIgnoreCase(NAMES_TO_USERNAMES)) { return getListWithTechnicalPresenters(query); } else { return getList(query); } }  void setUserDirectoryService(UserDirectoryService userDirectoryService); void setIndex(AbstractSearchIndex index); @Override String[] getListNames(); @Override Map<String, String> getList(String listName, ResourceListQuery query); @Override boolean isTranslatable(String listName); @Override String getDefault(); static final String DEFAULT; static final String NAMES_TO_USERNAMES; static final String USERNAMES; }
@Test public void testUsernamesList() { Map<String, String> list = contributorsListProvider.getList(ContributorsListProvider.NAMES_TO_USERNAMES, null); Assert.assertTrue(list.containsKey(user1.getUsername())); Assert.assertTrue(list.containsKey(user2.getUsername())); Assert.assertTrue(list.containsKey(user3.getUsername())); Assert.assertTrue(list.containsValue(user1.getName())); Assert.assertTrue(list.containsValue(user2.getName())); Assert.assertTrue(list.containsValue(user3.getUsername())); Assert.assertTrue(list.containsKey("User 5")); Assert.assertTrue(list.containsValue("User 5")); Assert.assertEquals(5, list.size()); }
@Test public void testListSimple() throws ListProviderException { Map<String, String> list = contributorsListProvider.getList(ContributorsListProvider.DEFAULT, null); Assert.assertTrue(list.containsKey(user1.getName())); Assert.assertTrue(list.containsKey(user2.getName())); Assert.assertTrue(list.containsValue(user1.getName())); Assert.assertTrue(list.containsValue(user2.getName())); Assert.assertTrue(list.containsKey("User 5")); Assert.assertTrue(list.containsValue("User 5")); Assert.assertEquals(3, list.size()); }
@Test public void testListQuery() { ResourceListQueryImpl query = new ResourceListQueryImpl(); query.setLimit(0); query.setOffset(0); Assert.assertEquals(5, contributorsListProvider.getList(ContributorsListProvider.NAMES_TO_USERNAMES, query).size()); query.setOffset(3); Assert.assertEquals(2, contributorsListProvider.getList(ContributorsListProvider.NAMES_TO_USERNAMES, query).size()); query.setOffset(0); query.setLimit(1); Assert.assertEquals(1, contributorsListProvider.getList(ContributorsListProvider.NAMES_TO_USERNAMES, query).size()); }