This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExtendWith(MockitoExtension.class) | |
public class TestMockitoInjection { | |
private BoringService service; | |
public TestMockitoInjection(@Mock BoringService service) { | |
this.service = service; | |
} | |
@Test | |
public void testConstructorInjectedValue() { | |
when(service.returnNumber()).thenReturn(2); | |
assertEquals(2, service.returnNumber()); | |
} | |
@Test | |
public void testMethodInjection(@Mock BoringService service) { | |
when(service.returnNumber()).thenReturn(3); | |
assertEquals(3, service.returnNumber()); | |
} | |
public class BoringService { | |
public int returnNumber() { | |
return 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment