Skip to content

Commit 5155fd7

Browse files
authored
Merge pull request #4 from getyourguide/add_stubbed_tests
Adding tests
2 parents 3b07ac5 + 20e4ef8 commit 5155fd7

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
package com.getourguide.interview;
22

3+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
4+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
5+
36
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
49
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.test.web.servlet.MockMvc;
511

612
@SpringBootTest
13+
@AutoConfigureMockMvc
714
class GetYourGuideApplicationTests {
15+
@Autowired
16+
private MockMvc mockMvc;
817

918
@Test
10-
void contextLoads() {
19+
void contextLoads() throws Exception {
20+
mockMvc.perform(get("/activities"))
21+
.andExpect(status().isOk());
1122
}
12-
1323
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.getourguide.interview.controller;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.test.context.SpringBootTest;
8+
9+
@SpringBootTest
10+
class ActivitiesControllerTest {
11+
@Autowired
12+
private ActivitiesController activitiesController;
13+
14+
@Test
15+
void testGetActivities() {
16+
var result = activitiesController.activities();
17+
assertNotNull(result);
18+
}
19+
}

src/test/java/com/getourguide/interview/service/ActivityServiceTest.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.getourguide.interview.service;
22

3-
import static org.junit.jupiter.api.Assertions.*;
4-
53
import com.getourguide.interview.controller.SupplierController;
64
import com.getourguide.interview.repository.ActivityRepository;
5+
import java.util.List;
6+
import org.junit.jupiter.api.Assertions;
77
import org.junit.jupiter.api.BeforeEach;
88
import org.junit.jupiter.api.Test;
99

@@ -24,6 +24,19 @@ void setup() {
2424
}
2525

2626
@Test
27-
void test() {
27+
void testGetActivities() {
28+
var testActivity = createActivity(
29+
1L,
30+
"Test Activity",
31+
100,
32+
5.0,
33+
false,
34+
createSupplier(1L, "Test Supplier")
35+
);
36+
when(activityRepository.findAll()).thenReturn(List.of(testActivity));
37+
38+
var result = activityService.getActivities();
39+
40+
Assertions.assertNotNull(result);
2841
}
2942
}

0 commit comments

Comments
 (0)