Skip to content

Commit 0048ff3

Browse files
authored
v1.4.2
1 parent 13b9711 commit 0048ff3

File tree

4 files changed

+63
-112
lines changed

4 files changed

+63
-112
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
# Changelog
44

5+
## [1.4.2]
6+
7+
### Upgraded
8+
9+
- spring-boot 3.4.4 → 3.4.5
10+
11+
---
12+
513
## [1.4.1]
614

715
### Upgraded
@@ -24,6 +32,8 @@
2432
- `answerAsMap(Class<K> keyType, Class<V> valueType)` now returns `null` instead of throwing
2533
a `MismatchedInputException` when the HTTP response is `null`.
2634

35+
---
36+
2737
## [1.4.0]
2838

2939
### Added

README.md

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
## Overview
1818

19-
This project provides a framework for structuring unit tests following the AAA (Arrange, Act,
20-
Assert) pattern with a focus on clarity and readability. The library offers a fluent API that guides
21-
the developer through each phase, ensuring that only contextually relevant methods are available at
22-
each step. This design choice enhances the ease of writing, maintaining, and understanding tests.
23-
The key goal is to provide a clean separation of concerns within the test, allowing developers to
24-
express their test logic fluently and naturally.
19+
A fluent testing framework for Spring's MockMvc that enforces the Arrange-Act-Assert (AAA)
20+
pattern and reduces boilerplate in controller tests.
21+
The library guides developers through each testing phase with a strongly-typed,
22+
step-by-step API, ensuring a consistent and intuitive test structure. Common tasks such as
23+
request setup, ObjectMapper-based serialization, and response assertions are fully abstracted,
24+
allowing developers to focus on the test logic itself rather than technical overhead.
25+
26+
<img src="images/aaa-mockmvc-example1.png" alt="aaa-mockmvc-example"/>
2527

2628
___
2729

@@ -38,15 +40,15 @@ ___
3840
## Installation
3941

4042
To include AAAMockMvc in the project, add the following dependency to the `pom.xml`.
41-
The sources can also be downloaded directly within the IDE (e.g., IntelliJ IDEA) to access the
43+
The sources can also be downloaded directly within the IDE (e.g. IntelliJ IDEA) to access the
4244
documentation of the classes.
4345

4446
```xml
4547

4648
<dependency>
4749
<groupId>io.github.co-mmer</groupId>
4850
<artifactId>aaa-mockmvc</artifactId>
49-
<version>1.4.1</version>
51+
<version>1.4.2</version>
5052
<scope>test</scope>
5153
</dependency>
5254

@@ -109,7 +111,7 @@ to `AAAMockMvc`.
109111
public class AAAMockMvcConfig {
110112

111113
@Bean
112-
AAAMockMvc aaaMockMvc(WebApplicationContext context, ObjectMapper objectMapper) {
114+
public AAAMockMvc aaaMockMvc(WebApplicationContext context, ObjectMapper objectMapper) {
113115
return new AAAMockMvc(context, objectMapper);
114116
}
115117

@@ -141,7 +143,7 @@ The framework will use a default ObjectMapper (`new ObjectMapper()`).
141143
public class AAAMockMvcConfig {
142144

143145
@Bean
144-
AAAMockMvc aaaMockMvc(MockMvc mockMvc) {
146+
public AAAMockMvc aaaMockMvc(MockMvc mockMvc) {
145147
return new AAAMockMvc(mockMvc);
146148
}
147149

@@ -177,7 +179,7 @@ specific configurations.
177179
public class AAAMockMvcConfig {
178180

179181
@Bean
180-
AAAMockMvc aaaMockMvc(WebApplicationContext context, ObjectMapper objectMapper) {
182+
public AAAMockMvc aaaMockMvc(WebApplicationContext context, ObjectMapper objectMapper) {
181183
return new AAAMockMvc(context, objectMapper);
182184
}
183185

@@ -304,22 +306,18 @@ In the provided library, every test follows the AAA structure using the followin
304306

305307
## Example
306308

307-
- [Registration Scenario](#registration-scenario)
308-
- [Test Implementation](#test-implementation)
309-
310-
This example demonstrates a typical registration process, where the user's email address must first
309+
This example demonstrates a registration process, where the user's email address must first
311310
be verified by sending a code. After the email verification, the user can proceed with the
312-
registration, including providing the verification code.
313-
314-
The process is split into two main steps:
311+
registration, including providing the verification code. The process is split into two main steps:
315312

316313
1. **Email Verification**: A verification code is sent to the provided email address.
317314
2. **Registration**: After receiving the verification code, the user sends it back to the backend
318315
for validation, allowing them to complete their registration.
319316

320-
Below are the necessary code snippets to represent this scenario:
317+
### Main Code
321318

322-
## Registration Scenario
319+
<details>
320+
<summary>Implementation of Registration Scenario</summary>
323321

324322
### 1. Verification Response Model
325323

@@ -414,22 +412,19 @@ public class RegistrationController {
414412

415413
```
416414

