TenantContextMessageInterceptor extends ChannelInterceptorAdapter { @Override public Message<?> postReceive(Message<?> message, MessageChannel messageChannel) { String tenant = message.getHeaders().get(this.headerName, String.class); this.logger.debug("Using tenant: {}", tenant); if (StringUtils.hasText(tenant)) { TenantContext context = TenantContextHolder.createEmptyContext(); context.setTenant(tenant); TenantContextHolder.setContext(context); } return message; }  @Override Message<?> preSend(Message<?> message, MessageChannel messageChannel); @Override Message<?> postReceive(Message<?> message, MessageChannel messageChannel); @Override void afterReceiveCompletion(Message<?> message, MessageChannel channel, Exception ex); void setHeaderName(String headerName);  }
@Test public void whenNoContextHeaderIsSetThenContextShouldNotBeSet() { this.interceptor.postReceive(this.message, null); assertThat(TenantContextHolder.getContext().getTenant(), is(nullValue())); }