Complete the code to create a simple stub for a dependency.
MyService service = new MyService();
Dependency dep = new [1]();
service.setDependency(dep);A stub provides fixed responses for testing without complex behavior.
Complete the code to verify that a method was called once using a mock.
MockedList list = mock(MockedList.class); list.add("item"); verify(list, [1]).add("item");
times(1) verifies the method was called exactly once.
Fix the error in the spy creation code.
List<String> list = new ArrayList<>(); List<String> spyList = [1](list); spyList.add("test");
spy() wraps a real object to track interactions while keeping behavior.
Fill both blanks to create a fake that simulates a database connection and returns a fixed value.
class FakeDatabase implements Database { public String query(String sql) { return [1]; } } Database db = new FakeDatabase(); String result = db.query([2]);
A fake provides a simple implementation returning fixed data. The query string is a typical SQL command.
Fill all three blanks to create a mock, set expectation, and verify interaction.
List<String> mockList = [1](List.class); when(mockList.get([2])).thenReturn("hello"); mockList.get(0); verify(mockList).get([3]);
mock() creates the mock object. The index 0 is used for both when() and verify() calls.
