无法在JUnit测试类中调用Pageable方法

时间:2019-02-07 08:40:07

标签: java junit pagination

下面显示的是用于检查存储库中供应商页面的上一页和下一页的代码段。为此方法编写JUnit

  

java.lang.UnsupportedOperationException,位于   org.springframework.data.domain.Unpaged.getPageNumber(Unpaged.java:87)

在调用getPageNumber()方法时从第三行抛出

请帮助我解决这个问题。

 PageDTO pageDTO = new PageDTO();
                int totalPages = vendors.getTotalPages() - 1;
                if (totalPages - vendors.getPageable().getPageNumber() != 0) {
                    pageDTO.setNext(paginationUrl + "getvendorslist?start=" + 
                 vendors.getPageable().next().getPageNumber() + "&limit=" + limit);
                } else {
                    pageDTO.setNext("");
                }
                if (vendors.getPageable().hasPrevious()) {
                    pageDTO.setPrevious(paginationUrl + "getvendorslist?start=" + vendors.getPageable().previousOrFirst().getPageNumber() + "&limit=" + limit);
                } else {
                    pageDTO.setPrevious("");
                }

    }

这就是我给出测试用例的方式

    @Test
    public void findAllVendors() {
        VendorAddress address = new VendorAddress(1, "address", "city", "country", "kerala", "zip", "craeted",
                "modified", true, false);
        ContactInformation contactInfo = new ContactInformation(1, "firstName", "lastName", "nayana.a@thinkpalm.com",
                "createdBy", "modifiedBy", true, false);
        PaymentDetails payDet = new PaymentDetails((long) 1, "mode", true, false, (long) 3);
        List<PaymentDetails> paymentDetails = new ArrayList<>();
        paymentDetails.add(new PaymentDetails((long) 1, "Cash", true, false, (long) 1));
        List<VendorDetails> details = new ArrayList<VendorDetails>();
        details.add(new VendorDetails((long) 1, "2", "TXA445", "pass", "createdby", "modifiedby", true, false, address,
                contactInfo, address, paymentDetails));
        Page<VendorDetails> vendors = new PageImpl(details);
        PageRequest page = PageRequest.of(0, 50);
        Mockito.when(vendorDetailsRepository.findAllVendors(page)).thenReturn(vendors);
        ResponseModel responseModel = registrationService.findAllVendors(0, 50);
        Integer result = responseModel.getCode();
        assertEquals((Integer) 1000, result);


    }

非常感谢您的帮助

0 个答案:

没有答案