### Question:
BindingConfig extends AbstractConfig { public Binding bind(Exchange exchange, Queue queue) { if (ExchangeTypes.HEADERS.getValue().equals(exchange.getType()) && CollectionUtils.isEmpty(getArguments())) { throw new RabbitmqConfigurationException(String .format("Invalid Arguments : Arguments must be provided for a header exchange for binding {%s}", this)); } else if (StringUtils.isEmpty(getRoutingKey())) { throw new RabbitmqConfigurationException(String .format("Invalid RoutingKey : RoutingKey must be provided for a non header exchange for binding {%s}", this)); } return BindingBuilder.bind(queue).to(exchange).with(getRoutingKey()).and(getArguments()); }  @Override boolean validate(); Binding bind(Exchange exchange, Queue queue);  }### Answer:
@Test public void createBindingWithExchangeAndQueueTest() { Exchange bindingExchange = ExchangeConfig.builder().name(exchaneg).type(ExchangeTypes.DIRECT).build().buildExchange(ExchangeConfig.builder().build()); Queue bindingQueue = QueueConfig.builder().name(queue).build().buildQueue(QueueConfig.builder().build(), null); Binding binding = BindingConfig.builder().exchange(exchaneg).queue(queue).routingKey(routingKey).build().bind(bindingExchange, bindingQueue); expectedBindingConfig = BindingConfig.builder() .exchange(exchaneg).queue(queue).routingKey(routingKey).arguments(new HashMap<>()) .build(); assertBinding(binding, expectedBindingConfig); }
@Test public void createBindingWithHeaderExchangeAndArgumentsTest() { Exchange bindingExchange = ExchangeConfig.builder().name(exchaneg).type(ExchangeTypes.HEADERS).build().buildExchange(ExchangeConfig.builder().build()); Queue bindingQueue = QueueConfig.builder().name(queue).build().buildQueue(QueueConfig.builder().build(), null); BindingConfig bindingConfig = BindingConfig.builder().exchange(exchaneg).queue(queue).routingKey(routingKey).argument("key", "value").build(); Binding actualBinding = bindingConfig.bind(bindingExchange, bindingQueue); assertBinding(actualBinding, bindingConfig); }
@Test(expected = RabbitmqConfigurationException.class) public void createBindingWithHeaderExchangeAndNoArgumentsTest() { Exchange bindingExchange = ExchangeConfig.builder().name(exchaneg).type(ExchangeTypes.HEADERS).build().buildExchange(ExchangeConfig.builder().build()); Queue bindingQueue = QueueConfig.builder().name(queue).build().buildQueue(QueueConfig.builder().build(), null); BindingConfig bindingConfig = BindingConfig.builder().exchange(exchaneg).queue(queue).routingKey(routingKey).build(); bindingConfig.bind(bindingExchange, bindingQueue); }
@Test public void createBindingWithNonHeaderExchangeAndRoutingKeyTest() { Exchange bindingExchange = ExchangeConfig.builder().name(exchaneg).type(ExchangeTypes.DIRECT).build().buildExchange(ExchangeConfig.builder().build()); Queue bindingQueue = QueueConfig.builder().name(queue).build().buildQueue(QueueConfig.builder().build(), null); BindingConfig bindingConfig = BindingConfig.builder().exchange(exchaneg).queue(queue).routingKey(routingKey).build(); Binding actualBinding = bindingConfig.bind(bindingExchange, bindingQueue); assertBinding(actualBinding, bindingConfig); }
@Test(expected = RabbitmqConfigurationException.class) public void createBindingWithNonHeaderExchangeAndNoRoutingKeyTest() { Exchange bindingExchange = ExchangeConfig.builder().name(exchaneg).type(ExchangeTypes.DIRECT).build().buildExchange(ExchangeConfig.builder().build()); Queue bindingQueue = QueueConfig.builder().name(queue).build().buildQueue(QueueConfig.builder().build(), null); BindingConfig bindingConfig = BindingConfig.builder().exchange(exchaneg).queue(queue).routingKey(null).build(); bindingConfig.bind(bindingExchange, bindingQueue); }