Buggy code:
private static final Charset UTF_8 = Charset . forName ( "UTF-8" ) ; private StompBrokerRelayMessageHandler relay ; private BrokerService activeMQBroker ; private ExecutorSubscribableChannel responseChannel ; private StompBrokerRelayMessageHandlerIntegrationTests . ExpectationMatchingMessageHandler responseHandler ; private StompBrokerRelayMessageHandlerIntegrationTests . ExpectationMatchingEventPublisher eventPublisher ; private int port ; @ Before public void setUp ( ) throws Exception { } private void startActiveMqBroker ( ) throws Exception { } private void createAndStartRelay ( ) throws InterruptedException { } @ After public void tearDown ( ) throws Exception { } private void stopActiveMqBrokerAndAwait ( ) throws Exception { } @ Test public void publishSubscribe ( ) throws Exception { } @ Test ( expected = MessageDeliveryException . class ) public void messageDeliverExceptionIfSystemSessionForwardFails ( ) throws Exception { } @ Test public void brokerBecomingUnvailableTriggersErrorFrame ( ) throws Exception { } @ Test public void brokerAvailabilityEventWhenStopped ( ) throws Exception { } @ Test public void relayReconnectsIfBrokerComesBackUp ( ) throws Exception { } @ Test public void disconnectClosesRelaySessionCleanly ( ) throws Exception { } private static class ExpectationMatchingMessageHandler implements MessageHandler { private final Object monitor = new Object ( ) ; private final List < StompBrokerRelayMessageHandlerIntegrationTests . MessageExchange > expected ; private final List < StompBrokerRelayMessageHandlerIntegrationTests . MessageExchange > actual = new ArrayList < > ( ) ; private final List < Message < ? > > unexpected = new ArrayList < > ( ) ; public ExpectationMatchingMessageHandler ( StompBrokerRelayMessageHandlerIntegrationTests . MessageExchange ... expected ) { } public void expect ( StompBrokerRelayMessageHandlerIntegrationTests . MessageExchange ... expected ) { } public void awaitAndAssert ( ) throws InterruptedException { long endTime = ( System . currentTimeMillis ( ) ) + 10000 ; synchronized ( this . monitor ) { while ( ( ! ( this . expected . isEmpty ( ) ) ) && ( ( System . currentTimeMillis ( ) ) < endTime ) ) { this . monitor . wait ( 500 ) ; } boolean result = this . expected . isEmpty ( ) ; assertTrue ( getAsString ( ) , ( result && ( this . unexpected . isEmpty ( ) ) ) ) ; } } @ Override public void handleMessage ( Message < ? > message ) throws MessagingException { } public String getAsString ( ) { } } private static class MessageExchange { private final Message < ? > message ; private final StompBrokerRelayMessageHandlerIntegrationTests . MessageMatcher [ ] expected ; private final Message < ? > [ ] actual ; public MessageExchange ( Message < ? > message , StompBrokerRelayMessageHandlerIntegrationTests . MessageMatcher ... expected ) { } public boolean isDone ( ) { } public boolean matchMessage ( Message < ? > message ) { } @ Override public String toString ( ) { } } private static class MessageExchangeBuilder { private final Message < ? > message ; private final StompHeaderAccessor headers ; private final List < StompBrokerRelayMessageHandlerIntegrationTests . MessageMatcher > expected = new ArrayList < > ( ) ; private MessageExchangeBuilder ( Message < ? > message ) { } public static StompBrokerRelayMessageHandlerIntegrationTests . MessageExchangeBuilder error ( String sessionId ) { } public static StompBrokerRelayMessageHandlerIntegrationTests . MessageExchangeBuilder connect ( String sessionId ) { } public static StompBrokerRelayMessageHandlerIntegrationTests . MessageExchangeBuilder connectWithError ( String sessionId ) { } public static StompBrokerRelayMessageHandlerIntegrationTests . MessageExchangeBuilder subscribeWithReceipt ( String sessionId , String subscriptionId , String destination , String receiptId ) { } public static StompBrokerRelayMessageHandlerIntegrationTests . MessageExchangeBuilder send ( String destination , String payload ) { } public StompBrokerRelayMessageHandlerIntegrationTests . MessageExchangeBuilder andExpectMessage ( String sessionId , String subscriptionId ) { } public StompBrokerRelayMessageHandlerIntegrationTests . MessageExchangeBuilder andExpectError ( ) { } public StompBrokerRelayMessageHandlerIntegrationTests . MessageExchangeBuilder andExpectError ( String sessionId ) { } public StompBrokerRelayMessageHandlerIntegrationTests . MessageExchange build ( ) { } } private static interface MessageMatcher { boolean match ( Message < ? > message ) { } } private static class StompFrameMessageMatcher implements StompBrokerRelayMessageHandlerIntegrationTests . MessageMatcher { private final StompCommand command ; private final String sessionId ; public StompFrameMessageMatcher ( StompCommand command , String sessionId ) { } @ Override public final boolean match ( Message < ? > message ) { } protected boolean matchInternal ( StompHeaderAccessor headers , Object payload ) { } @ Override public String toString ( ) { } } private static class StompReceiptFrameMessageMatcher extends StompBrokerRelayMessageHandlerIntegrationTests . StompFrameMessageMatcher { private final String receiptId ; public StompReceiptFrameMessageMatcher ( String sessionId , String receipt ) { } @ Override protected boolean matchInternal ( StompHeaderAccessor headers , Object payload ) { } @ Override public String toString ( ) { } } private static class StompMessageFrameMessageMatcher extends StompBrokerRelayMessageHandlerIntegrationTests . StompFrameMessageMatcher { private final String subscriptionId ; private final String destination ; private final Object payload ; public StompMessageFrameMessageMatcher ( String sessionId , String subscriptionId , String destination , Object payload ) { } @ Override protected boolean matchInternal ( StompHeaderAccessor headers , Object payload ) { } @ Override public String toString ( ) { } protected String getPayloadAsText ( ) { } } private static class StompConnectedFrameMessageMatcher extends StompBrokerRelayMessageHandlerIntegrationTests . StompFrameMessageMatcher { public StompConnectedFrameMessageMatcher ( String sessionId ) { } } private static class ExpectationMatchingEventPublisher implements ApplicationEventPublisher { private final List < Boolean > expected = new ArrayList < > ( ) ; private final List < Boolean > actual = new ArrayList < > ( ) ; private final Object monitor = new Object ( ) ; public void expectAvailabilityStatusChanges ( Boolean ... expected ) { } public void awaitAndAssert ( ) throws InterruptedException { synchronized ( this . monitor ) { <START_BUG> long endTime = ( System . currentTimeMillis ( ) ) + 10000 ; <END_BUG> while ( ( ( this . expected . size ( ) ) != ( this . actual . size ( ) ) ) && ( ( System . currentTimeMillis ( ) ) < endTime ) ) { this . monitor . wait ( 500 ) ; } assertEquals ( this . expected , this . actual ) ; } } @ Override public void publishEvent ( ApplicationEvent event ) { } } }

Fix:
long endTime = ( System . currentTimeMillis ( ) ) + 60000 ;