From 5ab072be9c04e61beb782d1ba511efe16d4e6ecf Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 8 Jun 2016 09:27:40 -0700 Subject: [PATCH] Polish --- ...AdvancedConfigurationIntegrationTests.java | 4 +++- .../boot/SpringApplicationTests.java | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java index 81af9674ce8..52cf0bc984a 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java @@ -41,6 +41,8 @@ import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.li import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; /** + * Tests for {@link AutoConfigureRestDocs}. + * * @author Andy Wilkinson */ @RunWith(SpringRunner.class) @@ -61,7 +63,7 @@ public class RestDocsAutoConfigurationAdvancedConfigurationIntegrationTests { @Test public void snippetGeneration() throws Exception { - this.document.snippets(links( + this.document.document(links( linkWithRel("self").description("Canonical location of this resource"))); this.mvc.perform(get("/")); File defaultSnippetsDir = new File( diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 2ebbad2f861..7271bd0a11e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -682,20 +682,17 @@ public class SpringApplicationTests { application.setApplicationContextClass(SpyApplicationContext.class); final LinkedHashSet events = new LinkedHashSet(); application.addListeners(new ApplicationListener() { + @Override public void onApplicationEvent(ApplicationEvent event) { events.add(event); } + }); this.context = application.run(); assertThat(events).hasAtLeastOneElementOfType(ApplicationPreparedEvent.class); assertThat(events).hasAtLeastOneElementOfType(ContextRefreshedEvent.class); - - ApplicationListener listener = this.context.getBean( - "testApplicationListener", ApplicationListener.class); - verify(listener).onApplicationEvent(argThat(isA(ContextRefreshedEvent.class))); - verify(listener).onApplicationEvent(argThat(isA(ApplicationReadyEvent.class))); - verifyNoMoreInteractions(listener); + verifyTestListenerEvents(); } @Test @@ -705,17 +702,23 @@ public class SpringApplicationTests { application.setApplicationContextClass(SpyApplicationContext.class); final LinkedHashSet events = new LinkedHashSet(); application.addListeners(new ApplicationListener() { + @Override public void onApplicationEvent(ApplicationEvent event) { events.add(event); } + }); this.context = application.run(); assertThat(events).hasAtLeastOneElementOfType(ApplicationPreparedEvent.class); assertThat(events).hasAtLeastOneElementOfType(ContextRefreshedEvent.class); + verifyTestListenerEvents(); + } - ApplicationListener listener = this.context.getBean( - "testApplicationListener", ApplicationListener.class); + @SuppressWarnings("unchecked") + private void verifyTestListenerEvents() { + ApplicationListener listener = this.context + .getBean("testApplicationListener", ApplicationListener.class); verify(listener).onApplicationEvent(argThat(isA(ContextRefreshedEvent.class))); verify(listener).onApplicationEvent(argThat(isA(ApplicationReadyEvent.class))); verifyNoMoreInteractions(listener);