417-
## Test Implementation
415+
</details>
418416

419-
The table below shows the same test scenario written in two different ways. On the left side, the
420-
test is written using **MockMvc**, which is the traditional way to perform HTTP tests in Spring. On
421-
the right side, the same test is written using the **AAA-Mock** framework, which is an open-source
422-
testing framework designed to make the test code more readable and concise.
417+
### Test Code
423418

424-
It is important to note that in both examples, the use of helper private methods has been
425-
intentionally avoided to keep the tests straightforward and focused on the core testing logic. This
426-
ensures clarity and helps demonstrate the difference between the two testing approaches.
419+
The following examples demonstrate the same test scenario written in two different ways. First, the
420+
test is implemented using MockMvc, the traditional approach for performing HTTP tests in Spring.
421+
This is followed by the same test written with AAAMockMvc.
427422

428-
<table>
429-
<tr>
430-
<td>
423+
To keep the tests straightforward and focused on the core testing logic, the use of private helper
424+
methods has been intentionally avoided. This ensures clarity and helps highlight the differences
425+
between the two testing approaches.
431426

432-
**Test with MockMvc**
427+
### Test with MockMvc
433428

434429
```java
435430

@@ -441,24 +436,25 @@ private ObjectMapper objectMapper;
441436

442437
@Test
443438
@SneakyThrows
444-
void GIVEN_registration_with_valid_verification_WHEN_createRegistration_THEN_return_status_201() {
439+
void GIVEN_valid_code_WHEN_registration_THEN_status_201() {
445440

446441
var verificationRequest = VerificationRequest.builder()
447442
.firstname(FIRSTNAME)
448443
.lastname(LASTNAME)
449444
.mail(EMAIL)
450445
.build();
451446

452-
var verificationResponseJson = mockMvc.perform(
453-
MockMvcRequestBuilders.post(POST_CREATE_VERIFICATION)
454-
.contentType(MediaType.APPLICATION_JSON)
455-
.content(objectMapper.writeValueAsString(verificationRequest)))
447+
var content = MockMvcRequestBuilders.post(SEND_MAIL_VERIFICATION)
448+
.contentType(MediaType.APPLICATION_JSON)
449+
.content(objectMapper.writeValueAsString(verificationRequest));
450+
451+
var verificationResponseJson = mockMvc.perform(content)
456452
.andReturn()
457453
.getResponse()
458454
.getContentAsString();
459455

460-
var verificationResponse = objectMapper.readValue(verificationResponseJson,
461-
VerificationResponse.class);
456+
var verificationResponse = objectMapper.readValue(
457+
verificationResponseJson, VerificationResponse.class);
462458

463459
var registrationRequest = RegistrationRequest.builder()
464460
.verification(VerificationResponse.builder()
@@ -468,24 +464,22 @@ void GIVEN_registration_with_valid_verification_WHEN_createRegistration_THEN_ret
468464
.build())
469465
.build();
470466

471-
mockMvc.perform(MockMvcRequestBuilders.post(POST_CREATE_REGISTRATION)
472-
.contentType(MediaType.APPLICATION_JSON)
473-
.content(objectMapper.writeValueAsString(registrationRequest)))
474-
.andExpect(status().isCreated());
467+
content = MockMvcRequestBuilders.post(POST_CREATE_REGISTRATION)
468+
.contentType(MediaType.APPLICATION_JSON)
469+
.content(objectMapper.writeValueAsString(registrationRequest));
470+
471+
mockMvc.perform(content).andExpect(status().isCreated());
475472
}
476473

477474
```
478475

479-
</td>
480-
<td>
481-
482-
**Test with AAA-MockMvc**
476+
### Test with AAAMockMvc
483477

484478
```java
485479

486480
@Test
487481
@SneakyThrows
488-
void GIVEN_registration_with_valid_verification_WHEN_createRegistration_THEN_return_status_201() {
482+
void GIVEN_valid_code_WHEN_registration_THEN_status_201() {
489483

490484
var verificationRequest = VerificationRequest.builder()
491485
.firstname(FIRSTNAME)
@@ -495,7 +489,7 @@ void GIVEN_registration_with_valid_verification_WHEN_createRegistration_THEN_ret
495489

496490
var verificationResponse = post()
497491
.arrange()
498-
.arrangeUrl(POST_CREATE_VERIFICATION)
492+
.arrangeUrl(SEND_VERIFICATION)
499493
.arrangeBody()
500494
.arrangeJson(verificationRequest)
501495
.act()
@@ -514,7 +508,7 @@ void GIVEN_registration_with_valid_verification_WHEN_createRegistration_THEN_ret
514508

515509
post()
516510
.arrange()
517-
.arrangeUrl(POST_CREATE_REGISTRATION)
511+
.arrangeUrl(CREATE_REGISTRATION)
518512
.arrangeBody()
519513
.arrangeJson(registrationRequest)
520514
.act()
@@ -526,10 +520,6 @@ void GIVEN_registration_with_valid_verification_WHEN_createRegistration_THEN_ret
526520

527521
```
528522

