... @Test void testGetItemCalled(){ // mock the api VidioService mockService = Mockito.mock(VidioService.class); // mock the api result
when(mockService.getItems()).thenReturn(createObservableListItems()); List<Item> items = sellItemController.getItems(); // verify get items is called verify(mockService).getItems(); assertEquals(10, items.size()); // verify the api result } import ApiService class SellItemController {
...
public void getItems() { apiService = buildRetrofitApiService(); //build api service return apiService.getItems(); // call the api } } SellItemController.java TestSellItemController.java