### Question:
XProperties extends OrderedProperties { @Nullable public <T> T getObject(@Nonnull final String key) { return getObjectOrDefault(key, null); } XProperties();  XProperties(@Nonnull final Map<String, String> initial); @Nonnull static XProperties from(@Nonnull @NonNull final String absolutePath); void register(@Nonnull final String prefix,
            @Nonnull final Conversion<?, ? extends Exception> factory); @Override synchronized void load(@Nonnull final Reader reader); @Override synchronized void load(final InputStream inStream); @Nullable @Override String getProperty(final String key); @Nullable @Override synchronized Object get(final Object key); @Nullable T getObject(@Nonnull final String key); @Nullable @SuppressWarnings("unchecked") T getObjectOrDefault(@Nonnull final String key,
            @Nullable final T defaultValue);  }### Answer:
@Test public void shouldThrowWhenWronglyKeyAssignedToNonString() { thrown.expect(ClassCastException.class); thrown.expectMessage(containsString(Integer.class.getName())); xprops.setProperty("bar", ""); final Integer ignored = xprops.getObject("bar"); }
@Test public void shouldGetInt() { xprops.setProperty("bar", "3"); assertThat(xprops.getObject("int:bar"), is(equalTo(3))); }
@Test public void shouldGetIntegerExplicit() { xprops.setProperty("bar", "3"); assertThat(xprops.getObject("java.math.BigInteger:bar"), is(equalTo(new BigInteger("3")))); }
@Test public void shouldGetIntegerAliased() { xprops.setProperty("bar", "3"); assertThat(xprops.getObject("integer:bar"), is(equalTo(new BigInteger("3")))); }
@Test public void shouldGetDecimal() { xprops.setProperty("bar", "3"); assertThat(xprops.getObject("decimal:bar"), is(equalTo(new BigDecimal("3")))); }
@Test public void shouldGetResources() { xprops.setProperty("bar", format("classpath*:%sincluded*.properties", firstPathComponent(pathPrefix))); final List<Resource> resources = xprops.getObject("resource*:bar"); assertThat(resources.size(), is(equalTo(2))); assertThat(resources, tests( "contains resource filename ending with 'included" + ".properties'", r -> r.stream(). map(Resource::getFilename). filter(f -> f.endsWith("included.properties")). findFirst(). isPresent())); assertThat(resources, tests( "contains resource filename ending with 'included2.properties'", r -> r.stream(). map(Resource::getFilename). filter(f -> f.endsWith("included2.properties")). findFirst(). isPresent())); }
@Test public void shouldGetAddress() { xprops.setProperty("bar", "[2001:db8::1]:80"); final InetSocketAddress address = xprops.getObject("address:bar"); assertThat(address.getHostString(), is(equalTo("2001:db8::1"))); assertThat(address.getPort(), is(equalTo(80))); }
@Test public void shouldThrowForBadAddress() { thrown.expect(FailedConversionException.class); thrown.expectMessage(containsString("address:bar")); thrown.expectMessage(containsString("-@-")); xprops.setProperty("bar", "-@-"); xprops.getObject("address:bar"); }