-1

I'm getting an UnfinishedStubbingException with the following code:

Mockito.when(repository.findAll(Mockito.any(Pageable.class)))
    .thenReturn(BusinessEntityMockGenerator.createPageResponse(bd, null));

The strange thing is I was not getting this error with Spring Boot 1.3. I just upgraded to Spring Boot 2.0 and now I'm getting this error.

Any ideas? Thanks!

EDIT: It's also giving the error Pageable must not be null!.

Jonathan
  • 20,053
  • 6
  • 63
  • 70
user3133300
  • 607
  • 4
  • 13
  • 23
  • Your issue is not very clear. The exceptions are not accumulative but if you catch them. So what did it raise ? `UnfinishedStubbingException` or `Pageable must not be null` Please present the `BusinessEntityMockGenerator` class too. It may matter. – davidxxx Jul 06 '18 at 15:24
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a [mcve]. Use the [edit] link to improve your *question* - do not add more information via comments. Thanks! – GhostCat Jul 08 '18 at 19:32

1 Answers1

1

I'm not sure what BusinessEntityMockGenerator is doing, but try to separate the method call for the page response:

Object toReturn = BusinessEntityMockGenerator.createPageResponse(bd, null);
Mockito.when(repository.findAll(Mockito.any(Pageable.class))).thenReturn(toReturn);

You can also try:

Object toReturn = BusinessEntityMockGenerator.createPageResponse(bd, null);
Mockito.doReturn(toReturn).when(repository).findAll(Mockito.any(Pageable.class))
Phil Ninan
  • 1,108
  • 1
  • 14
  • 23