src/test/java/com/sapient/XYZecommmarket/services/ProductServiceTests.java
@Test
    public void testGetAllProductsMock() {
        when(dataServiceMock.findAll(any(PageRequest.class))).thenReturn(new PageImpl<>(prodList));
        assertEquals(2, productService.getAllProducts(1).getTotalElements());
    }
/**
     * business layer test with mock DB data
     */
business layer test with mock DB data
business layer test with mock DB data
@Test
    public void testGetAllProductsMock() {
        when(dataServiceMock.findAll(any(PageRequest.class))).thenReturn(new PageImpl<>(prodList));
        assertEquals(2, productService.getAllProducts(1).getTotalElements());
    }
@ Test public void testGetAllProductsMock ( ) { when ( dataServiceMock . findAll ( any ( PageRequest . class ) ) ) . thenReturn ( new PageImpl < > ( prodList ) ) ; assertEquals ( 2 , productService . getAllProducts ( 1 ) . getTotalElements ( ) ) ; }
business layer test with mock DB data
business layer test with mock DB data