Skip to content

Instantly share code, notes, and snippets.

@roshanadh
Created October 21, 2022 18:16
Show Gist options
  • Save roshanadh/5fc60b30b13e80326562f8e865e37f8e to your computer and use it in GitHub Desktop.
Save roshanadh/5fc60b30b13e80326562f8e865e37f8e to your computer and use it in GitHub Desktop.
Testing POST /batteries
@Test
void shouldPersistBattery() throws Exception {
Battery mockBattery =
new Battery("Gold Coast Mc", "9729", 50000);
mockMvc
.perform(
post("/batteries")
.content(objectMapper.writeValueAsString(mockBattery))
.contentType(MediaType.APPLICATION_JSON)
)
.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.name").value(mockBattery.getName()))
.andExpect(jsonPath("$.postcode").value(mockBattery.getPostcode()))
.andExpect(jsonPath("$.capacity").value(mockBattery.getCapacity()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment