Skip to content

Commit 05ab11c

Browse files
committed
add junit test
1 parent 81eb762 commit 05ab11c

File tree

6 files changed

+74
-2
lines changed

6 files changed

+74
-2
lines changed

springboot-starter/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
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>
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
package com.codingapi.springboot.framework;
22

3+
import com.alibaba.fastjson.JSONObject;
34
import org.junit.jupiter.api.Test;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
47
import 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
716
class 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
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
api.error=this is an error info

0 commit comments

Comments
 (0)