@Test public void getMap() throws Exception { XWikiContext context = mock(XWikiContext.class); com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class); when(context.getWiki()).thenReturn(xwiki); XWikiGroupService groupService = mock(XWikiGroupService.class); when(xwiki.getGroupService(any())).thenReturn(groupService); when(groupService.getAllMatchedUsers(any(), anyBoolean(), anyInt(), anyInt(), any(), any())) .thenReturn((List) Arrays.asList("XWiki.Admin")); when(xwiki.getUserName(eq("XWiki.Admin"), any(), anyBoolean(), any())).thenReturn("Administrator"); Utils.setComponentManager(this.componentManager); this.componentManager.registerMockComponent(EntityReferenceSerializer.TYPE_STRING, "local"); this.componentManager.registerMockComponent(EntityReferenceResolver.TYPE_STRING, "relative"); this.componentManager.registerMockComponent(DocumentReferenceResolver.TYPE_REFERENCE, "current"); UsersClass usersClass = new UsersClass(); Map<String, ListItem> results = usersClass.getMap(context); assertEquals(1, results.size()); assertEquals("XWiki.Admin", results.get("XWiki.Admin").getId()); assertEquals("Administrator", results.get("XWiki.Admin").getValue()); }
@Override public Map<String, ListItem> getMap(XWikiContext context) { Map<String, ListItem> result; List<String> users = getList(context); if (users != null && users.size() > 0) { result = new LinkedHashMap<>(); for (String userName : users) { String prettyUserName = context.getWiki().getUserName(userName, null, false, context); result.put(userName, new ListItem(userName, prettyUserName)); } } else { result = Collections.emptyMap(); } return result; }
UsersClass extends ListClass { @Override public Map<String, ListItem> getMap(XWikiContext context) { Map<String, ListItem> result; List<String> users = getList(context); if (users != null && users.size() > 0) { result = new LinkedHashMap<>(); for (String userName : users) { String prettyUserName = context.getWiki().getUserName(userName, null, false, context); result.put(userName, new ListItem(userName, prettyUserName)); } } else { result = Collections.emptyMap(); } return result; } }
UsersClass extends ListClass { @Override public Map<String, ListItem> getMap(XWikiContext context) { Map<String, ListItem> result; List<String> users = getList(context); if (users != null && users.size() > 0) { result = new LinkedHashMap<>(); for (String userName : users) { String prettyUserName = context.getWiki().getUserName(userName, null, false, context); result.put(userName, new ListItem(userName, prettyUserName)); } } else { result = Collections.emptyMap(); } return result; } UsersClass(PropertyMetaClass metaClass);  UsersClass(); }
UsersClass extends ListClass { @Override public Map<String, ListItem> getMap(XWikiContext context) { Map<String, ListItem> result; List<String> users = getList(context); if (users != null && users.size() > 0) { result = new LinkedHashMap<>(); for (String userName : users) { String prettyUserName = context.getWiki().getUserName(userName, null, false, context); result.put(userName, new ListItem(userName, prettyUserName)); } } else { result = Collections.emptyMap(); } return result; } UsersClass(PropertyMetaClass metaClass);  UsersClass(); @Override List<String> getList(XWikiContext context); @Override Map<String, ListItem> getMap(XWikiContext context); @Deprecated boolean isUsesList(); @Deprecated void setUsesList(boolean usesList); @Override BaseProperty newProperty(); @Override BaseProperty fromString(String value); @Override BaseProperty fromStringArray(String[] strings); String getText(String value, XWikiContext context); static List<String> getListFromString(String value); @Override BaseProperty newPropertyfromXML(Element ppcel); @Override List<String> toList(BaseProperty<?> property); @Override void fromList(BaseProperty<?> property, List<String> list); @Override void mergeProperty(BaseProperty<T> currentProperty,
        BaseProperty<T> previousProperty, BaseProperty<T> newProperty, MergeConfiguration configuration,
        XWikiContext xcontext, MergeResult mergeResult); }
UsersClass extends ListClass { @Override public Map<String, ListItem> getMap(XWikiContext context) { Map<String, ListItem> result; List<String> users = getList(context); if (users != null && users.size() > 0) { result = new LinkedHashMap<>(); for (String userName : users) { String prettyUserName = context.getWiki().getUserName(userName, null, false, context); result.put(userName, new ListItem(userName, prettyUserName)); } } else { result = Collections.emptyMap(); } return result; } UsersClass(PropertyMetaClass metaClass);  UsersClass(); @Override List<String> getList(XWikiContext context); @Override Map<String, ListItem> getMap(XWikiContext context); @Deprecated boolean isUsesList(); @Deprecated void setUsesList(boolean usesList); @Override BaseProperty newProperty(); @Override BaseProperty fromString(String value); @Override BaseProperty fromStringArray(String[] strings); String getText(String value, XWikiContext context); static List<String> getListFromString(String value); @Override BaseProperty newPropertyfromXML(Element ppcel); @Override List<String> toList(BaseProperty<?> property); @Override void fromList(BaseProperty<?> property, List<String> list); @Override void mergeProperty(BaseProperty<T> currentProperty,
        BaseProperty<T> previousProperty, BaseProperty<T> newProperty, MergeConfiguration configuration,
        XWikiContext xcontext, MergeResult mergeResult);  }