formatting cleanup

This commit is contained in:
Eugen Paraschiv 2018-05-14 14:30:26 +03:00
parent dec95f5c25
commit 30552c8d0a
26 changed files with 93 additions and 127 deletions

View File

@ -9,9 +9,7 @@ public class AttrListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
servletContextEvent
.getServletContext()
.setAttribute("servlet-context-attr", "test");
servletContextEvent.getServletContext().setAttribute("servlet-context-attr", "test");
System.out.println("context init");
}

View File

@ -16,9 +16,7 @@ public class EchoServlet extends HttpServlet {
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) {
try {
Path path = File
.createTempFile("echo", "tmp")
.toPath();
Path path = File.createTempFile("echo", "tmp").toPath();
Files.copy(request.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
Files.copy(path, response.getOutputStream());
Files.delete(path);

View File

@ -18,9 +18,7 @@ public class HelloFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
servletResponse
.getOutputStream()
.print(filterConfig.getInitParameter("msg"));
servletResponse.getOutputStream().print(filterConfig.getInitParameter("msg"));
filterChain.doFilter(servletRequest, servletResponse);
}

View File

@ -21,9 +21,7 @@ public class HelloServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
response
.getOutputStream()
.write(servletConfig.getInitParameter("msg").getBytes());
response.getOutputStream().write(servletConfig.getInitParameter("msg").getBytes());
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -4,10 +4,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App
{
public static void main( String[] args )
{
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}

View File

@ -26,7 +26,6 @@ public class WebMvcConfigure extends WebMvcConfigurerAdapter {
configurer.enable();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/").setCachePeriod(3600).resourceChain(true).addResolver(new PathResourceResolver());

View File

@ -10,7 +10,8 @@ import org.springframework.core.env.ConfigurableEnvironment;
@Configuration
@ComponentScan(basePackages = { "com.baeldung.*" })
@PropertySource("classpath:custom.properties") public class PropertySourcesLoader {
@PropertySource("classpath:custom.properties")
public class PropertySourcesLoader {
private static final Logger log = LoggerFactory.getLogger(PropertySourcesLoader.class);

View File

@ -7,9 +7,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(name = "AnnotationServlet",
description = "Example Servlet Using Annotations",
urlPatterns = { "/annotationservlet" })
@WebServlet(name = "AnnotationServlet", description = "Example Servlet Using Annotations", urlPatterns = { "/annotationservlet" })
public class AnnotationServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

View File

@ -4,7 +4,6 @@ import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

View File

@ -2,7 +2,6 @@ package com.baeldung.webjar;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class WebjarsdemoApplication {

View File

@ -21,7 +21,6 @@ public class Foo implements Serializable {
this.name = name;
}
public Foo(Integer id, String name) {
super();
this.id = id;

View File

@ -22,7 +22,8 @@ import static org.junit.Assert.*;
@TestPropertySource(properties = { "security.basic.enabled=false" })
public class SpringBootWithServletComponentIntegrationTest {
@Autowired private ServletContext servletContext;
@Autowired
private ServletContext servletContext;
@Test
public void givenServletContext_whenAccessAttrs_thenFoundAttrsPutInServletListner() {
@ -37,12 +38,11 @@ public class SpringBootWithServletComponentIntegrationTest {
FilterRegistration filterRegistration = servletContext.getFilterRegistration("hello filter");
assertNotNull(filterRegistration);
assertTrue(filterRegistration
.getServletNameMappings()
.contains("echo servlet"));
assertTrue(filterRegistration.getServletNameMappings().contains("echo servlet"));
}
@Autowired private TestRestTemplate restTemplate;
@Autowired
private TestRestTemplate restTemplate;
@Test
public void givenServletFilter_whenGetHello_thenRequestFiltered() {
@ -58,8 +58,4 @@ public class SpringBootWithServletComponentIntegrationTest {
assertEquals("filtering echo", responseEntity.getBody());
}
}

View File

@ -22,9 +22,11 @@ import static org.junit.Assert.*;
@TestPropertySource(properties = { "security.basic.enabled=false" })
public class SpringBootWithoutServletComponentIntegrationTest {
@Autowired private ServletContext servletContext;
@Autowired
private ServletContext servletContext;
@Autowired private TestRestTemplate restTemplate;
@Autowired
private TestRestTemplate restTemplate;
@Test
public void givenServletContext_whenAccessAttrs_thenNotFound() {
@ -46,5 +48,3 @@ public class SpringBootWithoutServletComponentIntegrationTest {
}
}

View File

@ -26,16 +26,12 @@ public class AppLiveTest {
@Test
public void getIndex() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("Index Page")));
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(equalTo("Index Page")));
}
@Test
public void getLocal() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/local").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("/local")));
mvc.perform(MockMvcRequestBuilders.get("/local").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(equalTo("/local")));
}
}

View File

@ -10,7 +10,6 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.baeldung.utils.controller.UtilsController;
public class UtilsControllerIntegrationTest {
@ -23,19 +22,14 @@ public class UtilsControllerIntegrationTest {
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
this.mockMvc = MockMvcBuilders.standaloneSetup(utilsController)
.build();
this.mockMvc = MockMvcBuilders.standaloneSetup(utilsController).build();
}
@Test
public void givenParameter_setRequestParam_andSetSessionAttribute() throws Exception {
String param = "testparam";
this.mockMvc.perform(
post("/setParam")
.param("param", param)
.sessionAttr("parameter", param))
.andExpect(status().isOk());
this.mockMvc.perform(post("/setParam").param("param", param).sessionAttr("parameter", param)).andExpect(status().isOk());
}
}

View File

@ -9,8 +9,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.context.WebApplicationContext;
import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage;

View File

@ -23,9 +23,7 @@ import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
@RunWith(SpringRunner.class)
@SpringBootTest(
classes = DemoApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT)
@SpringBootTest(classes = DemoApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public class FooComponentIntegrationTest {
@Autowired

View File

@ -1,4 +1,5 @@
package org.baeldung.boot;
import java.util.HashMap;
import java.util.Map;
@ -22,7 +23,6 @@ public class FooIntegrationTest {
@Autowired
private TestRestTemplate testRestTemplate;
@Test
public void givenInquiryingFooWithId_whenIdIsValid_thenHttpStatusOK() {
Map<String, String> pathVariables = new HashMap<String, String>();

View File

@ -17,7 +17,6 @@ public class FooJsonIntegrationTest {
@Autowired
private JacksonTester<Foo> json;
@Test
public void testSerialize() throws Exception {
Foo foo = new Foo(3, "Foo_Name_3");