src/test/java/com/sapient/XYZecommmarket/services/ProductServiceTests.java
@Test
    public void testGetProductBySku() {
        Product prod1 = new Product();
        prod1.setId(4L);
        prod1.setName("Nike shoe");
        prod1.setBrand(new Brand(4L, "Nike"));
        prod1.setType(new ProductType(4L, "shoe"));
        prod1.setPrice(655.0);
        prod1.setColor("black");
        prod1.setSize(16);
        prod1.setAvailableCount(600);
        prod1.setSupplier(new Supplier(4L, "ABB retail"));
        when(dataServiceMock.findById(4L)).thenReturn(Optional.of(prod1));
        assertTrue(productService.getProductBySKU(4L).isPresent());
        assertEquals("Nike shoe", productService.getProductBySKU(4L).get().getName());
        assertEquals("Nike", productService.getProductBySKU(4L).get().getBrand().getName());
        assertEquals("shoe", productService.getProductBySKU(4L).get().getType().getName());
        assertEquals("655.0", String.valueOf(productService.getProductBySKU(4L).get().getPrice()));
    }
/**
     * business layer test with mock DB data
     */
business layer test with mock DB data
business layer test with mock DB data
@Test
    public void testGetProductBySku() {
        Product prod1 = new Product();
        prod1.setId(4L);
        prod1.setName("Nike shoe");
        prod1.setBrand(new Brand(4L, "Nike"));
        prod1.setType(new ProductType(4L, "shoe"));
        prod1.setPrice(655.0);
        prod1.setColor("black");
        prod1.setSize(16);
        prod1.setAvailableCount(600);
        prod1.setSupplier(new Supplier(4L, "ABB retail"));
        when(dataServiceMock.findById(4L)).thenReturn(Optional.of(prod1));
        assertTrue(productService.getProductBySKU(4L).isPresent());
        assertEquals("Nike shoe", productService.getProductBySKU(4L).get().getName());
        assertEquals("Nike", productService.getProductBySKU(4L).get().getBrand().getName());
        assertEquals("shoe", productService.getProductBySKU(4L).get().getType().getName());
        assertEquals("655.0", String.valueOf(productService.getProductBySKU(4L).get().getPrice()));
    }
@ Test public void testGetProductBySku ( ) { Product prod1 = new Product ( ) ; prod1 . setId ( 4L ) ; prod1 . setName ( "Nike shoe" ) ; prod1 . setBrand ( new Brand ( 4L , "Nike" ) ) ; prod1 . setType ( new ProductType ( 4L , "shoe" ) ) ; prod1 . setPrice ( 655.0 ) ; prod1 . setColor ( "black" ) ; prod1 . setSize ( 16 ) ; prod1 . setAvailableCount ( 600 ) ; prod1 . setSupplier ( new Supplier ( 4L , "ABB retail" ) ) ; when ( dataServiceMock . findById ( 4L ) ) . thenReturn ( Optional . of ( prod1 ) ) ; assertTrue ( productService . getProductBySKU ( 4L ) . isPresent ( ) ) ; assertEquals ( "Nike shoe" , productService . getProductBySKU ( 4L ) . get ( ) . getName ( ) ) ; assertEquals ( "Nike" , productService . getProductBySKU ( 4L ) . get ( ) . getBrand ( ) . getName ( ) ) ; assertEquals ( "shoe" , productService . getProductBySKU ( 4L ) . get ( ) . getType ( ) . getName ( ) ) ; assertEquals ( "655.0" , String . valueOf ( productService . getProductBySKU ( 4L ) . get ( ) . getPrice ( ) ) ) ; }
business layer test with mock DB data
business layer test with mock DB data