Skip to content

Instantly share code, notes, and snippets.

Created October 31, 2017 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9cc063d89d9eb2258633fc12dde4b862 to your computer and use it in GitHub Desktop.
Save anonymous/9cc063d89d9eb2258633fc12dde4b862 to your computer and use it in GitHub Desktop.
Example of Argument Captor
public class MainClassTest {
Utility utility = mock(Utility.class);
@Test
public void testCountofCharacter(){
String testText = "Harvey : I don’t play the odds, I play the man.";
MainClass mainClass = new MainClass(utility);
mainClass.countNumberCharacter(testText, 'e');
ArgumentCaptor<Integer> actualCount = ArgumentCaptor.forClass(Integer.class);
verify(utility, times(1)).logToConsole(actualCount.capture());
//Expected Number of 'e' in test text.
//Harv'e'y : I don't play th'e' odds, I play th'e' man.
Assert.assertEquals(3, (long)actualCount.getValue());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment