@Test public void testIfDelegatesImplementAllMethods() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method[] confMethods = Configuration.class.getDeclaredMethods(); Method[] delegateMethods = DelegatingConfiguration.class.getDeclaredMethods(); for (Method configurationMethod : confMethods) { if (!Modifier.isPublic(configurationMethod.getModifiers())) { continue; } boolean hasMethod = false; lookForWrapper: for (Method wrapperMethod : delegateMethods) { if (configurationMethod.getName().equals(wrapperMethod.getName())) { Class<?>[] wrapperMethodParams = wrapperMethod.getParameterTypes(); Class<?>[] configMethodParams = configurationMethod.getParameterTypes(); if (wrapperMethodParams.length != configMethodParams.length) { continue; } for (int i = 0; i < wrapperMethodParams.length; i++) { if (wrapperMethodParams[i] != configMethodParams[i]) { continue lookForWrapper; } } hasMethod = true; break; } } assertTrue("Configuration method '" + configurationMethod.getName() + "' has not been wrapped correctly in DelegatingConfiguration wrapper", hasMethod); } }
@Override public boolean equals(Object obj) { if (obj instanceof DelegatingConfiguration) { DelegatingConfiguration other = (DelegatingConfiguration) obj; return this.prefix.equals(other.prefix) && this.backingConfig.equals(other.backingConfig); } else { return false; } }
DelegatingConfiguration extends Configuration { @Override public boolean equals(Object obj) { if (obj instanceof DelegatingConfiguration) { DelegatingConfiguration other = (DelegatingConfiguration) obj; return this.prefix.equals(other.prefix) && this.backingConfig.equals(other.backingConfig); } else { return false; } } }
DelegatingConfiguration extends Configuration { @Override public boolean equals(Object obj) { if (obj instanceof DelegatingConfiguration) { DelegatingConfiguration other = (DelegatingConfiguration) obj; return this.prefix.equals(other.prefix) && this.backingConfig.equals(other.backingConfig); } else { return false; } } DelegatingConfiguration();  DelegatingConfiguration(Configuration backingConfig, String prefix); }
DelegatingConfiguration extends Configuration { @Override public boolean equals(Object obj) { if (obj instanceof DelegatingConfiguration) { DelegatingConfiguration other = (DelegatingConfiguration) obj; return this.prefix.equals(other.prefix) && this.backingConfig.equals(other.backingConfig); } else { return false; } } DelegatingConfiguration();  DelegatingConfiguration(Configuration backingConfig, String prefix); @Override String getString(String key, String defaultValue); @Override String getString(ConfigOption<String> configOption); @Override String getString(ConfigOption<String> configOption, String overrideDefault); @Override void setString(String key, String value); @Override void setString(ConfigOption<String> key, String value); @Override Class<T> getClass(String key, Class<? extends T> defaultValue, ClassLoader classLoader); @Override void setClass(String key, Class<?> klazz); @Override int getInteger(String key, int defaultValue); @Override int getInteger(ConfigOption<Integer> configOption); @Override int getInteger(ConfigOption<Integer> configOption, int overrideDefault); @Override void setInteger(String key, int value); @Override void setInteger(ConfigOption<Integer> key, int value); @Override long getLong(String key, long defaultValue); @Override long getLong(ConfigOption<Long> configOption); @Override long getLong(ConfigOption<Long> configOption, long overrideDefault); @Override void setLong(String key, long value); @Override void setLong(ConfigOption<Long> key, long value); @Override boolean getBoolean(String key, boolean defaultValue); @Override boolean getBoolean(ConfigOption<Boolean> configOption); @Override void setBoolean(String key, boolean value); @Override void setBoolean(ConfigOption<Boolean> key, boolean value); @Override boolean getBoolean(ConfigOption<Boolean> configOption, boolean overrideDefault); @Override float getFloat(String key, float defaultValue); @Override float getFloat(ConfigOption<Float> configOption); @Override float getFloat(ConfigOption<Float> configOption, float overrideDefault); @Override void setFloat(String key, float value); @Override void setFloat(ConfigOption<Float> key, float value); @Override double getDouble(String key, double defaultValue); @Override double getDouble(ConfigOption<Double> configOption); @Override double getDouble(ConfigOption<Double> configOption, double overrideDefault); @Override void setDouble(String key, double value); @Override void setDouble(ConfigOption<Double> key, double value); @Override byte[] getBytes(final String key, final byte[] defaultValue); @Override void setBytes(final String key, final byte[] bytes); @Override String getValue(ConfigOption<?> configOption); @Override T getEnum(final Class<T> enumClass, final ConfigOption<String> configOption); @Override void addAllToProperties(Properties props); @Override void addAll(Configuration other); @Override void addAll(Configuration other, String prefix); @Override String toString(); @Override Set<String> keySet(); @Override Configuration clone(); @Override Map<String, String> toMap(); @Override boolean removeConfig(ConfigOption<T> configOption); @Override boolean containsKey(String key); @Override boolean contains(ConfigOption<?> configOption); @Override void read(DataInputView in); @Override void write(DataOutputView out); @Override int hashCode(); @Override boolean equals(Object obj); }
DelegatingConfiguration extends Configuration { @Override public boolean equals(Object obj) { if (obj instanceof DelegatingConfiguration) { DelegatingConfiguration other = (DelegatingConfiguration) obj; return this.prefix.equals(other.prefix) && this.backingConfig.equals(other.backingConfig); } else { return false; } } DelegatingConfiguration();  DelegatingConfiguration(Configuration backingConfig, String prefix); @Override String getString(String key, String defaultValue); @Override String getString(ConfigOption<String> configOption); @Override String getString(ConfigOption<String> configOption, String overrideDefault); @Override void setString(String key, String value); @Override void setString(ConfigOption<String> key, String value); @Override Class<T> getClass(String key, Class<? extends T> defaultValue, ClassLoader classLoader); @Override void setClass(String key, Class<?> klazz); @Override int getInteger(String key, int defaultValue); @Override int getInteger(ConfigOption<Integer> configOption); @Override int getInteger(ConfigOption<Integer> configOption, int overrideDefault); @Override void setInteger(String key, int value); @Override void setInteger(ConfigOption<Integer> key, int value); @Override long getLong(String key, long defaultValue); @Override long getLong(ConfigOption<Long> configOption); @Override long getLong(ConfigOption<Long> configOption, long overrideDefault); @Override void setLong(String key, long value); @Override void setLong(ConfigOption<Long> key, long value); @Override boolean getBoolean(String key, boolean defaultValue); @Override boolean getBoolean(ConfigOption<Boolean> configOption); @Override void setBoolean(String key, boolean value); @Override void setBoolean(ConfigOption<Boolean> key, boolean value); @Override boolean getBoolean(ConfigOption<Boolean> configOption, boolean overrideDefault); @Override float getFloat(String key, float defaultValue); @Override float getFloat(ConfigOption<Float> configOption); @Override float getFloat(ConfigOption<Float> configOption, float overrideDefault); @Override void setFloat(String key, float value); @Override void setFloat(ConfigOption<Float> key, float value); @Override double getDouble(String key, double defaultValue); @Override double getDouble(ConfigOption<Double> configOption); @Override double getDouble(ConfigOption<Double> configOption, double overrideDefault); @Override void setDouble(String key, double value); @Override void setDouble(ConfigOption<Double> key, double value); @Override byte[] getBytes(final String key, final byte[] defaultValue); @Override void setBytes(final String key, final byte[] bytes); @Override String getValue(ConfigOption<?> configOption); @Override T getEnum(final Class<T> enumClass, final ConfigOption<String> configOption); @Override void addAllToProperties(Properties props); @Override void addAll(Configuration other); @Override void addAll(Configuration other, String prefix); @Override String toString(); @Override Set<String> keySet(); @Override Configuration clone(); @Override Map<String, String> toMap(); @Override boolean removeConfig(ConfigOption<T> configOption); @Override boolean containsKey(String key); @Override boolean contains(ConfigOption<?> configOption); @Override void read(DataInputView in); @Override void write(DataOutputView out); @Override int hashCode(); @Override boolean equals(Object obj);  }