class Student{
int age;
String name;
}
class Demo{
public void getStudentList() {
Future<List<Student>> future = client.getAsyncData();
List<Student> response = futures.get(100l, TimeUnit
.MILLISECONDS);
}
}
class StudentTest{
@Test
public testData(){
List<Student> students = new ArrayList();
Client client = ClientFactory.getInstance();
Future<List<Student>> mockFuture = mock(Future.class);
when(client.getAsyncData()).thenReturn(mockFuture);
when(mockFuture.get(10l,TimeUnit.MILLISECONDS)).thenReturn(students);
Demo demo = mock(Demo.class);
demo.getStudentList();
}
** I am getting students List object as null ** Client is 3rd party service, it is abstracted
// How should I mock future list in Java, is this the right way ?