@@ -0,0 +1,3035 @@
+/*%0A * Copyright 2010-2016 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.sambrannen.spring.events.web;%0A%0Aimport static java.util.Collections.singletonList;%0Aimport static org.hamcrest.Matchers.hasSize;%0Aimport static org.mockito.Mockito.when;%0Aimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;%0Aimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;%0Aimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;%0Aimport static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0A%0Aimport org.mockito.Mockito;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.context.annotation.Bean;%0Aimport org.springframework.context.annotation.ComponentScan;%0Aimport org.springframework.context.annotation.Configuration;%0Aimport org.springframework.test.context.ContextConfiguration;%0Aimport org.springframework.test.context.junit4.SpringJUnit4ClassRunner;%0Aimport org.springframework.test.context.web.WebAppConfiguration;%0Aimport org.springframework.test.web.servlet.MockMvc;%0Aimport org.springframework.web.context.WebApplicationContext;%0Aimport org.springframework.web.servlet.config.annotation.EnableWebMvc;%0A%0Aimport com.sambrannen.spring.events.domain.Event;%0Aimport com.sambrannen.spring.events.service.EventService;%0A%0A/**%0A * Integration tests for the %7B@link EventsController%7D with a manually%0A * mocked %7B@link EventService%7D using JUnit 4 and pre-Spring 4.3%0A * configuration mechanisms without Spring Boot.%0A *%0A * @author Sam Brannen%0A * @since 1.0%0A */%0A@RunWith(SpringJUnit4ClassRunner.class)%0A@WebAppConfiguration%0A@ContextConfiguration%0Apublic class EventsControllerWithManuallyMockedServiceTests %7B%0A%0A%09@Autowired%0A%09EventService eventService;%0A%0A%09@Autowired%0A%09WebApplicationContext wac;%0A%0A%09MockMvc mockMvc;%0A%0A%0A%09@Before%0A%09public void setUp() %7B%0A%09%09this.mockMvc = webAppContextSetup(wac).build();%0A%09%7D%0A%0A%09@Test%0A%09public void listEvents() throws Exception %7B%0A%09%09when(eventService.findAll()).thenReturn(singletonList(new Event(1L)));%0A%0A%09%09mockMvc.perform(get(%22/%22))//%0A%09%09%09%09.andExpect(view().name(%22event/list%22))//%0A%09%09%09%09.andExpect(model().attribute(%22events%22, hasSize(1)));%0A%09%7D%0A%0A%0A%09@Configuration%0A%09@EnableWebMvc%0A%09@ComponentScan(basePackageClasses = EventsController.class)%0A%09static class Config %7B%0A%0A%09%09@Bean%0A%09%09EventService eventService() %7B%0A%09%09%09return Mockito.mock(EventService.class);%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

Introduce EventsControllerWithManuallyMockedServiceTests