Skip to content

Commit 9b3b8dd

Browse files
committed
Added tests
1 parent 731f9c1 commit 9b3b8dd

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

hackster-service/src/test/java/com/lohika/jclub/HacksterServiceApplicationTests.java

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,50 @@
22

33
import org.junit.Test;
44
import org.junit.runner.RunWith;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
58
import org.springframework.boot.test.context.SpringBootTest;
69
import org.springframework.test.context.junit4.SpringRunner;
10+
import org.springframework.test.web.servlet.MockMvc;
11+
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
12+
13+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
14+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
15+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
716

817
@RunWith(SpringRunner.class)
918
@SpringBootTest
19+
@AutoConfigureMockMvc
1020
public class HacksterServiceApplicationTests {
21+
@Value("${maxAllowedApartmentsPerRealtor}")
22+
private int maxAllowedApartmentsPerRealtor;
23+
24+
@Autowired
25+
private MockMvc mockMvc;
26+
27+
@Test
28+
public void checkIfNewPhoneNumberIsNotHakster() throws Exception {
29+
mockMvc.perform(get("/hackster/123123123"))
30+
.andDo(MockMvcResultHandlers.print())
31+
.andExpect(status().isOk())
32+
.andExpect(content().string("false"));
33+
}
34+
35+
@Test
36+
public void checkIfOldPhoneNumberIsNotHakster() throws Exception {
37+
mockMvc.perform(get("/hackster/321321"))
38+
.andDo(MockMvcResultHandlers.print())
39+
.andExpect(status().isOk())
40+
.andExpect(content().string("false"));
41+
42+
for (int i = 0; i < maxAllowedApartmentsPerRealtor - 1; i++) {
43+
mockMvc.perform(get("/hackster/321321"));
44+
}
1145

12-
@Test
13-
public void contextLoads() {
14-
}
46+
mockMvc.perform(get("/hackster/321321"))
47+
.andDo(MockMvcResultHandlers.print())
48+
.andExpect(status().isOk())
49+
.andExpect(content().string("true"));
50+
}
1551
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
maxAllowedApartmentsPerRealtor=10
2+
eureka.client.enabled=false

0 commit comments

Comments
 (0)