SDN Controller Programming Guide
151
@Override
@Before
public void setUp() throws Exception {
super.setUp();
ResourceTest.setDefaultMediaType(MediaType.APPLICATION_JSON);
switchServiceMock = EasyMock.createMock(SwitchService.class);
sl.register(SwitchService.class, switchServiceMock,
Collections.<String, Object> emptyMap());
}
@Override
@After
public void tearDown() throws Exception {
super.tearDown();
sl.unregister(SwitchService.class, switchServiceMock);
}
@Test
public void testList() {
// Create mocks and define test case data
List<Switch> switches = Collections.emptyList(); // Create test case
// Recording phase (Define expectations)
EasyMock.expect(
switchServiceMock.find(EasyMock.isNull(SwitchFilter.class),
EasyMock.isNull(SortSpecification.class))).andReturn(switches);
// Execution phase
EasyMock.replay(switchServiceMock);
String response = get(BASE_PATH);
// Verification phase
String expectedResponse = "{\"switches\":[]}";
assertResponseContains(response, expectedResponse);
EasyMock.verify(switchServiceMock);
}
...
}