0

I am trying to write a simple test case in which I am trying to make a PagedList (com.microsoft.azure.PagedList) return a mock object.

But I am unable to understand the underlying implementation to be able to do so. If anyone has any example or have done this would be really grateful.

This is the type of PagedList I was using to return a mock object of type VirtualMachineSize

PagedList<VirtualMachineSize>
user1142317
  • 533
  • 1
  • 8
  • 20

1 Answers1

1

So this is how I managed to do it.

    PagedList<VirtualMachineSize> mockResult = new PagedList<VirtualMachineSize>() {
                    @Override
                    public Page<VirtualMachineSize> nextPage(String s) {
                        return new Page<VirtualMachineSize>() {
                            @Override
                            public String nextPageLink() {
                                return null;
                            }

                            @Override
                            public List<VirtualMachineSize> items() {
                                return null;
                            }
                        };
                    }
                };
 mockResult.add(getMockVirtualMachineSize());


.
.
.

    /*
        Creates and returns mock VirtualMachineSize object.
        @return VirtualMachineSize mocked VirtualMachineSize object.
         */
        @Nonnull
        private static VirtualMachineSize getMockVirtualMachineSize() {
            final VirtualMachineSize vmSize = Mockito.mock(VirtualMachineSize.class);
            Mockito.when(vmSize.name()).thenReturn(VM_PROFILE_BASIC_A2);
            return vmSize;
        }
user1142317
  • 533
  • 1
  • 8
  • 20