openrewrite / openrewrite/rewrite-spring

MockMvc Soft Assertions recipe

Open
#196 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

boot-2.4 recipe
Dominant language
Java
Stars
403
Forks
149
Avg merge
2h 33m
Merged PRs (30d)
10

Description

Spring Framework 5.3 added support for soft assertions to MockMvc, as detailed on slides 36 & 37 here.

These allow you to check multiple conditions and report on all of them, rather than just report on the first one that fails.

mockMvc.perform(get("/person/5").accept(APPLICATION_JSON))
-  .andExpect(status().isOk())
-  .andExpect(jsonPath("$.name").value("Jane"));
+  .andExpectAll(
+     status().isOk(),
+     jsonPath("$.name").value("Jane"));

This helps debugging when a test fails, as you not only get the status code (something like 4xx/5xx), but also the content body.

Would seem doable to pick up as a recipe to aid that migration, so figured pitch it here for anyone willing to work on that (or until I find the time).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names MockMvc and the andExpect-to-andExpectAll migration but no repository files or tests. Start by locating existing MockMvc recipe implementations and their tests, then use the shown transformation as the expected behavior. Done means the recipe applies that migration and its tests cover the resulting assertions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.