Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Main entry point of the application
package com.mrxgrc.inventory;

import org.springframework.boot.SpringApplication;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/mrxgrc/inventory/ItemController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mrxgrc.inventory;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ItemController {

@GetMapping("/items")
public String getItems() {
return "List of items";
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Generated by the protocol buffer compiler to check spring application context starts without errors.
package com.mrxgrc.inventory;

import org.junit.jupiter.api.Test;
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/com/mrxgrc/inventory/ItemControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mrxgrc.inventory;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(ItemController.class)
public class ItemControllerTest {

@Autowired
private MockMvc mockMvc;

@Test
void getItemsReturnsListofItems() throws Exception{
this.mockMvc.perform(get("/items"))
.andExpect(status().isOk())
.andExpect(content().string("List of items"));


}
}