-
-
Save alpizano/704f1446136477f37a75bd3ee5af611e to your computer and use it in GitHub Desktop.
Mockito spy example
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
import static org.mockito.Mockito.*; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.junit.Test; | |
public class MockitoSpyExample { | |
@Test | |
public void spyExample_nominal_case_Test() { | |
Map<String, String> hashMap = new HashMap<String, String>(); | |
Map<String, String> mapSpy = spy(hashMap); | |
System.out.println(mapSpy.get("key")); | |
mapSpy.put("key", "Test value"); | |
System.out.println(mapSpy.get("key")); // Will print "Test value". | |
when(mapSpy.get("key")).thenReturn("Mocked value"); | |
System.out.println(mapSpy.get("key")); // Will print "Mocked vqlue". | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment