Skip to content

Instantly share code, notes, and snippets.

@hakansander
Last active April 24, 2020 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakansander/99c833434b864b12ee40c3f4cfbc1670 to your computer and use it in GitHub Desktop.
Save hakansander/99c833434b864b12ee40c3f4cfbc1670 to your computer and use it in GitHub Desktop.
Success case of Invoice Controller
@Test
public void testWhenPhoneNumEnteredAndDataExists_thenReturnHttp200() throws Exception {
final String mockPhoneNumber = "534*******";
final FileInputStream fileInputStream = new FileInputStream(ResourceUtils.getFile("classpath:response_http200.json"));
final String staticResponse = StreamUtils.copyToString(fileInputStream, Charset.defaultCharset());
InvoiceResponse mockInvoiceResponse = mapper.readValue(staticResponse, InvoiceResponse.class);
when(invoiceService.getInvoiceInfo(mockPhoneNumber))
.thenReturn(mockInvoiceResponse);
mockMvc.perform(get("/invoiceQuery/{phoneNumber}", mockPhoneNumber))
.andExpect(jsonPath("$.statusCode", is("200")));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment