### Question:
ExchangeConfig extends AbstractConfig { public ExchangeConfig applyDefaultConfig(ExchangeConfig defaultExchangeConfig) { log.debug("Applying DefaultExchangeConfig on the current ExchangeConfig :: ExchangeConfig = {{}} , DefaultExchangeConfig = {{}}", this, defaultExchangeConfig); setType(getDefaultConfig(getName(), "type", getType(), defaultExchangeConfig.getType(), ExchangeTypes.TOPIC)); setDurable(getDefaultConfig(getName(), "durable", getDurable(), defaultExchangeConfig.getDurable(), Boolean.FALSE)); setAutoDelete(getDefaultConfig(getName(), "autoDelete", getAutoDelete(), defaultExchangeConfig.getAutoDelete(), Boolean.FALSE)); setInternal(getDefaultConfig(getName(), "internal", getInternal(), defaultExchangeConfig.getInternal(), Boolean.FALSE)); setDelayed(getDefaultConfig(getName(), "delayed", getDelayed(), defaultExchangeConfig.getDelayed(), Boolean.FALSE)); setArguments(loadArguments(getArguments(), defaultExchangeConfig.getArguments())); setDefaultConfigApplied(true); log.info("DefaultExchangeConfig applied on the current ExchangeConfig :: ExchangeConfig = {{}} , DefaultExchangeConfig = {{}}", this, defaultExchangeConfig); return this; }  boolean validate(); ExchangeConfig applyDefaultConfig(ExchangeConfig defaultExchangeConfig); AbstractExchange buildExchange(ExchangeConfig defaultExchangeConfig);  }### Answer:
@Test public void defaultExchangeConfigWithDefaultConfigurationAppliedTest() { exchangeConfig = ExchangeConfig.builder().build().applyDefaultConfig(defaultExchangeConfig); expectedExchangeConfig = ExchangeConfig.builder().type(ExchangeTypes.TOPIC).durable(false).autoDelete(false).delayed(false).internal(false).build(); assertNull(exchangeConfig.getName()); assertThat(exchangeConfig.getType(), equalTo(ExchangeTypes.TOPIC)); assertFalse(exchangeConfig.getDurable()); assertFalse(exchangeConfig.getAutoDelete()); assertFalse(exchangeConfig.getDelayed()); assertFalse(exchangeConfig.getInternal()); assertNotNull(exchangeConfig.getArguments()); assertTrue(exchangeConfig.isDefaultConfigApplied()); assertTrue(CollectionUtils.isEmpty(exchangeConfig.getArguments())); assertThat(exchangeConfig, equalTo(expectedExchangeConfig)); }
@Test public void exchangeConfigWithOnlyExchangeNameAndDefaultConfigurationAppliedTest() { exchangeConfig = ExchangeConfig.builder().name(exchangeName).build().applyDefaultConfig(defaultExchangeConfig); expectedExchangeConfig = ExchangeConfig.builder().name(exchangeName).type(ExchangeTypes.TOPIC).durable(false).autoDelete(false).delayed(false).internal(false).build(); assertThat(exchangeConfig, equalTo(expectedExchangeConfig)); }
@Test public void exchangeConfigWithOnlyExchangeNameAndFewDefaultConfigurationTest() { defaultExchangeConfig = ExchangeConfig.builder() .type(ExchangeTypes.HEADERS).durable(true).autoDelete(true).delayed(true).internal(true).argument("key1", "value1") .build(); exchangeConfig = ExchangeConfig.builder() .name(exchangeName) .build() .applyDefaultConfig(defaultExchangeConfig); expectedExchangeConfig = ExchangeConfig.builder() .name(exchangeName).type(ExchangeTypes.HEADERS).durable(true).autoDelete(true).delayed(true).internal(true) .argument("key1", "value1") .build(); assertThat(exchangeConfig, equalTo(expectedExchangeConfig)); }
@Test public void exchangeConfigByOverriddingFromDefaultConfigurationTest() { defaultExchangeConfig = ExchangeConfig.builder() .type(ExchangeTypes.HEADERS).durable(true).autoDelete(true).delayed(true).internal(true).argument("key1", "value1") .build(); exchangeConfig = ExchangeConfig.builder() .name(exchangeName).type(ExchangeTypes.FANOUT).durable(false).autoDelete(false) .argument("key1", "NEW_VALUE").argument("key2", "value2") .build() .applyDefaultConfig(defaultExchangeConfig); expectedExchangeConfig = ExchangeConfig.builder() .name(exchangeName).type(ExchangeTypes.FANOUT).durable(false).autoDelete(false).delayed(true).internal(true) .argument("key1", "NEW_VALUE").argument("key2", "value2") .build(); assertThat(exchangeConfig, equalTo(expectedExchangeConfig)); }