Commit ce7fee8c authored by Bhargava Rellu's avatar Bhargava Rellu

Changes according to the review comments,

Added test cases.
parent 4abed227
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
build/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
\ No newline at end of file
...@@ -2,7 +2,7 @@ plugins { ...@@ -2,7 +2,7 @@ plugins {
id 'java' id 'java'
} }
group 'org.example' group 'com.retailstore.ordermanagement'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
repositories { repositories {
...@@ -19,6 +19,8 @@ dependencies { ...@@ -19,6 +19,8 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.22' annotationProcessor 'org.projectlombok:lombok:1.18.22'
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.2' testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.2'
// https://mvnrepository.com/artifact/org.mockito/mockito-core
testImplementation group: 'org.mockito', name: 'mockito-inline', version: '3.4.4'
} }
test { test {
......
package com.retail_store.order_management.application; package com.retailstore.ordermanagement.application;
import com.retail_store.order_management.service.RetailStore; import com.retailstore.ordermanagement.service.RetailStoreService;
import com.retail_store.order_management.service.RetailStoreService; import com.retailstore.ordermanagement.service.RetailStoreServiceImpl;
import com.retailstore.ordermanagement.utils.DBUtil;
import lombok.extern.java.Log;
import java.sql.SQLException;
import java.util.Scanner; import java.util.Scanner;
import java.util.logging.Logger;
import static com.retail_store.order_management.utils.Utility.getInt; import static com.retailstore.ordermanagement.utils.InputUtil.validateInputNumber;
/** /**
* The project run starts from here * The project run starts from here
*/ */
@Log
public class OrderManagement { public class OrderManagement {
private Scanner scanner; private Scanner scanner;
private final Logger logger;
/** /**
* No-Arg Constructor for class OrderManagement with their private * No-Arg Constructor for class OrderManagement with their private
...@@ -23,7 +25,6 @@ public class OrderManagement { ...@@ -23,7 +25,6 @@ public class OrderManagement {
System.setProperty("java.util.logging.SimpleFormatter.format", System.setProperty("java.util.logging.SimpleFormatter.format",
"%5$s %n"); "%5$s %n");
this.scanner = new Scanner(System.in); this.scanner = new Scanner(System.in);
this.logger = Logger.getLogger(OrderManagement.class.getName());
} }
/** /**
...@@ -40,44 +41,49 @@ public class OrderManagement { ...@@ -40,44 +41,49 @@ public class OrderManagement {
String enterForMenu = "Please enter 5 for menu"; String enterForMenu = "Please enter 5 for menu";
boolean flag = true; boolean flag = true;
logger.info("Welcome to RetailStore Business Management"); log.info("Welcome to RetailStore Business Management");
RetailStore gap = new RetailStoreService(); RetailStoreService gap = new RetailStoreServiceImpl();
String menu = "\n------------------------\nMenu\n------------------------\n" + String menu = "\n------------------------\nMenu\n------------------------\n" +
option1 + "\n------------------------\n" + option1 + "\n------------------------\n" +
option2 + "\n------------------------\n" + option2 + "\n------------------------\n" +
option3 + "\n------------------------\n" + option3 + "\n------------------------\n" +
option4; option4;
logger.info(menu); log.info(menu);
while (flag) { while (flag) {
int menuOption; int menuOption;
menuOption = getInt(); menuOption = validateInputNumber();
switch (menuOption) { switch (menuOption) {
case 1: case 1:
gap.addProducts(); gap.addProducts();
logger.info("\n------------------------\nPlease enter 5 for menu\n------------------------\n" + log.info("\n------------------------\n" + enterForMenu + "\n------------------------\n" +
"To exit please enter 4\n------------------------\n" + toExit + "\n------------------------\n" +
"To Add more enter 1\n------------------------\n"); toAddMore + "\n------------------------\n");
break; break;
case 2: case 2:
gap.placeOrders(); gap.placeOrders();
logger.info("\n------------------------\nPlease enter 5 for menu\n------------------------\n" + log.info("\n------------------------\n" + enterForMenu + "\n------------------------\n" +
"To exit please enter 4"); toExit);
break; break;
case 3: case 3:
gap.showOrders(); gap.showOrders();
logger.info("\n------------------------\nPlease enter 5 for menu\n------------------------\n" + log.info("\n------------------------\n" + enterForMenu + "\n------------------------\n" +
"To exit please enter 4"); toExit);
break; break;
case 4: case 4:
logger.info("Good Bye."); log.info("Good Bye.");
flag = false; flag = false;
try {
DBUtil.getConnection().close();
} catch (SQLException e) {
log.warning(e.getMessage());
}
break; break;
case 5: case 5:
logger.info(menu); log.info(menu);
break; break;
default: default:
logger.warning("\n------------------------\nPlease enter valid menu option\n------------------------\n"); log.warning("\n------------------------\nPlease enter valid menu option\n------------------------\n");
logger.info(menu); log.info(menu);
} }
} }
} }
......
package com.retail_store.order_management.constants; package com.retailstore.ordermanagement.constants;
/** /**
* Here using Enum class types as the requirement has constants to * Here using Enum class types as the requirement has constants to
......
package com.retail_store.order_management.constants; package com.retailstore.ordermanagement.constants;
/** /**
* Enumeration class of name Color * Enumeration class of name Color
......
package com.retail_store.order_management.constants; package com.retailstore.ordermanagement.constants;
/** /**
* Enumeration class of name Gender * Enumeration class of name Gender
...@@ -11,7 +11,7 @@ public enum Gender { ...@@ -11,7 +11,7 @@ public enum Gender {
*/ */
EXIT(0, "exit"), MEN(1, "Men"), WOMEN(2, "Women"); EXIT(0, "exit"), MEN(1, "Men"), WOMEN(2, "Women");
int option; int option;
String gender; String getName;
/** /**
* Method is used to return option value * Method is used to return option value
...@@ -30,7 +30,7 @@ public enum Gender { ...@@ -30,7 +30,7 @@ public enum Gender {
* @return * @return
*/ */
public String getGender() { public String getGender() {
return gender; return getName;
} }
/** /**
...@@ -41,6 +41,6 @@ public enum Gender { ...@@ -41,6 +41,6 @@ public enum Gender {
*/ */
Gender(int option, String gender) { Gender(int option, String gender) {
this.option = option; this.option = option;
this.gender = gender; this.getName = gender;
} }
} }
package com.retail_store.order_management.constants; package com.retailstore.ordermanagement.constants;
/** /**
* Enumeration class name Size * Enumeration class name Size
......
package com.retail_store.order_management.model; package com.retailstore.ordermanagement.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
......
package com.retail_store.order_management.model; package com.retailstore.ordermanagement.model;
import com.retail_store.order_management.constants.Category; import com.retailstore.ordermanagement.constants.Category;
import com.retail_store.order_management.constants.Color; import com.retailstore.ordermanagement.constants.Color;
import com.retail_store.order_management.constants.Gender; import com.retailstore.ordermanagement.constants.Gender;
import com.retail_store.order_management.constants.Size; import com.retailstore.ordermanagement.constants.Size;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
......
package com.retail_store.order_management.model; package com.retailstore.ordermanagement.model;
import com.retail_store.order_management.constants.Category; import com.retailstore.ordermanagement.constants.Category;
import com.retail_store.order_management.constants.Color; import com.retailstore.ordermanagement.constants.Color;
import com.retail_store.order_management.constants.Gender; import com.retailstore.ordermanagement.constants.Gender;
import com.retail_store.order_management.constants.Size; import com.retailstore.ordermanagement.constants.Size;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
......
...@@ -14,7 +14,7 @@ import java.util.Map; ...@@ -14,7 +14,7 @@ import java.util.Map;
* This is an interface to filter the products according to * This is an interface to filter the products according to
* respective of taken methods in this interface * respective of taken methods in this interface
*/ */
public interface ProductFilter { public interface ProductService {
/** /**
* This is an abstract method gives the * This is an abstract method gives the
* categories of product according selection of gender type * categories of product according selection of gender type
......
...@@ -12,7 +12,7 @@ import java.util.Collection; ...@@ -12,7 +12,7 @@ import java.util.Collection;
* In this interface there present different abstract methods to perform * In this interface there present different abstract methods to perform
* various functions of the project * various functions of the project
*/ */
public interface RetailStore { public interface RetailStoreService {
/** /**
* This abstract method is used to add the products seemly according to the * This abstract method is used to add the products seemly according to the
* given process in the console, if added then shows message accordingly * given process in the console, if added then shows message accordingly
......
...@@ -9,14 +9,14 @@ import java.sql.SQLException; ...@@ -9,14 +9,14 @@ import java.sql.SQLException;
* This is a final class in which all the configurations of the database are present to * This is a final class in which all the configurations of the database are present to
* establish the connection to the database to the project * establish the connection to the database to the project
*/ */
public final class Database { public final class DBUtil {
private static Connection connection; private static Connection connection;
/** /**
* Private constructor that will not * Private constructor that will not
* allow to create object * allow to create object
*/ */
private Database() { private DBUtil() {
} }
/** /**
......
...@@ -11,17 +11,20 @@ import org.junit.jupiter.api.Test; ...@@ -11,17 +11,20 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mock; import org.mockito.Mock;
import java.sql.Connection; import java.sql.Connection;
import java.util.*; import java.util.LinkedHashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
class ProductFilterTest { class ProductServiceTest {
@Mock @Mock
Connection connection; Connection connection;
RetailStoreService service; RetailStoreServiceImpl service;
@BeforeEach @BeforeEach
void createretailsStoreObject() { void createretailsStoreObject() {
service = new RetailStoreService(); service = new RetailStoreServiceImpl();
} }
@AfterEach @AfterEach
...@@ -31,7 +34,7 @@ class ProductFilterTest { ...@@ -31,7 +34,7 @@ class ProductFilterTest {
@Test @Test
void getCategoriesByGenderTest() { void getCategoriesByGenderTest() {
Map<Integer, Category> categoryMap = new HashMap<>(); Map<Integer, Category> categoryMap = new LinkedHashMap<>();
categoryMap.put(1, Category.SWEATSHIRTS); categoryMap.put(1, Category.SWEATSHIRTS);
categoryMap.put(2, Category.T_SHIRTS); categoryMap.put(2, Category.T_SHIRTS);
categoryMap.put(3, Category.SHIRTS); categoryMap.put(3, Category.SHIRTS);
...@@ -57,7 +60,7 @@ class ProductFilterTest { ...@@ -57,7 +60,7 @@ class ProductFilterTest {
@Test @Test
void getColorsByGenderAndCategoryTest() { void getColorsByGenderAndCategoryTest() {
Map<Integer, Color> colorMap = new HashMap<>(); Map<Integer, Color> colorMap = new LinkedHashMap<>();
colorMap.put(1, Color.BLUE); colorMap.put(1, Color.BLUE);
colorMap.put(2, Color.GREY); colorMap.put(2, Color.GREY);
colorMap.put(3, Color.BLACK); colorMap.put(3, Color.BLACK);
...@@ -69,7 +72,7 @@ class ProductFilterTest { ...@@ -69,7 +72,7 @@ class ProductFilterTest {
@Test @Test
void getOrdersTest() { void getOrdersTest() {
List<Order> orderList = new ArrayList<>(); List<Order> orderList = new ArrayList<>();
Map<Integer, Order> ordersMap = new HashMap<>(); Map<Integer, Order> ordersMap = new LinkedHashMap<>();
Assertions.assertEquals(ordersMap, service.getOrders(connection)); Assertions.assertEquals(ordersMap, service.getOrders(connection));
} }
} }
\ No newline at end of file
...@@ -4,83 +4,49 @@ import com.retailstore.ordermanagement.constants.Category; ...@@ -4,83 +4,49 @@ import com.retailstore.ordermanagement.constants.Category;
import com.retailstore.ordermanagement.constants.Color; import com.retailstore.ordermanagement.constants.Color;
import com.retailstore.ordermanagement.constants.Gender; import com.retailstore.ordermanagement.constants.Gender;
import com.retailstore.ordermanagement.constants.Size; import com.retailstore.ordermanagement.constants.Size;
import com.retailstore.ordermanagement.model.Order; import com.retailstore.ordermanagement.utils.InputUtil;
import com.retailstore.ordermanagement.model.OrderedProduct;
import com.retailstore.ordermanagement.utils.Utility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.Spy;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.sql.Connection; import java.sql.Connection;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Scanner;
class RetailStoreTest { class RetailStoreServiceTest {
@Mock @Mock
Connection connection; Connection connection;
RetailStoreService service; RetailStoreServiceImpl service;
@Spy
@InjectMocks
Utility utility;
@BeforeEach
void createretailsStoreObject() {
service = new RetailStoreService();
}
@AfterEach
void removeretailsStoreObject() {
service = null;
}
@Test @Test
void addProducts() { void addProducts() {
LinkedHashMap<Size, Integer> sizeMap = new LinkedHashMap<>(); Scanner scanner = Mockito.mock(Scanner.class);
Map<Size, Integer> sizeMap = new LinkedHashMap<>();
sizeMap.put(Size.S, 2); sizeMap.put(Size.S, 2);
sizeMap.put(Size.M, 2); sizeMap.put(Size.M, 2);
sizeMap.put(Size.L, 2); sizeMap.put(Size.L, 2);
sizeMap.put(Size.XL, 2); sizeMap.put(Size.XL, 2);
sizeMap.put(Size.XXL, 2); sizeMap.put(Size.XXL, 2);
Mockito.when(utility.productIdGenerator()).thenReturn("TestMethod" + LocalDate.now() + LocalTime.now()); try (MockedStatic<InputUtil> inputUtil = Mockito.mockStatic(InputUtil.class)) {
Mockito.when(Utility.getScanner().nextLine()).thenReturn("TestProduct");
Mockito.when(Utility.getCategory(true, "Test check")).thenReturn(Category.JEANS); inputUtil.when(() -> InputUtil.productIdGenerator()).thenReturn("TestMethod" + LocalDate.now() + LocalTime.now());
Mockito.when(Utility.getColor(true, "Test check")).thenReturn(Color.BLACK); String input = "Test Input";
Mockito.when(Utility.getGender(true, "Test check")).thenReturn(Gender.WOMEN); InputStream in = new ByteArrayInputStream(input.getBytes());
Mockito.when(Utility.getDouble(true, "Test price")).thenReturn(1350.00); System.setIn(in);
Mockito.when(Utility.getProductSizes()).thenReturn(sizeMap); inputUtil.when(() -> InputUtil.validateInputNumber()).thenReturn(2);
inputUtil.when(() -> InputUtil.getCategory(true, "Test check")).thenReturn(Category.JEANS);
inputUtil.when(() -> InputUtil.getColor(true, "Test check")).thenReturn(Color.BLACK);
inputUtil.when(() -> InputUtil.getGender(true, "Test check")).thenReturn(Gender.WOMEN);
inputUtil.when(() -> InputUtil.validateInputPrice(true, "Test price")).thenReturn(1350.00);
inputUtil.when(() -> InputUtil.getProductSizes()).thenReturn(sizeMap);
}
Assertions.assertEquals(true, service.addProducts()); Assertions.assertEquals(true, service.addProducts());
} }
@Test
void placeOrders() {
}
@Test
void showOrdersTest() {
Map<Integer, Order> ordersMap = Mockito.mock(LinkedHashMap.class);
List<OrderedProduct> orderedProductList = Mockito.mock(ArrayList.class);
ordersMap.put(1, new Order("10bc46f3#Order", LocalDate.now(), LocalTime.now(), "Customer", "9633214574", 2500.00, new ArrayList<OrderedProduct>()));
Mockito.when(service.getOrders(connection)).thenReturn(ordersMap);
}
@Test
void createOrder() {
ArrayList<OrderedProduct> orderedProducts = new ArrayList<>();
orderedProducts.add(new OrderedProduct("test1", "testname", Category.JEANS, Color.BLACK, 1200.00, Gender.MEN, Size.L, 2));
// Mockito.when(getGender(true, "Test check")).thenReturn(Gender.WOMEN);
}
@Test
void addProductToCart() {
}
} }
\ No newline at end of file
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