NoteService { public Note getNote(String id) { URI resolvedUri = configuration.baseUri().resolve("/notes/").resolve(id); log.info("Retrieving note from {}", resolvedUri); return restTemplate.getForObject(resolvedUri, Note.class); } @Autowired  NoteService(NoteServiceConfiguration configuration); Note getNote(String id);  }
@Test @WireMockTest(stubPath = "mappings/note-get-example") public void should_1_use_dedicated_wiremock_stub_returning_path_id_in_response_body() { UUID id = UUID.randomUUID(); final Note note = noteService.getNote(id.toString()); assertEquals("REST maturity model", note.getTitle()); assertEquals(id, note.getId()); }
@Test(expected = HttpClientErrorException.class) @WireMockTest(stubPath = "mappings/note-badrequest-example") public void should_2_use_different_wiremock_stub() { noteService.getNote("xy"); }
@Test public void should_3_use_default_wiremock_stubs() { assertEquals("REST maturity model", noteService.getNote(UUID.randomUUID().toString()).getTitle()); }
@Test(expected = HttpClientErrorException.class) @WireMockTest(stubPath = "mappings/note-badrequest-example") public void should_4_not_find_excluded_wiremock_stub() { noteService.getNote("1"); }