SimpleNamespaceContext implements NamespaceContext { @Override public String getPrefix(String namespaceUri) { Iterator<String> iterator = getPrefixes(namespaceUri); return iterator.hasNext() ? iterator.next() : null; }  @Override String getNamespaceURI(String prefix); @Override String getPrefix(String namespaceUri); @Override Iterator<String> getPrefixes(String namespaceUri); void setBindings(Map<String, String> bindings); void bindDefaultNamespaceUri(String namespaceUri); void bindNamespaceUri(String prefix, String namespaceUri); void clear(); Iterator<String> getBoundPrefixes(); void removeBinding(String prefix); boolean hasBinding(String prefix);  }
@Test public void testGetPrefix() { context.bindDefaultNamespaceUri("defaultNamespaceURI"); Assert.assertEquals("Invalid prefix for default namespace", XMLConstants.DEFAULT_NS_PREFIX, context.getPrefix("defaultNamespaceURI")); Assert.assertEquals("Invalid prefix for bound namespace", "prefix", context.getPrefix("namespaceURI")); Assert.assertNull("Invalid prefix for unbound namespace", context.getPrefix("unbound")); Assert.assertEquals("Invalid prefix for namespace", XMLConstants.XML_NS_PREFIX, context.getPrefix(XMLConstants.XML_NS_URI)); Assert.assertEquals("Invalid prefix for attribute namespace", XMLConstants.XMLNS_ATTRIBUTE, context.getPrefix(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)); }