File tree Expand file tree Collapse file tree 6 files changed +74
-2
lines changed
java/com/codingapi/springboot/framework Expand file tree Collapse file tree 6 files changed +74
-2
lines changed Original file line number Diff line number Diff line change 4141 <artifactId >commons-io</artifactId >
4242 </dependency >
4343
44+ <dependency >
45+ <groupId >org.springframework.boot</groupId >
46+ <artifactId >spring-boot-starter-web</artifactId >
47+ <scope >test</scope >
48+ </dependency >
49+
4450 </dependencies >
4551
4652</project >
Original file line number Diff line number Diff line change 11package com .codingapi .springboot .framework ;
22
3+ import com .alibaba .fastjson .JSONObject ;
34import org .junit .jupiter .api .Test ;
5+ import org .springframework .beans .factory .annotation .Autowired ;
6+ import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
47import org .springframework .boot .test .context .SpringBootTest ;
8+ import org .springframework .http .MediaType ;
9+ import org .springframework .test .web .servlet .MockMvc ;
10+
11+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
12+ import static org .junit .jupiter .api .Assertions .assertEquals ;
513
614@ SpringBootTest
15+ @ AutoConfigureMockMvc
716class FrameworkApplicationTests {
817
18+ @ Autowired
19+ private MockMvc mockMvc ;
920
1021 @ Test
11- void contextLoads () {
12-
22+ void hello () throws Exception {
23+ mockMvc .perform (get ("/open/hello" ).contentType (MediaType .APPLICATION_JSON )).andExpect (result -> {
24+ JSONObject jsonObject = JSONObject .parseObject (result .getResponse ().getContentAsString ());
25+ assertEquals (jsonObject .getJSONObject ("data" ).getString ("hello" ),"hello" );
26+ });
1327 }
1428
1529}
Original file line number Diff line number Diff line change 1+ package com .codingapi .springboot .framework .controller ;
2+
3+ import com .codingapi .springboot .framework .dto .response .MapResponse ;
4+ import org .springframework .web .bind .annotation .GetMapping ;
5+ import org .springframework .web .bind .annotation .RequestMapping ;
6+ import org .springframework .web .bind .annotation .RestController ;
7+
8+ @ RestController
9+ @ RequestMapping ("/open" )
10+ public class DemoController {
11+
12+ @ GetMapping ("/hello" )
13+ public MapResponse hello (){
14+ return MapResponse .create ().add ("hello" ,"hello" );
15+ }
16+
17+ }
Original file line number Diff line number Diff line change 1+ package com .codingapi .springboot .framework .dto .request ;
2+
3+ import org .junit .jupiter .api .Test ;
4+
5+ import static org .junit .jupiter .api .Assertions .*;
6+
7+ class PageRequestTest {
8+
9+ @ Test
10+ void test (){
11+ System .setProperty (PageRequest .CURRENT_FIX_VALUE ,"1" );
12+ PageRequest pageRequest = new PageRequest ();
13+ pageRequest .setCurrent (2 );
14+
15+ assertEquals (pageRequest .getPageNumber (),1 );
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ package com .codingapi .springboot .framework .exception ;
2+
3+ import org .junit .jupiter .api .Test ;
4+ import org .springframework .boot .test .context .SpringBootTest ;
5+
6+ import static org .junit .jupiter .api .Assertions .*;
7+
8+ @ SpringBootTest
9+ class LocaleMessageExceptionTest {
10+
11+ @ Test
12+ void test (){
13+ LocaleMessageException exception = new LocaleMessageException ("api.error" );
14+ assertEquals (exception .getErrMessage (),"this is an error info" );
15+ }
16+
17+ }
Original file line number Diff line number Diff line change 1+ api.error =this is an error info
You can’t perform that action at this time.
0 commit comments