I am trying to test a List with mockito but do not know how to set my expected value.
Below is what I have so far. Also if someone can tell me how to create mock objects with specific values that would be awesome.
@Test
public void testFindAllProductsByCategoryId() throws Exception {
List<Map> expectedProductList = anyList(Products.class);
when(productListMock.findAllProductsByCategoryId(1)).thenReturn(expectedProductList);
List<Map> actualProductList = productListMock.findAllProductsByCategoryId(1);
}
I don’t think you’re doing this right. anyList is for matchers. you’re supposed to use it inside the
whenmethod. For example:That said, I don’t have a clear idea of what you’re trying to do here. The documentation of mockito is very well written so I think you should go back to that to figure out what you’re trying to do.