NamespaceContextMap implements NamespaceContext { @Override public final Iterator<String> getPrefixes(final String namespaceURI) { List<String> prefixes = uriMap.get(namespaceURI); if (prefixes == null) { prefixes = Collections.emptyList(); } return prefixes.iterator(); } NamespaceContextMap(@Nullable final String... values); @Override final String getNamespaceURI(final String prefix); @Override final String getPrefix(final String namespaceURI); @Override final Iterator<String> getPrefixes(final String namespaceURI);  }
@Test public void testGetPrefixesUnbound() { final NamespaceContextMap testee = new NamespaceContextMap(); final Iterator<String> itPrefixes = testee.getPrefixes("http: assertThat(itPrefixes).isNotNull(); assertThat(itPrefixes.hasNext()).isFalse(); }
@Test public void testGetPrefixesSingle() { final NamespaceContextMap testee = new NamespaceContextMap("abc", "http: final Iterator<String> itPrefixes = testee.getPrefixes("http: assertThat(itPrefixes.next()).isEqualTo("abc"); assertThat(itPrefixes.hasNext()).isFalse(); }
@Test public void testGetPrefixesMultiple() { final NamespaceContextMap testee = new NamespaceContextMap("abc", "http: final Iterator<String> itPrefixes = testee.getPrefixes("http: assertThat(itPrefixes.next()).isEqualTo("abc"); assertThat(itPrefixes.next()).isEqualTo("def"); assertThat(itPrefixes.hasNext()).isFalse(); }
@Test public void testGetPrefixesXML_NS_URI() { final NamespaceContextMap testee = new NamespaceContextMap(); final Iterator<String> itPrefixes = testee.getPrefixes(XMLConstants.XML_NS_URI); assertThat(itPrefixes.next()).isEqualTo(XMLConstants.XML_NS_PREFIX); assertThat(itPrefixes.hasNext()).isFalse(); }
@Test public void testGetPrefixesXMLNS_ATTRIBUTE_NS_URI() { final NamespaceContextMap testee = new NamespaceContextMap(); final Iterator<String> itPrefixes = testee.getPrefixes(XMLConstants.XMLNS_ATTRIBUTE_NS_URI); assertThat(itPrefixes.next()).isEqualTo(XMLConstants.XMLNS_ATTRIBUTE); assertThat(itPrefixes.hasNext()).isFalse(); }
@Test public void testGetPrefixesNull() { final NamespaceContextMap testee = new NamespaceContextMap(); try { testee.getPrefixes(null); } catch (final IllegalArgumentException ex) { assertThat(ex.getMessage()).isEqualTo(""); } }