From f01d1e257e8ec3174d9cd1ce53ba5f40c28c716c Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 9 Sep 2017 16:55:05 +0200 Subject: [PATCH] Build optimization (#2591) --- mustache/pom.xml | 87 +++++++++++++++++++ .../mustache/TodoMustacheServiceTest.java | 72 ++++++++------- ...ngMustacheApplicationIntegrationTest.java} | 2 +- .../src/main/java/com/baeldung/web/BeanA.java | 1 - .../src/main/java/com/baeldung/web/BeanB.java | 1 - spring-rest-angular/pom.xml | 1 - ...PostControllerRequestIntegrationTest.java} | 11 ++- ...ostControllerResponseIntegrationTest.java} | 17 ++-- .../StudentServiceIntegrationTest.java | 14 +-- 9 files changed, 148 insertions(+), 58 deletions(-) rename mustache/src/test/java/com/baeldung/springmustache/{SpringMustacheApplicationTests.java => SpringMustacheApplicationIntegrationTest.java} (94%) rename spring-rest-angular/src/test/java/com/baeldung/controllers/{ExamplePostControllerRequestUnitTest.java => ExamplePostControllerRequestIntegrationTest.java} (90%) rename spring-rest-angular/src/test/java/com/baeldung/controllers/{ExamplePostControllerResponseUnitTest.java => ExamplePostControllerResponseIntegrationTest.java} (86%) diff --git a/mustache/pom.xml b/mustache/pom.xml index 15c0e3a8c7..8aab038313 100644 --- a/mustache/pom.xml +++ b/mustache/pom.xml @@ -71,9 +71,96 @@ org.springframework.boot spring-boot-maven-plugin + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + 3 + true + + **/*IntegrationTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/JdbcTest.java + **/*LiveTest.java + + true + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + **/AutoconfigurationTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + autoconfiguration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + **/*IntegrationTest.java + + + **/AutoconfigurationTest.java + + + + + + + json + + + + + + + + 0.9.2 3.7.0 diff --git a/mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceTest.java b/mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceTest.java index 17a59aa6a1..0df2f7f8a4 100644 --- a/mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceTest.java +++ b/mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceTest.java @@ -1,100 +1,98 @@ package com.baeldung.mustache; -import static org.assertj.core.api.Assertions.assertThat; +import com.baeldung.mustache.model.Todo; +import com.github.mustachejava.Mustache; +import org.junit.Test; import java.io.IOException; import java.io.StringWriter; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.temporal.TemporalUnit; import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Function; -import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; -import com.baeldung.mustache.model.Todo; -import com.github.mustachejava.Mustache; public class TodoMustacheServiceTest { - private String executeTemplate(Mustache m, Map context) throws IOException{ + private String executeTemplate(Mustache m, Map context) throws IOException { StringWriter writer = new StringWriter(); m.execute(writer, context).flush(); return writer.toString(); } - - private String executeTemplate(Mustache m, Todo todo) throws IOException{ + + private String executeTemplate(Mustache m, Todo todo) throws IOException { StringWriter writer = new StringWriter(); m.execute(writer, todo).flush(); return writer.toString(); } - + @Test - public void givenTodoObject_whenGetHtml_thenSuccess() throws IOException{ + public void givenTodoObject_whenGetHtml_thenSuccess() throws IOException { Todo todo = new Todo("Todo 1", "Todo description"); Mustache m = MustacheUtil.getMustacheFactory().compile("todo.mustache"); Map context = new HashMap<>(); context.put("todo", todo); - + String expected = "

Todo 1

"; assertThat(executeTemplate(m, todo)).contains(expected); } - + @Test - public void givenNullTodoObject_whenGetHtml_thenEmptyHtml() throws IOException{ + public void givenNullTodoObject_whenGetHtml_thenEmptyHtml() throws IOException { Mustache m = MustacheUtil.getMustacheFactory().compile("todo-section.mustache"); Map context = new HashMap<>(); assertThat(executeTemplate(m, context)).isEmpty(); } - + @Test - public void givenTodoList_whenGetHtml_thenSuccess() throws IOException{ + public void givenTodoList_whenGetHtml_thenSuccess() throws IOException { Mustache m = MustacheUtil.getMustacheFactory().compile("todos.mustache"); - + List todos = Arrays.asList( - new Todo("Todo 1", "Todo description"), - new Todo("Todo 2", "Todo description another"), - new Todo("Todo 3", "Todo description another") - ); + new Todo("Todo 1", "Todo description"), + new Todo("Todo 2", "Todo description another"), + new Todo("Todo 3", "Todo description another") + ); Map context = new HashMap<>(); context.put("todos", todos); - + assertThat(executeTemplate(m, context)) .contains("

Todo 1

") .contains("

Todo 2

") .contains("

Todo 3

"); } - + @Test - public void givenEmptyList_whenGetHtml_thenEmptyHtml() throws IOException{ + public void givenEmptyList_whenGetHtml_thenEmptyHtml() throws IOException { Mustache m = MustacheUtil.getMustacheFactory().compile("todos.mustache"); - + Map context = new HashMap<>(); - assertThat(executeTemplate(m, context)).isEmpty();; + assertThat(executeTemplate(m, context)).isEmpty(); + ; } - + @Test - public void givenEmptyList_whenGetHtmlUsingInvertedSection_thenHtml() throws IOException{ + public void givenEmptyList_whenGetHtmlUsingInvertedSection_thenHtml() throws IOException { Mustache m = MustacheUtil.getMustacheFactory().compile("todos-inverted-section.mustache"); - + Map context = new HashMap<>(); assertThat(executeTemplate(m, context).trim()).isEqualTo("

No todos!

"); } - + @Test - public void givenTodoList_whenGetHtmlUsingLamdba_thenHtml() throws IOException{ + public void givenTodoList_whenGetHtmlUsingLamdba_thenHtml() throws IOException { Mustache m = MustacheUtil.getMustacheFactory().compile("todos-lambda.mustache"); List todos = Arrays.asList( - new Todo("Todo 1", "Todo description"), - new Todo("Todo 2", "Todo description another"), - new Todo("Todo 3", "Todo description another") - ); + new Todo("Todo 1", "Todo description"), + new Todo("Todo 2", "Todo description another"), + new Todo("Todo 3", "Todo description another") + ); todos.get(2).setDone(true); todos.get(2).setCompletedOn(Date.from(Instant.now().plusSeconds(300))); - + Map context = new HashMap<>(); context.put("todos", todos); assertThat(executeTemplate(m, context).trim()).contains("Done 5 minutes ago"); diff --git a/mustache/src/test/java/com/baeldung/springmustache/SpringMustacheApplicationTests.java b/mustache/src/test/java/com/baeldung/springmustache/SpringMustacheApplicationIntegrationTest.java similarity index 94% rename from mustache/src/test/java/com/baeldung/springmustache/SpringMustacheApplicationTests.java rename to mustache/src/test/java/com/baeldung/springmustache/SpringMustacheApplicationIntegrationTest.java index 9138dfe92b..1eecf58986 100644 --- a/mustache/src/test/java/com/baeldung/springmustache/SpringMustacheApplicationTests.java +++ b/mustache/src/test/java/com/baeldung/springmustache/SpringMustacheApplicationIntegrationTest.java @@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class SpringMustacheApplicationTests { +public class SpringMustacheApplicationIntegrationTest { @Autowired private TestRestTemplate restTemplate; diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java b/spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java index 79fac724f7..60da29f354 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java +++ b/spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java @@ -12,5 +12,4 @@ public class BeanA { public BeanA() { super(); } - } diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java b/spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java index 05c9560a0c..9e713d59ab 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java +++ b/spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java @@ -8,5 +8,4 @@ public class BeanB { public BeanB() { super(); } - } diff --git a/spring-rest-angular/pom.xml b/spring-rest-angular/pom.xml index 0562e3ad58..3fc429f626 100644 --- a/spring-rest-angular/pom.xml +++ b/spring-rest-angular/pom.xml @@ -5,7 +5,6 @@ 4.0.0 spring-rest-angular spring-rest-angular - com.baeldung 1.0 war diff --git a/spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestUnitTest.java b/spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java similarity index 90% rename from spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestUnitTest.java rename to spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java index 00a2685c53..3d0934f842 100644 --- a/spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestUnitTest.java +++ b/spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java @@ -2,6 +2,7 @@ package com.baeldung.controllers; import com.baeldung.services.ExampleService; import com.baeldung.transfer.LoginForm; +import org.baeldung.web.main.Application; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -12,7 +13,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.baeldung.web.main.Application; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -21,11 +21,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) -public class ExamplePostControllerRequestUnitTest { +public class ExamplePostControllerRequestIntegrationTest { MockMvc mockMvc; - @Mock private ExampleService exampleService; - @InjectMocks private ExamplePostController exampleController; + @Mock + private ExampleService exampleService; + + @InjectMocks + private ExamplePostController exampleController; private final String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}"; private LoginForm lf = new LoginForm(); diff --git a/spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseUnitTest.java b/spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java similarity index 86% rename from spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseUnitTest.java rename to spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java index 585cec015f..0794edad6f 100644 --- a/spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseUnitTest.java +++ b/spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java @@ -2,6 +2,7 @@ package com.baeldung.controllers; import com.baeldung.services.ExampleService; import com.baeldung.transfer.LoginForm; +import org.baeldung.web.main.Application; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -10,7 +11,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import org.baeldung.web.main.Application; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -22,12 +22,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) -public class ExamplePostControllerResponseUnitTest { +public class ExamplePostControllerResponseIntegrationTest { + + private MockMvc mockMvc; + + @Mock + private ExampleService exampleService; + + @InjectMocks + private ExamplePostController exampleController; - MockMvc mockMvc; - @Mock private ExampleService exampleService; - @InjectMocks private ExamplePostController exampleController; - private final String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}"; private LoginForm lf = new LoginForm(); @Before @@ -44,6 +48,7 @@ public class ExamplePostControllerResponseUnitTest { public void requestBodyTest() { try { when(exampleService.fakeAuthenticate(lf)).thenReturn(true); + String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}"; mockMvc .perform(post("/post/response") .content(jsonBody) diff --git a/spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceIntegrationTest.java b/spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceIntegrationTest.java index 48c985fb9d..4d65c02fff 100644 --- a/spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceIntegrationTest.java +++ b/spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceIntegrationTest.java @@ -1,10 +1,5 @@ package org.baeldung.web.service; -import static io.restassured.RestAssured.given; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsCollectionContaining.hasItems; -import static org.hamcrest.core.IsEqual.equalTo; - import org.apache.commons.lang3.RandomStringUtils; import org.baeldung.web.main.Application; import org.junit.Test; @@ -13,6 +8,11 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.test.context.junit4.SpringRunner; +import static io.restassured.RestAssured.given; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsCollectionContaining.hasItems; +import static org.hamcrest.core.IsEqual.equalTo; + @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.DEFINED_PORT) public class StudentServiceIntegrationTest { @@ -21,7 +21,8 @@ public class StudentServiceIntegrationTest { @Test public void givenRequestForStudents_whenPageIsOne_expectContainsNames() { - given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("content.name", hasItems("Bryan", "Ben")); + given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat() + .body("content.name", hasItems("Bryan", "Ben")); } @Test @@ -58,5 +59,4 @@ public class StudentServiceIntegrationTest { public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources() { given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("first", equalTo(true)); } - }