529-
</td>
530-
</tr>
531-
</table>
532-
533523
---
534524

535525
## License

images/aaa-mockmvc-example1.png

135 KB
Loading

pom.xml

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
<groupId>io.github.co-mmer</groupId>
88
<artifactId>aaa-mockmvc</artifactId>
9-
<version>1.4.1</version>
9+
<version>1.4.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>AAA-MockMvc</name>
13-
<description>This project provides a framework for structuring unit tests following the AAA
14-
(Arrange, Act, Assert) pattern with a focus on clarity and readability.
15-
The library offers a fluent API that guides the developer through each phase,
16-
ensuring that only contextually relevant methods are available at each step.
17-
The key goal is to provide a clean separation of concerns within the test, allowing developers
18-
to express their test logic fluently and naturally.
13+
<description>
14+
A fluent testing framework for Spring's MockMvc that enforces the Arrange-Act-Assert (AAA)
15+
pattern and reduces boilerplate in controller tests.
16+
The library guides developers through each testing phase with a strongly-typed,
17+
step-by-step API, ensuring a consistent and intuitive test structure. Common tasks such as
18+
request setup, ObjectMapper-based serialization, and response assertions are fully abstracted,
19+
allowing developers to focus on the test logic itself rather than technical overhead.
1920
</description>
2021
<url>https://github.com/co-mmer/aaa-mockmvc</url>
2122

@@ -45,7 +46,7 @@
4546
<parent>
4647
<groupId>org.springframework.boot</groupId>
4748
<artifactId>spring-boot-starter-parent</artifactId>
48-
<version>3.4.4</version>
49+
<version>3.4.5</version>
4950
<relativePath/>
5051
</parent>
5152

@@ -58,71 +59,21 @@
5859

5960
<dependencies>
6061

61-
<!-- Lombok -->
6262
<dependency>
6363
<groupId>org.projectlombok</groupId>
6464
<artifactId>lombok</artifactId>
6565
<version>1.18.38</version>
6666
<scope>provided</scope>
6767
</dependency>
6868

69-
<!-- jakarta -->
70-
<dependency>
71-
<groupId>jakarta.servlet</groupId>
72-
<artifactId>jakarta.servlet-api</artifactId>
73-
<version>6.1.0</version>
74-
<scope>provided</scope>
75-
</dependency>
76-
77-
<!-- Spring -->
7869
<dependency>
7970
<groupId>org.springframework.boot</groupId>
8071
<artifactId>spring-boot-starter-web</artifactId>
81-
<scope>provided</scope>
82-
<exclusions>
83-
<exclusion>
84-
<groupId>org.springframework.boot</groupId>
85-
<artifactId>spring-boot-starter-logging</artifactId>
86-
</exclusion>
87-
<exclusion>
88-
<groupId>com.fasterxml.jackson.module</groupId>
89-
<artifactId>jackson-module-parameter-names</artifactId>
90-
</exclusion>
91-
<exclusion>
92-
<groupId>com.fasterxml.jackson.datatype</groupId>
93-
<artifactId>jackson-datatype-jsr310</artifactId>
94-
</exclusion>
95-
<exclusion>
96-
<groupId>com.fasterxml.jackson.datatype</groupId>
97-
<artifactId>jackson-datatype-jdk8</artifactId>
98-
</exclusion>
99-
<exclusion>
100-
<groupId>org.yaml</groupId>
101-
<artifactId>snakeyaml</artifactId>
102-
</exclusion>
103-
<exclusion>
104-
<groupId>org.springframework.boot</groupId>
105-
<artifactId>spring-boot-starter-tomcat</artifactId>
106-
</exclusion>
107-
<exclusion>
108-
<groupId>org.apache.tomcat.embed</groupId>
109-
<artifactId>tomcat-embed-el</artifactId>
110-
</exclusion>
111-
<exclusion>
112-
<groupId>org.apache.tomcat.embed</groupId>
113-
<artifactId>tomcat-embed-websocket</artifactId>
114-
</exclusion>
115-
<exclusion>
116-
<groupId>ch.qos.logback</groupId>
117-
<artifactId>logback-classic</artifactId>
118-
</exclusion>
119-
</exclusions>
12072
</dependency>
12173

12274
<dependency>
12375
<groupId>org.springframework.boot</groupId>
12476
<artifactId>spring-boot-starter-test</artifactId>
125-
<scope>provided</scope>
12677
<exclusions>
12778
<exclusion>
12879
<groupId>org.xmlunit</groupId>

0 commit comments

Comments
 (0)