DefaultConfiguration implements Configuration, Serializable { @Override public String getOrDefault(String key, String defaultValue) { Objects.requireNonNull(key, "Key must not be null."); String val = get(key); if(val==null){ return defaultValue; } return val; } DefaultConfiguration(ConfigurationContext configurationContext); @Override String get(String key); List<PropertyValue> getValues(String key); @Override String getOrDefault(String key, String defaultValue); @Override T getOrDefault(String key, Class<T> type, T defaultValue); @Override Map<String, String> getProperties(); @Override T get(String key, Class<T> type); @Override T get(String key, TypeLiteral<T> type); @Override T getOrDefault(String key, TypeLiteral<T> type, T defaultValue); @Override Configuration with(ConfigOperator operator); @Override T query(ConfigQuery<T> query); @Override ConfigurationContext getContext(); @Override ConfigurationSnapshot getSnapshot(Iterable<String> keys); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test(expected = NullPointerException.class) public void getOrDefaultDoesNotAcceptNullAsKeyForThreeParameterVariant() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); c.getOrDefault((String)null, String.class, "ok"); }
@Test(expected = NullPointerException.class) public void getOrDefaultDoesNotAcceptNullAsKeyForThreeParameterVariant2() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); c.getOrDefault((Iterable<String>)null, String.class, "ok"); }
@SuppressWarnings({"unchecked", "rawtypes"}) @Test(expected = NullPointerException.class) public void getOrDefaultDoesNotAcceptNullAsTargetTypeForThreeParameterVariant() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); c.getOrDefault("a", (Class) null, "b"); }
@Test(expected = NullPointerException.class) public void getOrDefaultDoesNotAcceptNullAsKeyForThreeParameterVariantSecondIsTypeLiteral() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); c.getOrDefault((String)null, TypeLiteral.of(String.class), "ok"); }
@Test(expected = NullPointerException.class) public void getOrDefaultDoesNotAcceptNullAsKeyForThreeParameterVariantSecondIsTypeLiteral2() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); c.getOrDefault((Iterable<String>)null, TypeLiteral.of(String.class), "ok"); }
@Test public void getOrDefaultDoesAcceptNullAsDefaultValueForThreeParameterVariant() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); assertThat(c.getOrDefault("a", String.class, null)).isNotNull(); assertThat((String) c.getOrDefault("a", TypeLiteral.of(String.class), null)).isNotNull(); }
@Test(expected = NullPointerException.class) public void getOrDefaultDoesNotAcceptNullAsTargetTypeForThreeParameterVariantSecondIsTypeLiteral() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); c.getOrDefault("a", (TypeLiteral<String>) null, "b"); }
@Test(expected = NullPointerException.class) public void getOrDefaultDoesNotAcceptNullAsKeyForTwoParameterVariantDefaultValueIsSecond() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); c.getOrDefault((String)null, "ok"); }
@Test(expected = NullPointerException.class) public void getOrDefaultDoesNotAcceptNullAsKeyForTwoParameterVariantDefaultValueIsSecond2() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); c.getOrDefault((Iterable<String>)null, "ok"); }
@Test public void getOrDefaultDoesAcceptNullAsDefaultValueForTwoParameterVariantDefaultValueIsSecond() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); assertThat(c.getOrDefault("a", null)).isNotNull(); }
@Test public void getOrDefaultReturnDefaultIfValueWouldHaveBeenNull() { DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext()); assertThat("ok").isEqualTo(c.getOrDefault("valueOfNull", "ok")); assertThat("ok").isEqualTo(c.getOrDefault("valueOfNull", String.class, "ok")); assertThat("ok").isEqualTo(c.getOrDefault("valueOfNull", TypeLiteral.of(String.class), "ok")); }