Commit 97983b66 authored by snamdeo's avatar snamdeo

Commiting after adding test cases to increase code coverage

parent adb72695
...@@ -35,7 +35,8 @@ public class Customer { ...@@ -35,7 +35,8 @@ public class Customer {
private Integer valetAmount ; private Integer valetAmount ;
public Customer(String firstName, String lastName, String emailId,Integer valetAmount) { public Customer(Integer id,String firstName, String lastName, String emailId,Integer valetAmount) {
this.id = id;
this.firstName = firstName; this.firstName = firstName;
this.lastName = lastName; this.lastName = lastName;
this.emailId = emailId; this.emailId = emailId;
......
package com.altimetrik.poc.dto; package com.altimetrik.poc.dto;
import com.altimetrik.poc.dto.Customer;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
...@@ -21,6 +22,7 @@ public class OrderDetails { ...@@ -21,6 +22,7 @@ public class OrderDetails {
private Integer shippingPrice; private Integer shippingPrice;
private Integer totalPrice; private Integer totalPrice;
private Integer itemsPrice; private Integer itemsPrice;
private Integer reference;
private Integer[] productIds; private Integer[] productIds;
@ManyToOne @ManyToOne
private Customer customer; private Customer customer;
......
...@@ -25,7 +25,7 @@ class ShoppingCartControllerTest { ...@@ -25,7 +25,7 @@ class ShoppingCartControllerTest {
public void getProducts(){ public void getProducts(){
when(shoppingCartServices.getProducts()).thenReturn(Stream.of( when(shoppingCartServices.getProducts()).thenReturn(Stream.of(
new OrderDetails(300,3761,0,0,42,342,new Integer[2],new Customer())).collect(Collectors.toList())); new OrderDetails(300,3761,0,0,42,342,667,new Integer[2],new Customer())).collect(Collectors.toList()));
assertEquals("200 OK",shoppingCartController.getProducts().getStatusCode().toString()); assertEquals("200 OK",shoppingCartController.getProducts().getStatusCode().toString());
...@@ -33,7 +33,8 @@ class ShoppingCartControllerTest { ...@@ -33,7 +33,8 @@ class ShoppingCartControllerTest {
@Test @Test
public void addProducts(){ public void addProducts(){
OrderDetails pd = new OrderDetails(300,3721,4356,6456,6565,454, new Integer[43], new Customer()); OrderDetails pd = new OrderDetails(300,3721,4356,6456,6565,454,667, new Integer[43], new Customer());
Customer c = new Customer();
shoppingCartController.addProducts(pd); shoppingCartController.addProducts(pd);
verify(shoppingCartServices,times(1)).addProducts(pd); verify(shoppingCartServices,times(1)).addProducts(pd);
} }
......
...@@ -3,6 +3,7 @@ import com.altimetrik.poc.dto.Customer; ...@@ -3,6 +3,7 @@ import com.altimetrik.poc.dto.Customer;
import com.altimetrik.poc.dto.OrderDetails; import com.altimetrik.poc.dto.OrderDetails;
import com.altimetrik.poc.dto.ProductDetails; import com.altimetrik.poc.dto.ProductDetails;
import com.altimetrik.poc.repository.ShoppingCartRepository; import com.altimetrik.poc.repository.ShoppingCartRepository;
import com.altimetrik.poc.repository.UserLoggedInRepository;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
...@@ -24,6 +25,9 @@ public class ShoppingCartServicesTest { ...@@ -24,6 +25,9 @@ public class ShoppingCartServicesTest {
@Autowired @Autowired
ShoppingCartServices shoppingCartServices; ShoppingCartServices shoppingCartServices;
@MockBean
UserLoggedInRepository userLoggedInRepository;
@MockBean @MockBean
List<ProductDetails> lpd; List<ProductDetails> lpd;
...@@ -32,7 +36,7 @@ public class ShoppingCartServicesTest { ...@@ -32,7 +36,7 @@ public class ShoppingCartServicesTest {
when(shoppingCartRepository.findAll()).thenReturn(Stream.of( when(shoppingCartRepository.findAll()).thenReturn(Stream.of(
new OrderDetails(300,3761,0,0,42,342,new Integer[2],new Customer())).collect(Collectors.toList())); new OrderDetails(123,300,3761,0,0,42,342,new Integer[2],new Customer())).collect(Collectors.toList()));
assertEquals(1,shoppingCartServices.getProducts().size()); assertEquals(1,shoppingCartServices.getProducts().size());
...@@ -40,9 +44,9 @@ public class ShoppingCartServicesTest { ...@@ -40,9 +44,9 @@ public class ShoppingCartServicesTest {
} }
@Test @Test
public void addProducts(){ public void addProducts(){
Customer c = new Customer(1,"Shishir", "Namdeo","shishirnamdeo220@gmail.com",0);
when(userLoggedInRepository.findByReference(Customer.refer)).thenReturn(c);
OrderDetails pd = new OrderDetails(300,3721,4356,6456,6565,454, new Integer[43], new Customer()); OrderDetails pd = new OrderDetails(123,3721,4356,6456,6565,454, 667,new Integer[43], new Customer());
shoppingCartServices.addProducts(pd); shoppingCartServices.addProducts(pd);
verify(shoppingCartRepository,times(1)).save(pd); verify(shoppingCartRepository,times(1)).save(pd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment