Environment { public <T> void setProperty(@NonNull final String key, T value) { Class clazz = value.getClass(); if(Number.class.isAssignableFrom(clazz) || String.class == clazz || Boolean.class == clazz) { properties.put(key, value); } else { throw new RuntimeException("Value must be of type Number, String or Boolean"); } } Environment(); boolean isProduction(); T getProperty(@NonNull final String key, final T defaultValue); void setProperty(@NonNull final String key, T value); String getName(); void setName(@NonNull final String name); @Override String toString(); @Override boolean equals(final Object object); @Override int hashCode(); static final String ENVIRONMENT_PRODUCTION; }
@Test(expected = RuntimeException.class) public void whenSetInvalidType_exceptionIsThrown() { environment.setProperty("test", new Environment()); }
@Test public void whenSetValidType_noErrors() { environment.setProperty("test", 1); }