SHARE
TWEET

Untitled

a guest Sep 13th, 2017 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. protected JSONObject myMethod(final String param1, final String param2)
  2. {
  3. }
  4.    
  5. final MyService mymock = Mockito.mock(MyService.class, Mockito.CALLS_REAL_METHODS);        
  6.     final String pararm1 = “param1”;
  7.     Mockito.doReturn(myData).when(mymock).myMethod(param1, param2);
  8.    
  9. public class MyClass {
  10.     protected String protectedMethod() {
  11.         return "Can't touch this";
  12.     }
  13.     public String publicMethod() {
  14.         return protectedMethod();
  15.     }
  16. }
  17.    
  18. @RunWith(MockitoJUnitRunner.class)
  19. public class MyClassTest {
  20.  
  21.     class MyClassMock extends MyClass {
  22.         @Override
  23.         public String protectedFunction() {
  24.             return "You can see me now!";
  25.         }
  26.     }
  27.  
  28.     @Mock
  29.     MyClassMock myClass = mock(MyClassMock.class);
  30.  
  31.     @Test
  32.     public void myClassPublicFunctionTest() {
  33.         when(myClass.publicFunction()).thenCallRealMethod();
  34.         when(myClass.protectedFunction()).thenReturn("jk!");
  35.     }
  36. }
RAW Paste Data
Top