Last active
October 20, 2016 18:33
-
-
Save efleming969/969fc36a64bce5819e2984854226ff05 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package example; | |
import java.util.*; | |
import java.io.*; | |
import static org.junit.Assert.*; | |
import static org.mockito.Mockito.*; | |
import org.junit.*; | |
public class MockingExample { | |
@Test | |
public void should_build_a_greeting_based_on_age() { | |
DataService ds = mock( DataService.class ); | |
when( ds.getMessageBasedOnAge( 45 ) ).thenReturn( "Whazzup" ); | |
Greeting g = new Greeting( ds ); | |
String message = g.build( "Joe", 45 ); | |
assertEquals( "Whazzup, Joe!", message ); | |
} | |
@Test | |
public void should_send_an_email_message() { | |
EmailService es = mock( EmailService.class ); | |
Greeting g = new Greeting( es ); | |
g.sayHello( "Joe" ); | |
verify( es ).send( "Whazzup, Joe!" ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment