### Question:
NameValueFactory extends AbstractValueFactory<Name> implements NameFactory { public Name create( String value ) { return create(value, getDecoder()); } NameValueFactory( NamespaceRegistry namespaceRegistry,
                             TextDecoder decoder,
                             ValueFactory<String> stringValueFactory ); Name create( String value ); Name create( String value,
                        TextDecoder decoder ); Name create( String namespaceUri,
                        String localName ); Name create( String namespaceUri,
                        String localName,
                        TextDecoder decoder ); Name create( int value ); Name create( long value ); Name create( boolean value ); Name create( float value ); Name create( double value ); Name create( BigDecimal value ); Name create( Calendar value ); Name create( Date value ); Name create( DateTime value ); Name create( Name value ); Name create( Path value ); Name create( Path.Segment segment ); Name create( Reference value ); Name create( URI value ); Name create( UUID value ); Name create( byte[] value ); Name create( Binary value ); Name create( InputStream stream,
                        long approximateLength ); Name create( Reader reader,
                        long approximateLength ); NamespaceRegistry getNamespaceRegistry();  }### Answer:
@Test public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormatWithoutPrefix() { name = factory.create("a"); assertThat(name.getLocalName(), is("a")); assertThat(name.getNamespaceUri(), is(this.registry.getNamespaceForPrefix(""))); }
@Test public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormat() { name = factory.create("dna:something"); assertThat(name.getLocalName(), is("something")); assertThat(name.getNamespaceUri(), is("http: assertThat(name.getString(NO_OP_ENCODER), is("{http: }
@Test public void shouldCreateNameFromSingleEncodedStringInPrefixedNamespaceFormat() { name = factory.create(encoder.encode("dna") + ":" + encoder.encode("some/thing")); assertThat(name.getLocalName(), is("some/thing")); assertThat(name.getNamespaceUri(), is("http: assertThat(name.getString(NO_OP_ENCODER), is("{http: }
@Test public void shouldCreateNameFromSingleStringInStandardFullNamespaceFormat() { name = factory.create("{http: assertThat(name.getLocalName(), is("something")); assertThat(name.getNamespaceUri(), is("http: assertThat(name.getString(NO_OP_ENCODER), is("{http: }
@Test public void shouldCreateNameFromSingleEncodedStringInStandardFullNamespaceFormat() { name = factory.create("{" + encoder.encode("http: assertThat(name.getLocalName(), is("some/thing")); assertThat(name.getNamespaceUri(), is("http: assertThat(name.getString(NO_OP_ENCODER), is("{http: }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowNullLocalName() { factory.create("a", (String)null); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowNullLocalNameWithEncoder() { factory.create("a", null, decoder); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowEmptyLocalName() { factory.create("a", ""); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowEmptyLocalNameWithEncoder() { factory.create("a", "", decoder); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateNameFromStringWithMultipleNonEscapedColons() { factory.create("a:b:c"); }
@Test public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() { List<String> values = new ArrayList<String>(); for (int i = 0; i != 10; ++i) { values.add("dna:something" + i); } Iterator<Name> iter = factory.create(values.iterator()); Iterator<String> valueIter = values.iterator(); while (iter.hasNext()) { assertThat(iter.next(), is(factory.create(valueIter.next()))); } }