Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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