From 73e3e356fa3b9607ffdecc37ed48895612f0f7d4 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 22 Oct 2023 22:15:40 -0700 Subject: [PATCH] Minor cleanup --- .idea/misc.xml | 19 ++++++++++ .../com/example/springboot/Application.java | 36 +++++++++---------- .../example/springboot/HelloController.java | 10 +++--- .../example/springboot/HelloControllerIT.java | 12 +++---- .../springboot/HelloControllerTest.java | 26 +++++++------- 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 8678395..dd3a644 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,23 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/example/springboot/Application.java b/src/main/java/com/example/springboot/Application.java index 42b3689..d8200b5 100644 --- a/src/main/java/com/example/springboot/Application.java +++ b/src/main/java/com/example/springboot/Application.java @@ -1,33 +1,29 @@ package com.example.springboot; -import java.util.Arrays; - import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; +import java.util.Arrays; + @SpringBootApplication public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - @Bean - public CommandLineRunner commandLineRunner(ApplicationContext ctx) { - return args -> { - - System.out.println("Let's inspect the beans provided by Spring Boot:"); - - String[] beanNames = ctx.getBeanDefinitionNames(); - Arrays.sort(beanNames); - for (String beanName : beanNames) { - System.out.println(beanName); - } - - }; - } + @Bean + public CommandLineRunner commandLineRunner(ApplicationContext ctx) { + return args -> { + System.out.println("Let's inspect the beans provided by Spring Boot:"); + String[] beanNames = ctx.getBeanDefinitionNames(); + Arrays.sort(beanNames); + for (String beanName : beanNames) { + System.out.println(beanName); + } + }; + } } diff --git a/src/main/java/com/example/springboot/HelloController.java b/src/main/java/com/example/springboot/HelloController.java index e4677a0..ac323f2 100644 --- a/src/main/java/com/example/springboot/HelloController.java +++ b/src/main/java/com/example/springboot/HelloController.java @@ -5,10 +5,8 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { - - @GetMapping("/") - public String index() { - return "Greetings from Spring Boot!"; - } - + @GetMapping("/") + public String index() { + return "Greetings from Spring Boot!"; + } } diff --git a/src/test/java/com/example/springboot/HelloControllerIT.java b/src/test/java/com/example/springboot/HelloControllerIT.java index 496700c..0d3ea5c 100644 --- a/src/test/java/com/example/springboot/HelloControllerIT.java +++ b/src/test/java/com/example/springboot/HelloControllerIT.java @@ -1,7 +1,6 @@ package com.example.springboot; import org.junit.jupiter.api.Test; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -11,17 +10,16 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class HelloControllerIT { + @Autowired + private TestRestTemplate template; - @Autowired - private TestRestTemplate template; + public static void main(String[] args) throws Exception { + new HelloControllerIT().getHello(); + } @Test public void getHello() throws Exception { ResponseEntity response = template.getForEntity("/", String.class); assertThat(response.getBody()).isEqualTo("Greetings from Spring Boot!"); } - - public static void main(String[] args) throws Exception { - new HelloControllerIT().getHello(); - } } diff --git a/src/test/java/com/example/springboot/HelloControllerTest.java b/src/test/java/com/example/springboot/HelloControllerTest.java index 81262f4..58f272d 100644 --- a/src/test/java/com/example/springboot/HelloControllerTest.java +++ b/src/test/java/com/example/springboot/HelloControllerTest.java @@ -1,11 +1,6 @@ package com.example.springboot; -import static org.hamcrest.Matchers.equalTo; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - import org.junit.jupiter.api.Test; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -13,17 +8,20 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import static org.hamcrest.Matchers.equalTo; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + @SpringBootTest @AutoConfigureMockMvc public class HelloControllerTest { + @Autowired + private MockMvc mvc; - @Autowired - private MockMvc mvc; - - @Test - public void getHello() throws Exception { - mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().string(equalTo("Greetings from Spring Boot!"))); - } + @Test + public void getHello() throws Exception { + mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(equalTo("Greetings from Spring Boot!"))); + } }