Skip to content

Commit f01d1e2

Browse files
authored
Build optimization (eugenp#2591)
1 parent 4589860 commit f01d1e2

9 files changed

Lines changed: 148 additions & 58 deletions

File tree

‎mustache/pom.xml‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,96 @@
7171
<groupId>org.springframework.boot</groupId>
7272
<artifactId>spring-boot-maven-plugin</artifactId>
7373
</plugin>
74+
<plugin>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<artifactId>maven-surefire-plugin</artifactId>
77+
<version>${maven-surefire-plugin.version}</version>
78+
<configuration>
79+
<forkCount>3</forkCount>
80+
<reuseForks>true</reuseForks>
81+
<excludes>
82+
<exclude>**/*IntegrationTest.java</exclude>
83+
<exclude>**/*LongRunningUnitTest.java</exclude>
84+
<exclude>**/*ManualTest.java</exclude>
85+
<exclude>**/JdbcTest.java</exclude>
86+
<exclude>**/*LiveTest.java</exclude>
87+
</excludes>
88+
<testFailureIgnore>true</testFailureIgnore>
89+
</configuration>
90+
</plugin>
7491
</plugins>
92+
7593
</build>
7694

95+
<profiles>
96+
<profile>
97+
<id>integration</id>
98+
<build>
99+
<plugins>
100+
<plugin>
101+
<groupId>org.apache.maven.plugins</groupId>
102+
<artifactId>maven-surefire-plugin</artifactId>
103+
<executions>
104+
<execution>
105+
<phase>integration-test</phase>
106+
<goals>
107+
<goal>test</goal>
108+
</goals>
109+
<configuration>
110+
<excludes>
111+
<exclude>**/*LiveTest.java</exclude>
112+
<exclude>**/AutoconfigurationTest.java</exclude>
113+
</excludes>
114+
<includes>
115+
<include>**/*IntegrationTest.java</include>
116+
</includes>
117+
</configuration>
118+
</execution>
119+
</executions>
120+
<configuration>
121+
<systemPropertyVariables>
122+
<test.mime>json</test.mime>
123+
</systemPropertyVariables>
124+
</configuration>
125+
</plugin>
126+
</plugins>
127+
</build>
128+
</profile>
129+
<profile>
130+
<id>autoconfiguration</id>
131+
<build>
132+
<plugins>
133+
<plugin>
134+
<groupId>org.apache.maven.plugins</groupId>
135+
<artifactId>maven-surefire-plugin</artifactId>
136+
<executions>
137+
<execution>
138+
<phase>integration-test</phase>
139+
<goals>
140+
<goal>test</goal>
141+
</goals>
142+
<configuration>
143+
<excludes>
144+
<exclude>**/*LiveTest.java</exclude>
145+
<exclude>**/*IntegrationTest.java</exclude>
146+
</excludes>
147+
<includes>
148+
<include>**/AutoconfigurationTest.java</include>
149+
</includes>
150+
</configuration>
151+
</execution>
152+
</executions>
153+
<configuration>
154+
<systemPropertyVariables>
155+
<test.mime>json</test.mime>
156+
</systemPropertyVariables>
157+
</configuration>
158+
</plugin>
159+
</plugins>
160+
</build>
161+
</profile>
162+
</profiles>
163+
77164
<properties>
78165
<mustache.compiler.api.version>0.9.2</mustache.compiler.api.version>
79166
<assertj.version>3.7.0</assertj.version>

‎mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceTest.java‎

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,98 @@
11
package com.baeldung.mustache;
22

3-
import static org.assertj.core.api.Assertions.assertThat;
3+
import com.baeldung.mustache.model.Todo;
4+
import com.github.mustachejava.Mustache;
5+
import org.junit.Test;
46

57
import java.io.IOException;
68
import java.io.StringWriter;
79
import java.time.Instant;
8-
import java.time.LocalDateTime;
9-
import java.time.temporal.TemporalUnit;
1010
import java.util.Arrays;
1111
import java.util.Date;
1212
import java.util.HashMap;
1313
import java.util.List;
1414
import java.util.Map;
15-
import java.util.function.Function;
1615

17-
import org.junit.Test;
16+
import static org.assertj.core.api.Assertions.assertThat;
1817

19-
import com.baeldung.mustache.model.Todo;
20-
import com.github.mustachejava.Mustache;
2118
public class TodoMustacheServiceTest {
2219

23-
private String executeTemplate(Mustache m, Map<String, Object> context) throws IOException{
20+
private String executeTemplate(Mustache m, Map<String, Object> context) throws IOException {
2421
StringWriter writer = new StringWriter();
2522
m.execute(writer, context).flush();
2623
return writer.toString();
2724
}
28-
29-
private String executeTemplate(Mustache m, Todo todo) throws IOException{
25+
26+
private String executeTemplate(Mustache m, Todo todo) throws IOException {
3027
StringWriter writer = new StringWriter();
3128
m.execute(writer, todo).flush();
3229
return writer.toString();
3330
}
34-
31+
3532
@Test
36-
public void givenTodoObject_whenGetHtml_thenSuccess() throws IOException{
33+
public void givenTodoObject_whenGetHtml_thenSuccess() throws IOException {
3734
Todo todo = new Todo("Todo 1", "Todo description");
3835
Mustache m = MustacheUtil.getMustacheFactory().compile("todo.mustache");
3936
Map<String, Object> context = new HashMap<>();
4037
context.put("todo", todo);
41-
38+
4239
String expected = "<h2>Todo 1</h2>";
4340
assertThat(executeTemplate(m, todo)).contains(expected);
4441
}
45-
42+
4643
@Test
47-
public void givenNullTodoObject_whenGetHtml_thenEmptyHtml() throws IOException{
44+
public void givenNullTodoObject_whenGetHtml_thenEmptyHtml() throws IOException {
4845
Mustache m = MustacheUtil.getMustacheFactory().compile("todo-section.mustache");
4946
Map<String, Object> context = new HashMap<>();
5047
assertThat(executeTemplate(m, context)).isEmpty();
5148
}
52-
49+
5350
@Test
54-
public void givenTodoList_whenGetHtml_thenSuccess() throws IOException{
51+
public void givenTodoList_whenGetHtml_thenSuccess() throws IOException {
5552
Mustache m = MustacheUtil.getMustacheFactory().compile("todos.mustache");
56-
53+
5754
List<Todo> todos = Arrays.asList(
58-
new Todo("Todo 1", "Todo description"),
59-
new Todo("Todo 2", "Todo description another"),
60-
new Todo("Todo 3", "Todo description another")
61-
);
55+
new Todo("Todo 1", "Todo description"),
56+
new Todo("Todo 2", "Todo description another"),
57+
new Todo("Todo 3", "Todo description another")
58+
);
6259
Map<String, Object> context = new HashMap<>();
6360
context.put("todos", todos);
64-
61+
6562
assertThat(executeTemplate(m, context))
6663
.contains("<h2>Todo 1</h2>")
6764
.contains("<h2>Todo 2</h2>")
6865
.contains("<h2>Todo 3</h2>");
6966
}
70-
67+
7168
@Test
72-
public void givenEmptyList_whenGetHtml_thenEmptyHtml() throws IOException{
69+
public void givenEmptyList_whenGetHtml_thenEmptyHtml() throws IOException {
7370
Mustache m = MustacheUtil.getMustacheFactory().compile("todos.mustache");
74-
71+
7572
Map<String, Object> context = new HashMap<>();
76-
assertThat(executeTemplate(m, context)).isEmpty();;
73+
assertThat(executeTemplate(m, context)).isEmpty();
74+
;
7775
}
78-
76+
7977
@Test
80-
public void givenEmptyList_whenGetHtmlUsingInvertedSection_thenHtml() throws IOException{
78+
public void givenEmptyList_whenGetHtmlUsingInvertedSection_thenHtml() throws IOException {
8179
Mustache m = MustacheUtil.getMustacheFactory().compile("todos-inverted-section.mustache");
82-
80+
8381
Map<String, Object> context = new HashMap<>();
8482
assertThat(executeTemplate(m, context).trim()).isEqualTo("<p>No todos!</p>");
8583
}
86-
84+
8785
@Test
88-
public void givenTodoList_whenGetHtmlUsingLamdba_thenHtml() throws IOException{
86+
public void givenTodoList_whenGetHtmlUsingLamdba_thenHtml() throws IOException {
8987
Mustache m = MustacheUtil.getMustacheFactory().compile("todos-lambda.mustache");
9088
List<Todo> todos = Arrays.asList(
91-
new Todo("Todo 1", "Todo description"),
92-
new Todo("Todo 2", "Todo description another"),
93-
new Todo("Todo 3", "Todo description another")
94-
);
89+
new Todo("Todo 1", "Todo description"),
90+
new Todo("Todo 2", "Todo description another"),
91+
new Todo("Todo 3", "Todo description another")
92+
);
9593
todos.get(2).setDone(true);
9694
todos.get(2).setCompletedOn(Date.from(Instant.now().plusSeconds(300)));
97-
95+
9896
Map<String, Object> context = new HashMap<>();
9997
context.put("todos", todos);
10098
assertThat(executeTemplate(m, context).trim()).contains("Done 5 minutes ago");

mustache/src/test/java/com/baeldung/springmustache/SpringMustacheApplicationTests.java renamed to mustache/src/test/java/com/baeldung/springmustache/SpringMustacheApplicationIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
@RunWith(SpringRunner.class)
1515
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
16-
public class SpringMustacheApplicationTests {
16+
public class SpringMustacheApplicationIntegrationTest {
1717

1818
@Autowired
1919
private TestRestTemplate restTemplate;

‎spring-mvc-java/src/main/java/com/baeldung/web/BeanA.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ public class BeanA {
1212
public BeanA() {
1313
super();
1414
}
15-
1615
}

‎spring-mvc-java/src/main/java/com/baeldung/web/BeanB.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ public class BeanB {
88
public BeanB() {
99
super();
1010
}
11-
1211
}

‎spring-rest-angular/pom.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<modelVersion>4.0.0</modelVersion>
66
<artifactId>spring-rest-angular</artifactId>
77
<name>spring-rest-angular</name>
8-
<groupId>com.baeldung</groupId>
98
<version>1.0</version>
109
<packaging>war</packaging>
1110

spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestUnitTest.java renamed to spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.baeldung.services.ExampleService;
44
import com.baeldung.transfer.LoginForm;
5+
import org.baeldung.web.main.Application;
56
import org.junit.Before;
67
import org.junit.Test;
78
import org.junit.runner.RunWith;
@@ -12,7 +13,6 @@
1213
import org.springframework.test.context.junit4.SpringRunner;
1314
import org.springframework.test.web.servlet.MockMvc;
1415
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
15-
import org.baeldung.web.main.Application;
1616

1717
import static org.mockito.Mockito.when;
1818
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
@@ -21,11 +21,14 @@
2121

2222
@RunWith(SpringRunner.class)
2323
@SpringBootTest(classes = Application.class)
24-
public class ExamplePostControllerRequestUnitTest {
24+
public class ExamplePostControllerRequestIntegrationTest {
2525

2626
MockMvc mockMvc;
27-
@Mock private ExampleService exampleService;
28-
@InjectMocks private ExamplePostController exampleController;
27+
@Mock
28+
private ExampleService exampleService;
29+
30+
@InjectMocks
31+
private ExamplePostController exampleController;
2932
private final String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}";
3033
private LoginForm lf = new LoginForm();
3134

spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseUnitTest.java renamed to spring-rest-angular/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.baeldung.services.ExampleService;
44
import com.baeldung.transfer.LoginForm;
5+
import org.baeldung.web.main.Application;
56
import org.junit.Before;
67
import org.junit.Test;
78
import org.junit.runner.RunWith;
@@ -10,7 +11,6 @@
1011
import org.mockito.MockitoAnnotations;
1112
import org.springframework.boot.test.context.SpringBootTest;
1213
import org.springframework.test.context.junit4.SpringRunner;
13-
import org.baeldung.web.main.Application;
1414
import org.springframework.test.web.servlet.MockMvc;
1515
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
1616

@@ -22,12 +22,16 @@
2222

2323
@RunWith(SpringRunner.class)
2424
@SpringBootTest(classes = Application.class)
25-
public class ExamplePostControllerResponseUnitTest {
25+
public class ExamplePostControllerResponseIntegrationTest {
26+
27+
private MockMvc mockMvc;
28+
29+
@Mock
30+
private ExampleService exampleService;
31+
32+
@InjectMocks
33+
private ExamplePostController exampleController;
2634

27-
MockMvc mockMvc;
28-
@Mock private ExampleService exampleService;
29-
@InjectMocks private ExamplePostController exampleController;
30-
private final String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}";
3135
private LoginForm lf = new LoginForm();
3236

3337
@Before
@@ -44,6 +48,7 @@ public void preTest() {
4448
public void requestBodyTest() {
4549
try {
4650
when(exampleService.fakeAuthenticate(lf)).thenReturn(true);
51+
String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}";
4752
mockMvc
4853
.perform(post("/post/response")
4954
.content(jsonBody)

‎spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceIntegrationTest.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package org.baeldung.web.service;
22

3-
import static io.restassured.RestAssured.given;
4-
import static org.hamcrest.core.Is.is;
5-
import static org.hamcrest.core.IsCollectionContaining.hasItems;
6-
import static org.hamcrest.core.IsEqual.equalTo;
7-
83
import org.apache.commons.lang3.RandomStringUtils;
94
import org.baeldung.web.main.Application;
105
import org.junit.Test;
@@ -13,6 +8,11 @@
138
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
149
import org.springframework.test.context.junit4.SpringRunner;
1510

11+
import static io.restassured.RestAssured.given;
12+
import static org.hamcrest.core.Is.is;
13+
import static org.hamcrest.core.IsCollectionContaining.hasItems;
14+
import static org.hamcrest.core.IsEqual.equalTo;
15+
1616
@RunWith(SpringRunner.class)
1717
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.DEFINED_PORT)
1818
public class StudentServiceIntegrationTest {
@@ -21,7 +21,8 @@ public class StudentServiceIntegrationTest {
2121

2222
@Test
2323
public void givenRequestForStudents_whenPageIsOne_expectContainsNames() {
24-
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("content.name", hasItems("Bryan", "Ben"));
24+
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat()
25+
.body("content.name", hasItems("Bryan", "Ben"));
2526
}
2627

2728
@Test
@@ -58,5 +59,4 @@ public void givenRequestForStudents_whenPageSizeIsFive_expectFiveItems() {
5859
public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources() {
5960
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("first", equalTo(true));
6061
}
61-
6262
}

0 commit comments

Comments
 (0)