Created
October 31, 2017 14:48
-
-
Save anonymous/9cc063d89d9eb2258633fc12dde4b862 to your computer and use it in GitHub Desktop.
Example of Argument Captor
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
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