Created
June 29, 2010 11:54
-
-
Save CliveEvans/457120 to your computer and use it in GitHub Desktop.
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 Helper { | |
public void addInterface(SomeInterface some) { | |
} | |
} |
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
@RunWith(MockitoJUnitRunner.class) | |
public class MockitoAnyVersusIsATest { | |
@Mock | |
private Helper helper; | |
@Test | |
public void shouldVerifyCalledWithAnyArgumentsAtAll() throws Exception { | |
new ObjectUnderTest(helper); | |
verify(helper, times(2)).addInterface(any(ImplementationOne.class)); // class parameter is used to make the systems happy at compile time | |
} | |
@Test | |
public void shouldVerifyArgumentsWereOfRightType() throws Exception { | |
new ObjectUnderTest(helper); | |
verify(helper).addInterface(isA(ImplementationOne.class)); | |
verify(helper).addInterface(isA(ImplementationTwo.class)); | |
} | |
} |
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
@RunWith(MockitoJUnitRunner.class) | |
public class MockitoAnyVersusIsATest { | |
@Mock | |
private Helper helper; | |
@Test | |
public void shouldVerifyCalledWithAnyArgumentsAtAll() throws Exception { | |
new ObjectUnderTest(helper); | |
verify(helper)).addInterface(any(ImplementationOne.class)); | |
verify(helper)).addInterface(any(ImplementationTwo.class)); | |
} | |
} |
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 ObjectUnderTest { | |
public ObjectUnderTest(Helper helper) { | |
helper.addInterface(new ImplementationOne()); | |
helper.addInterface(new ImplementationTwo()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment