UserMessageArchivePreferencesElement { static XMLElement toXml(String namespace, UserMessageArchivePreferences preferences) { List<XMLFragment> alwaysJids = preferences.getAlwaysArchivedToOrFromJids().stream() .map(entity -> new XMLElement(null, "jid", null, Collections.emptyList(), Collections.singletonList(new XMLText(entity.getFullQualifiedName())))) .collect(Collectors.toList()); XMLElement alwaysElement = new XMLElement(null, "always", null, Collections.emptyList(), alwaysJids); List<XMLFragment> neverJids = preferences.getNeverArchivedToOrFromJids().stream() .map(entity -> new XMLElement(null, "jid", null, Collections.emptyList(), Collections.singletonList(new XMLText(entity.getFullQualifiedName())))) .collect(Collectors.toList()); XMLElement neverElement = new XMLElement(null, "never", null, Collections.emptyList(), neverJids); List<XMLFragment> prefsFragments = new ArrayList<>(); prefsFragments.add(alwaysElement); prefsFragments.add(neverElement); Attribute defaultBehaviour = new Attribute("default", preferences.getDefaultBehaviour().name().toLowerCase()); return new XMLElement(namespace, NAME, null, Collections.singletonList(defaultBehaviour), prefsFragments); } private  UserMessageArchivePreferencesElement();   }
@Test public void toXml() { UserMessageArchivePreferences preferences = new SimpleUserMessageArchivePreferences( DefaultUserArchiveBehaviour.ROSTER, Collections.singleton(EntityImpl.parseUnchecked("always@foo.com")), Collections.singleton(EntityImpl.parseUnchecked("never@foo.com"))); XMLElement prefs = UserMessageArchivePreferencesElement.toXml("foo", preferences); assertEquals("prefs", prefs.getName()); assertEquals("foo", prefs.getNamespaceURI()); List<XMLElement> innerElements = prefs.getInnerElements(); XMLElement always = innerElements.get(0); assertEquals("always", always.getName()); List<XMLElement> alwaysJids = always.getInnerElements(); assertEquals(1, alwaysJids.size()); assertEquals("always@foo.com", alwaysJids.get(0).getInnerText().getText()); XMLElement never = innerElements.get(1); assertEquals("never", never.getName()); List<XMLElement> neverJids = never.getInnerElements(); assertEquals(1, neverJids.size()); assertEquals("never@foo.com", neverJids.get(0).getInnerText().getText()); }