Skip to content

Instantly share code, notes, and snippets.

@Romeh
Created September 3, 2018 15:11
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 Romeh/eb676c3ca8741e3de8892c5759a70e60 to your computer and use it in GitHub Desktop.
Save Romeh/eb676c3ca8741e3de8892c5759a70e60 to your computer and use it in GitHub Desktop.
@ExtendWith(MockitoExtension.class)
@DisplayName("Spring boot 2 mockito2 Junit5 example")
public class ShowServiceTests {
private static final String MOCK_OUTPUT = "Mocked show label";
@Mock
private TextService textService;
@InjectMocks
private ShowService showService;
@BeforeEach
void setMockOutput() {
when(textService.getText()).thenReturn(MOCK_OUTPUT);
}
@Test
@DisplayName("Mock the output of the text service using mockito")
public void contextLoads() {
assertEquals(showService.getShowLable(), MOCK_OUTPUT);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment