Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected JSONObject myMethod(final String param1, final String param2)
- {
- …
- }
- final MyService mymock = Mockito.mock(MyService.class, Mockito.CALLS_REAL_METHODS);
- final String pararm1 = “param1”;
- Mockito.doReturn(myData).when(mymock).myMethod(param1, param2);
- public class MyClass {
- protected String protectedMethod() {
- return "Can't touch this";
- }
- public String publicMethod() {
- return protectedMethod();
- }
- }
- @RunWith(MockitoJUnitRunner.class)
- public class MyClassTest {
- class MyClassMock extends MyClass {
- @Override
- public String protectedFunction() {
- return "You can see me now!";
- }
- }
- @Mock
- MyClassMock myClass = mock(MyClassMock.class);
- @Test
- public void myClassPublicFunctionTest() {
- when(myClass.publicFunction()).thenCallRealMethod();
- when(myClass.protectedFunction()).thenReturn("jk!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement