Skip to content

Commit

Permalink
Added test mvc method generation
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTimeey committed Oct 1, 2020
1 parent 6ad40c9 commit 4a13db8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ Options:
- [x] Use static import if possible
- [x] Shorten FQ names

### JUnit Test Method with MockMvc
Test method generation with imported `MockMvc` from Spring.

![Generate mockmvc test method](test_mvc_method/example.gif)

Abbreviation: __testmvc__
Template text:
```java
@org.springframework.beans.factory.annotation.Autowired
private org.springframework.test.web.servlet.MockMvc mockMvc;

@org.junit.jupiter.api.Test
public void test$Function$() throws java.lang.Exception {
org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder request = org.springframework.test.web.servlet.request.MockMvcRequestBuilders
.get("")
.contentType(org.springframework.http.MediaType.APPLICATION_JSON);

mockMvc.perform(request)
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status().isOk())
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content().contentType(org.springframework.http.MediaType.APPLICATION_JSON))
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath("", org.hamcrest.Matchers.is("")));
}
```
Options:
- [x] Reformat according to style
- [ ] Use static import if possible
- [x] Shorten FQ names

### Create SLF4J-Logger
Creates SLF4J logger and adds the static imports.

Expand Down
6 changes: 6 additions & 0 deletions custom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="testmvc" value="@org.springframework.beans.factory.annotation.Autowired&#10;private org.springframework.test.web.servlet.MockMvc mockMvc;&#10;&#10;@org.junit.jupiter.api.Test&#10;public void test$Function$() throws java.lang.Exception {&#10; org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder request = org.springframework.test.web.servlet.request.MockMvcRequestBuilders&#10; .get(&quot;&quot;)&#10; .contentType(org.springframework.http.MediaType.APPLICATION_JSON);&#10;&#10; mockMvc.perform(request)&#10; .andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status().isOk())&#10; .andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content().contentType(org.springframework.http.MediaType.APPLICATION_JSON))&#10; .andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath(&quot;&quot;, org.hamcrest.Matchers.is(&quot;&quot;)));&#10;}" description="Creates JUnit test method with MockMvc" toReformat="true" toShortenFQNames="true">
<variable name="Function" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
</templateSet>
Binary file modified settings.zip
Binary file not shown.
Binary file added test_mvc_method/example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4a13db8

Please sign in to comment.