Polishing

This commit is contained in:
Sam Brannen
2019-03-06 14:21:58 +01:00
parent 777b4c809d
commit 7abe9c6a08
2 changed files with 28 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,18 +67,20 @@ import org.springframework.validation.Validator;
* protocols such as STOMP.
*
* <p>{@link #clientInboundChannel()} and {@link #clientOutboundChannel()} deliver
* messages to and from remote clients to several message handlers such as
* messages to and from remote clients to several message handlers such as the
* following.
* <ul>
* <li>{@link #simpAnnotationMethodMessageHandler()}</li>
* <li>{@link #simpleBrokerMessageHandler()}</li>
* <li>{@link #stompBrokerRelayMessageHandler()}</li>
* <li>{@link #userDestinationMessageHandler()}</li>
* </ul>
* while {@link #brokerChannel()} delivers messages from within the application to the
*
* <p>{@link #brokerChannel()} delivers messages from within the application to the
* the respective message handlers. {@link #brokerMessagingTemplate()} can be injected
* into any application component to send messages.
*
* <p>Subclasses are responsible for the part of the configuration that feed messages
* <p>Subclasses are responsible for the parts of the configuration that feed messages
* to and from the client inbound/outbound channels (e.g. STOMP over WebSocket).
*
* @author Rossen Stoyanchev
@@ -403,7 +405,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
* Override this method to add custom message converters.
* @param messageConverters the list to add converters to, initially empty
* @return {@code true} if default message converters should be added to list,
* {@code false} if no more converters should be added.
* {@code false} if no more converters should be added
*/
protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
return true;
@@ -448,9 +450,8 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
protected abstract SimpUserRegistry createLocalUserRegistry(@Nullable Integer order);
/**
* Return a {@link org.springframework.validation.Validator
* org.springframework.validation.Validators} instance for validating
* {@code @Payload} method arguments.
* Return an {@link org.springframework.validation.Validator} instance for
* validating {@code @Payload} method arguments.
* <p>In order, this method tries to get a Validator instance:
* <ul>
* <li>delegating to getValidator() first</li>

View File

@@ -23,7 +23,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -60,9 +60,7 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS;
/**
* Integration tests for {@link EventPublishingTestExecutionListener} and
@@ -88,11 +86,9 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
public final ExpectedException exception = ExpectedException.none();
@Before
public void resetMock() {
// The mocked listener is a bean in the ApplicationContext that is stored
// in a static cache by the Spring TestContext Framework.
reset(listener);
@After
public void closeApplicationContext() {
this.testContext.markApplicationContextDirty(null);
}
@Test
@@ -113,6 +109,12 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
verify(listener, only()).beforeTestMethod(testContext);
}
/**
* The {@code @BeforeTestMethod} condition in
* {@link TestEventListenerConfiguration#beforeTestMethod(BeforeTestMethodEvent)}
* only matches if the test method is annotated with {@code @Traceable}, and
* {@link ExampleTestCase#standardTest()} is not.
*/
@Test
public void beforeTestMethodAnnotationWithFailingCondition() throws Exception {
Method standardTest = ReflectionUtils.findMethod(ExampleTestCase.class, "standardTest");
@@ -120,6 +122,10 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
verify(listener, never()).beforeTestMethod(testContext);
}
/**
* An exception thrown from an event listener executed in the current thread
* should fail the test method.
*/
@Test
public void beforeTestMethodAnnotationWithFailingEventListener() throws Exception {
Method method = ReflectionUtils.findMethod(ExampleTestCase.class, "testWithFailingEventListener");
@@ -135,6 +141,10 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
}
}
/**
* An exception thrown from an event listener that is executed asynchronously
* should not fail the test method.
*/
@Test
public void beforeTestMethodAnnotationWithFailingAsyncEventListener() throws Exception {
TrackingAsyncUncaughtExceptionHandler.asyncException = null;
@@ -183,7 +193,7 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = TestEventListenerConfiguration.class)
@TestExecutionListeners(listeners = EventPublishingTestExecutionListener.class, mergeMode = MERGE_WITH_DEFAULTS)
@TestExecutionListeners(EventPublishingTestExecutionListener.class)
public static class ExampleTestCase {
@Traceable