Guest User

Untitled

a guest
Oct 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import org.junit.Test;
  2. import org.junit.runner.RunWith;
  3. import org.mockito.InjectMocks;
  4. import org.mockito.Mock;
  5. import org.mockito.Mockito;
  6. import org.mockito.junit.MockitoJUnitRunner;
  7.  
  8. @RunWith(MockitoJUnitRunner.class)
  9.  
  10. public class ClassATest {
  11.  
  12. @InjectMocks
  13. ClassA classsA;
  14. @Mock
  15. ClassB classB;
  16. @Test
  17. public void testClassAMethod() {
  18. //Assuming ClassA has one method which takes String array,
  19. String[] inputStrings = {"A", "B", "C"};
  20. //when you call classAMethod, it intern calls getClassMethod(String input)
  21. classA.classAMethod(inputStrings);
  22. //times(0) tells you method getClassBmethod(anyString()) been called zero times, in my example inputStrings length is three,
  23. //it will be called thrice
  24. //Mockito.verify(classB, times(0)).getClassBMethod(anyString());
  25. Mockito.verify(classB, times(3)).getClassBMethod(anyString());
  26. }
  27. }
Add Comment
Please, Sign In to add comment