diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f01843d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.idea/*
+.out/
+*.iml
+target/
\ No newline at end of file
diff --git a/WhatsApp.md b/WhatsApp.md
new file mode 100644
index 0000000..a399f27
--- /dev/null
+++ b/WhatsApp.md
@@ -0,0 +1,53 @@
+### WhatsAPP ###
+
+Feature: Mute notification for
+ In order to test mute notification
+ As an user
+ I want to validate if we can mute the notifications.
+
+ Scenario: Register Whatsapp Number
+ Given App Whatsapp installed on the Mobile Phone
+ When the user click on the app icon
+ And the mobile number is valid
+ Then enter the mobile number on the app
+ And receive the authentication code
+
+ Scenario: Mute Notifications
+ Given A valid number with a channel group added before.
+ When the user click on chats tab
+ And click on the group chat
+ And the user click on the three dots right button
+ And click on Mute Notifications
+ Then enter the period of time to be muted
+ And click on OK button
+
+Feature: Starred Messages
+ In order to test starred messages
+ As an user
+ I want to validate if we can see the starred messages.
+
+ Scenario: Starred Messages
+ Given App Whatsapp installed on the Mobile Phone and Registered
+ When the user click on chats tab
+ And click on the group chat
+ Then click on any message and hold the message
+ And click on the star icon
+
+ Scenario: See Starred Messages
+ Given A user with starred messages
+ When the user click on the three dots right button
+ And the user click on Starred Messages
+ Then see the messages starred before.
+
+Feature: Search
+ In order to test search
+ As an user
+ I want to validate if we can get a list of words searched.
+
+ Scenario: Search
+ Given App Whatsapp installed on the Mobile Phone and Registered
+ When the user click on search button on the right corner
+ Then enter any word to search
+ And while typing the word it should appear on the list.
+
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..082d2c3
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,57 @@
+
+
+ 4.0.0
+
+ qa-recruting
+ hsa
+ 1.0-SNAPSHOT
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ com.typesafe
+ config
+ 1.3.2
+
+
+ org.jeasy
+ easy-rules-core
+ 3.3.0
+
+
+ org.jeasy
+ easy-rules-mvel
+ 3.3.0
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.5
+
+
+ org.slf4j
+ slf4j-simple
+ 1.6.4
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 1.8
+ 1.8
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/BasketFromConfig.java b/src/main/java/BasketFromConfig.java
new file mode 100644
index 0000000..72e2559
--- /dev/null
+++ b/src/main/java/BasketFromConfig.java
@@ -0,0 +1,64 @@
+import java.util.HashMap;
+
+public class BasketFromConfig implements RulesPromotion{
+
+ private HashMap catalog;
+ private HashMap basketList;
+ private double total;
+
+ public BasketFromConfig(HashMap config) {
+ this.catalog = config;
+ basketList = new HashMap<>();
+ total = 0;
+ }
+
+ public void addItemToBasket(String productName){
+ if(!productName.equals("")){
+ Item item = catalog.get(productName);
+ if(basketList.get(productName) != null){
+ int aux = basketList.get(productName).getQuantity();
+ item.setQuantity(++aux);
+ basketList.put(productName,item);
+ }else{
+ int quantity = 1;
+ item.setQuantity(quantity);
+ basketList.put(productName,item);
+ }
+ }
+ }
+
+ public double checkTotal(){
+
+ total = 0;
+
+ basketList.forEach((name,item) -> {
+ int quantity = item.getQuantity();
+ if (item.getPromotions()!=null){
+ total = total + item.checkPromotion(quantity);
+ }else {
+ total = total + (quantity * item.getPrice());
+ }
+ });
+
+ return total;
+ }
+
+ public double price(String listOfItems){
+
+ basketList = new HashMap<>();
+ total = 0;
+
+ char[] arrayItems = listOfItems.toCharArray();
+
+ if (arrayItems.length != 0){
+ for (char sku:arrayItems) {
+ String productName = String.valueOf(sku);
+ addItemToBasket(productName);
+ }
+ }
+
+ return checkTotal();
+ }
+
+
+}
diff --git a/src/main/java/BasketFromRules.java b/src/main/java/BasketFromRules.java
new file mode 100644
index 0000000..e2853c7
--- /dev/null
+++ b/src/main/java/BasketFromRules.java
@@ -0,0 +1,142 @@
+import org.jeasy.rules.api.Facts;
+import org.jeasy.rules.api.Rule;
+import org.jeasy.rules.api.Rules;
+import org.jeasy.rules.api.RulesEngine;
+import org.jeasy.rules.core.DefaultRulesEngine;
+import org.jeasy.rules.mvel.MVELRule;
+import org.jeasy.rules.mvel.MVELRuleFactory;
+import org.jeasy.rules.support.YamlRuleDefinitionReader;
+
+import java.io.FileReader;
+import java.util.HashMap;
+
+
+public class BasketFromRules implements RulesPromotion{
+
+ private HashMap basketList;
+ private double total;
+
+ private static Rules rules;
+
+ public static Rules getRulesYML() {
+
+ if (rules==null) {
+
+ MVELRuleFactory ruleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());
+
+ try {
+
+ rules = ruleFactory.createRules(new FileReader("src/test/resources/rules.yml"));
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return rules;
+ }
+ public static Rules getRulesAPI() {
+
+ if (rules==null) {
+
+ Rule itemA = new MVELRule()
+ .name("item A")
+ .description("1 item A for 50")
+ .when("item.getName() == 'A'")
+ .then("item.setPrice(item.getQuantity() * 50)");
+
+ Rule itemB = new MVELRule()
+ .name("item B")
+ .description("1 item B for 30")
+ .when("item.getName() == 'B'")
+ .then("item.setPrice(item.getQuantity() * 30)");
+
+ Rule itemC = new MVELRule()
+ .name("item C")
+ .description("1 item C for 20")
+ .when("item.getName() == 'C'")
+ .then("item.setPrice(item.getQuantity() * 20)");
+
+ Rule itemD = new MVELRule()
+ .name("item D")
+ .description("1 item D for 15")
+ .when("item.getName() == 'D'")
+ .then("item.setPrice(item.getQuantity() * 15)");
+
+ Rule promoA = new MVELRule()
+ .name("promo A")
+ .description("3 item A for 130")
+ .when("item.getName().equals('A') && item.getQuantity() / 3 >= 1")
+ .then("int q = item.getQuantity() / 3; item.setPrice(item.getPrice() - q * 20)");
+
+ Rule promoB = new MVELRule()
+ .name("promo B")
+ .description("2 item b for 45")
+ .when("item.getName().equals('B') && item.getQuantity() / 2 >= 1")
+ .then("int q = item.getQuantity() /2; item.setPrice(item.getPrice() - q * 15)");
+
+
+
+ rules = new Rules();
+ rules.register(itemA);
+ rules.register(itemB);
+ rules.register(itemC);
+ rules.register(itemD);
+ rules.register(promoA);
+ rules.register(promoB);
+ }
+ return rules;
+ }
+
+
+ public BasketFromRules(){
+
+ basketList = new HashMap<>();
+ total = 0;
+
+ }
+
+ private double calculatePrice(Item item){
+ RulesEngine rulesEngine = new DefaultRulesEngine();
+ Facts facts = new Facts();
+
+ facts.put("item", item);
+ rulesEngine.fire(rules, facts);
+
+ return item.getPrice();
+ }
+
+ public void addItemToBasket(String productName) {
+ if (productName.length() != 0){
+ Item scannedItem = new Item(productName);
+ Item item = basketList.get(scannedItem.getName());
+ if (item == null) {
+ scannedItem.setQuantity(1);
+ basketList.put(productName, scannedItem);
+ } else {
+ Integer quantity = item.getQuantity();
+ item.setQuantity(++quantity);
+ }
+ }
+
+ }
+
+ public double checkTotal(){
+ total = 0;
+ for (Item item : basketList.values()) {
+ total = total + calculatePrice(item);
+ }
+ return total;
+
+ }
+
+ public double price(String productName) {
+ basketList = new HashMap<>();
+ total = 0;
+
+ for (int i = 0; i < productName.length(); i++) {
+ addItemToBasket(productName.substring(i, i + 1));
+ }
+ return checkTotal();
+
+ }
+}
diff --git a/src/main/java/CatalogFromConfig.java b/src/main/java/CatalogFromConfig.java
new file mode 100644
index 0000000..606c26a
--- /dev/null
+++ b/src/main/java/CatalogFromConfig.java
@@ -0,0 +1,58 @@
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigFactory;
+import com.typesafe.config.ConfigObject;
+import com.typesafe.config.ConfigValue;
+
+import java.util.HashMap;
+
+public class CatalogFromConfig {
+
+ private static Config defaultConfig;
+ private static HashMap catalog;
+
+ private static Config getConfig(String file) {
+ if (defaultConfig==null) {
+ defaultConfig = ConfigFactory.parseResources(file);
+
+ }
+ return defaultConfig;
+ }
+
+ public HashMap getListOfItems(String file){
+
+ if (catalog ==null) {
+
+ defaultConfig = getConfig(file);
+
+ final ConfigValue configItems = defaultConfig.getObject("products");
+
+ catalog = new HashMap<>(((ConfigObject) configItems).size());
+
+ ((ConfigObject) configItems).keySet().forEach(pname -> {
+
+ ConfigObject productConfig = ((ConfigObject) configItems).toConfig().getObject(pname);
+ String productName = productConfig.get("productName").render().replaceAll("^\"|\"$", "");
+ String productPrice = productConfig.get("productPrice").render();
+
+ Item item;
+ Promotion promotion;
+
+ if (productConfig.containsKey("promotion")){
+ ConfigObject promotionConfig = (ConfigObject) productConfig.get("promotion");
+ String promoName = promotionConfig.get("promoName").render().replaceAll("^\"|\"$", "");
+ String promoNroItems = promotionConfig.get("promoNroItems").render();
+ String promoPrice = promotionConfig.get("promoPrice").render();
+ promotion = new Promotion(promoName,Integer.parseInt(promoNroItems),Double.parseDouble(promoPrice));
+ item = new Item(productName,Double.parseDouble(productPrice),promotion);
+ }else{
+ item = new Item(productName,Double.parseDouble(productPrice));
+ }
+
+ catalog.put(item.getName(),item);
+
+ });
+
+ }
+ return catalog;
+ }
+}
diff --git a/src/main/java/Item.java b/src/main/java/Item.java
new file mode 100644
index 0000000..388bbda
--- /dev/null
+++ b/src/main/java/Item.java
@@ -0,0 +1,75 @@
+public class Item {
+
+ private String name;
+ private double price;
+ private Promotion promotions;
+ private int quantity;
+
+ public Item(String name, double price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ public Item(String name, double price, Promotion promotion) {
+ this.name = name;
+ this.price = price;
+ this.promotions = promotion;
+ }
+
+ public Item(String productName) {
+ this.name = productName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ public Promotion getPromotions() {
+ return promotions;
+ }
+
+ public void setPromotions(Promotion promotions) {
+ this.promotions = promotions;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+
+ public double checkPromotion(int quantity){
+
+ double total = 0;
+
+ if (quantity < this.promotions.getNro_items()){
+ total = total + (quantity * this.price);
+ }else{
+ while (quantity >= this.promotions.getNro_items()){
+ if(quantity>=this.promotions.getNro_items()){
+ total = total + this.promotions.getPrice();
+ }else{
+ total = total + (quantity * this.price);
+ }
+ quantity = quantity-this.promotions.getNro_items();
+ }
+ total = total + (quantity * this.price);
+ }
+
+ return total;
+ }
+}
diff --git a/src/main/java/Promotion.java b/src/main/java/Promotion.java
new file mode 100644
index 0000000..c491046
--- /dev/null
+++ b/src/main/java/Promotion.java
@@ -0,0 +1,36 @@
+public class Promotion {
+
+ private String name;
+ private int nro_items;
+ private double price;
+
+ public Promotion(String name, int nro_items, double price) {
+ this.name = name;
+ this.nro_items = nro_items;
+ this.price = price;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getNro_items() {
+ return nro_items;
+ }
+
+ public void setNro_items(int nro_items) {
+ this.nro_items = nro_items;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+}
diff --git a/src/main/java/RulesPromotion.java b/src/main/java/RulesPromotion.java
new file mode 100644
index 0000000..b430244
--- /dev/null
+++ b/src/main/java/RulesPromotion.java
@@ -0,0 +1,7 @@
+public interface RulesPromotion {
+
+ double checkTotal();
+
+ double price(String items);
+
+}
diff --git a/src/main/resources/catalog.conf b/src/main/resources/catalog.conf
new file mode 100644
index 0000000..ae5d4aa
--- /dev/null
+++ b/src/main/resources/catalog.conf
@@ -0,0 +1,30 @@
+{
+ products: {
+ itemA: {
+ productName: A,
+ productPrice: 50,
+ promotion: {
+ promoName: promoA,
+ promoNroItems: 3,
+ promoPrice: 130
+ }
+ },
+ itemB: {
+ productName: B,
+ productPrice: 30,
+ promotion: {
+ promoName: promoB,
+ promoNroItems: 2,
+ promoPrice: 45
+ }
+ },
+ itemC: {
+ productName: C,
+ productPrice: 20
+ },
+ itemD: {
+ productName: D,
+ productPrice: 15
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/catalog2.conf b/src/main/resources/catalog2.conf
new file mode 100644
index 0000000..dd9df99
--- /dev/null
+++ b/src/main/resources/catalog2.conf
@@ -0,0 +1,30 @@
+{
+ products: {
+ itemA: {
+ productName: A,
+ productPrice: 50,
+ promotion: {
+ promoName: promoA,
+ promoNroItems: 3,
+ promoPrice: 160
+ }
+ },
+ itemB: {
+ productName: B,
+ productPrice: 30,
+ promotion: {
+ promoName: promoB,
+ promoNroItems: 2,
+ promoPrice: 175
+ }
+ },
+ itemC: {
+ productName: C,
+ productPrice: 20
+ },
+ itemD: {
+ productName: D,
+ productPrice: 15
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/rules.yml b/src/main/resources/rules.yml
new file mode 100644
index 0000000..0ed78a9
--- /dev/null
+++ b/src/main/resources/rules.yml
@@ -0,0 +1,41 @@
+name: "Item A for 50"
+description: "Item A for 50"
+priority: 1
+condition: "item.name == 'A'"
+actions:
+ - "item.setPrice(item.quantity * 50);"
+---
+name: "Item B for 30"
+description: "Item B for 30"
+priority: 1
+condition: "item.name == 'B'"
+actions:
+ - "item.setPrice(item.quantity * 30);"
+---
+name: "Item C for 20"
+description: "Item C for 20"
+priority: 1
+condition: "item.name == 'C'"
+actions:
+ - "item.setPrice(item.quantity * 20);"
+---
+name: "Item D for 15"
+description: "Item D for 15"
+priority: 1
+condition: "item.name == 'D'"
+actions:
+ - "item.setPrice(item.quantity * 15);"
+---
+name: "Item A: 3 for 130"
+description: "buy three ‘A’s and they’ll cost you $130"
+priority: 2
+condition: "item.getName().equals('A') && item.getQuantity() / 3 >= 1"
+actions:
+ - "int quotient = item.getQuantity() / 3; item.setPrice(item.getPrice() - quotient * 20)"
+---
+name: "Item B: 2 for 45"
+description: "buy two ‘B’s and they’ll cost you $45"
+priority: 2
+condition: "item.getName().equals('B') && item.getQuantity() / 2 >= 1"
+actions:
+ - "int quotient = item.getQuantity() / 2; item.setPrice(item.getPrice() - quotient * 15)"
\ No newline at end of file
diff --git a/src/test/java/CheckoutTest.java b/src/test/java/CheckoutTest.java
new file mode 100644
index 0000000..2967518
--- /dev/null
+++ b/src/test/java/CheckoutTest.java
@@ -0,0 +1,70 @@
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+
+public class CheckoutTest {
+
+ static BasketFromConfig basket;
+ static HashMap config;
+
+ @BeforeClass
+ public static void beforeAllTestMethods() {
+
+ CatalogFromConfig loadCatalog = new CatalogFromConfig();
+ config = loadCatalog.getListOfItems("catalog.conf");
+
+ }
+
+ @Before
+ public void beforeEachMethod() {
+
+ basket = new BasketFromConfig(config);
+
+ }
+
+ @Test
+ public void test_totals(){
+ Assert.assertEquals(0, basket.price(""),0.0d);
+
+ Assert.assertEquals(50, basket.price("A"),0.0d);
+ Assert.assertEquals(80, basket.price("AB"),0.0d);
+ Assert.assertEquals(115, basket.price("CDBA"),0.0d);
+
+ Assert.assertEquals(100, basket.price("AA"),0.0d);
+ Assert.assertEquals(130, basket.price("AAA"),0.0d);
+ Assert.assertEquals(180, basket.price("AAAA"),0.0d);
+ Assert.assertEquals(230, basket.price("AAAAA"),0.0d);
+ Assert.assertEquals(260, basket.price("AAAAAA"),0.0d);
+
+ Assert.assertEquals(160, basket.price("AAAB"),0.0d);
+ Assert.assertEquals(175, basket.price("AAABB"),0.0d);
+ Assert.assertEquals(190, basket.price("AAABBD"),0.0d);
+ Assert.assertEquals(190, basket.price("DABABA"),0.0d);
+
+ }
+
+ @Test
+ public void test_incremental(){
+ basket.addItemToBasket("");
+ Assert.assertEquals(0,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(50,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("B");
+ Assert.assertEquals(80,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(130,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(160,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("B");
+ Assert.assertEquals(175,basket.checkTotal(),0.0d);
+ }
+}
diff --git a/src/test/java/CheckoutTest2.java b/src/test/java/CheckoutTest2.java
new file mode 100644
index 0000000..403dc2f
--- /dev/null
+++ b/src/test/java/CheckoutTest2.java
@@ -0,0 +1,74 @@
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+
+public class CheckoutTest2 {
+
+ static BasketFromConfig basket;
+ static HashMap config;
+
+ @BeforeClass
+ public static void beforeAllTestMethods() {
+
+ CatalogFromConfig loadCatalog = new CatalogFromConfig();
+ config = loadCatalog.getListOfItems("catalog2.conf");
+
+ }
+
+ @Before
+ public void beforeEachMethod() {
+
+ basket = new BasketFromConfig(config);
+
+ }
+
+ @Test
+ public void test_totals(){
+ Assert.assertEquals(0, basket.price(""),0.0d);
+
+ Assert.assertEquals(50, basket.price("A"),0.0d);
+ Assert.assertEquals(80, basket.price("AB"),0.0d);
+ Assert.assertEquals(115, basket.price("CDBA"),0.0d);
+
+ Assert.assertEquals(100, basket.price("AA"),0.0d);
+ Assert.assertEquals(160, basket.price("AAA"),0.0d);
+ Assert.assertEquals(210, basket.price("AAAA"),0.0d);
+ Assert.assertEquals(260, basket.price("AAAAA"),0.0d);
+ Assert.assertEquals(320, basket.price("AAAAAA"),0.0d);
+
+ Assert.assertEquals(190, basket.price("AAAB"),0.0d);
+ Assert.assertEquals(335, basket.price("AAABB"),0.0d);
+ Assert.assertEquals(350, basket.price("AAABBD"),0.0d);
+ Assert.assertEquals(350, basket.price("DABABA"),0.0d);
+
+ }
+
+ @Test
+ public void test_incremental(){
+ basket.addItemToBasket("");
+ Assert.assertEquals(0,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(50,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("B");
+ Assert.assertEquals(80,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(130,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ //Promotion A 3 x 160
+ Assert.assertEquals(190,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("B");
+ //Promotion A 3 x 160
+ //Promotion B 2 x 175
+ Assert.assertEquals(335,basket.checkTotal(),0.0d);
+ }
+
+}
diff --git a/src/test/java/CheckoutTest3.java b/src/test/java/CheckoutTest3.java
new file mode 100644
index 0000000..de5cad8
--- /dev/null
+++ b/src/test/java/CheckoutTest3.java
@@ -0,0 +1,66 @@
+import org.jeasy.rules.api.Rules;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class CheckoutTest3 {
+
+ static Rules rules;
+ BasketFromRules basket;
+
+ @BeforeClass
+ public static void beforeAllTestMethods() {
+
+ rules = BasketFromRules.getRulesAPI();
+ }
+
+ @Before
+ public void beforeEachMethod() {
+
+ basket = new BasketFromRules();
+
+ }
+ @Test
+ public void test_totals(){
+ Assert.assertEquals(0,basket.price(""),0.0d);
+
+ Assert.assertEquals(50,basket.price("A"),0.0d);
+ Assert.assertEquals(80,basket.price("AB"),0.0d);
+ Assert.assertEquals(115,basket.price("CDBA"),0.0d);
+
+ Assert.assertEquals(100,basket.price("AA"),0.0d);
+ Assert.assertEquals(130,basket.price("AAA"),0.0d);
+ Assert.assertEquals(180,basket.price("AAAA"),0.0d);
+ Assert.assertEquals(230,basket.price("AAAAA"),0.0d);
+ Assert.assertEquals(260,basket.price("AAAAAA"),0.0d);
+
+ Assert.assertEquals(160,basket.price("AAAB"),0.0d);
+ Assert.assertEquals(175,basket.price("AAABB"),0.0d);
+ Assert.assertEquals(190,basket.price("AAABBD"),0.0d);
+ Assert.assertEquals(190,basket.price("DABABA"),0.0d);
+
+ }
+
+ @Test
+ public void test_incremental(){
+ basket.addItemToBasket("");
+ Assert.assertEquals(0,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(50,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("B");
+ Assert.assertEquals(80,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(130,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(160,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("B");
+ Assert.assertEquals(175,basket.checkTotal(),0.0d);
+ }
+}
diff --git a/src/test/java/CheckoutTest4.java b/src/test/java/CheckoutTest4.java
new file mode 100644
index 0000000..53fe38a
--- /dev/null
+++ b/src/test/java/CheckoutTest4.java
@@ -0,0 +1,67 @@
+import org.jeasy.rules.api.Rules;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class CheckoutTest4 {
+
+ static Rules rules;
+ BasketFromRules basket;
+
+ @BeforeClass
+ public static void beforeAllTestMethods() {
+
+ rules = BasketFromRules.getRulesYML();
+ }
+
+ @Before
+ public void beforeEachMethod() {
+
+ basket = new BasketFromRules();
+
+ }
+
+ @Test
+ public void test_totals(){
+ Assert.assertEquals(0,basket.price(""),0.0d);
+
+ Assert.assertEquals(50,basket.price("A"),0.0d);
+ Assert.assertEquals(80,basket.price("AB"),0.0d);
+ Assert.assertEquals(115,basket.price("CDBA"),0.0d);
+
+ Assert.assertEquals(100,basket.price("AA"),0.0d);
+ Assert.assertEquals(130,basket.price("AAA"),0.0d);
+ Assert.assertEquals(180,basket.price("AAAA"),0.0d);
+ Assert.assertEquals(230,basket.price("AAAAA"),0.0d);
+ Assert.assertEquals(260,basket.price("AAAAAA"),0.0d);
+
+ Assert.assertEquals(160,basket.price("AAAB"),0.0d);
+ Assert.assertEquals(175,basket.price("AAABB"),0.0d);
+ Assert.assertEquals(190,basket.price("AAABBD"),0.0d);
+ Assert.assertEquals(190,basket.price("DABABA"),0.0d);
+
+ }
+
+ @Test
+ public void test_incremental(){
+ basket.addItemToBasket("");
+ Assert.assertEquals(0,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(50,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("B");
+ Assert.assertEquals(80,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(130,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("A");
+ Assert.assertEquals(160,basket.checkTotal(),0.0d);
+
+ basket.addItemToBasket("B");
+ Assert.assertEquals(175,basket.checkTotal(),0.0d);
+ }
+}
diff --git a/src/test/resources/catalog.conf b/src/test/resources/catalog.conf
new file mode 100644
index 0000000..ae5d4aa
--- /dev/null
+++ b/src/test/resources/catalog.conf
@@ -0,0 +1,30 @@
+{
+ products: {
+ itemA: {
+ productName: A,
+ productPrice: 50,
+ promotion: {
+ promoName: promoA,
+ promoNroItems: 3,
+ promoPrice: 130
+ }
+ },
+ itemB: {
+ productName: B,
+ productPrice: 30,
+ promotion: {
+ promoName: promoB,
+ promoNroItems: 2,
+ promoPrice: 45
+ }
+ },
+ itemC: {
+ productName: C,
+ productPrice: 20
+ },
+ itemD: {
+ productName: D,
+ productPrice: 15
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/catalog2.conf b/src/test/resources/catalog2.conf
new file mode 100644
index 0000000..dd9df99
--- /dev/null
+++ b/src/test/resources/catalog2.conf
@@ -0,0 +1,30 @@
+{
+ products: {
+ itemA: {
+ productName: A,
+ productPrice: 50,
+ promotion: {
+ promoName: promoA,
+ promoNroItems: 3,
+ promoPrice: 160
+ }
+ },
+ itemB: {
+ productName: B,
+ productPrice: 30,
+ promotion: {
+ promoName: promoB,
+ promoNroItems: 2,
+ promoPrice: 175
+ }
+ },
+ itemC: {
+ productName: C,
+ productPrice: 20
+ },
+ itemD: {
+ productName: D,
+ productPrice: 15
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/rules.yml b/src/test/resources/rules.yml
new file mode 100644
index 0000000..34aa419
--- /dev/null
+++ b/src/test/resources/rules.yml
@@ -0,0 +1,35 @@
+name: "item A"
+description: "1 item A for 50"
+condition: "item.getName() == 'A'"
+actions:
+ - "item.setPrice(item.getQuantity() * 50);"
+---
+name: "item B"
+description: "1 item B for 30"
+condition: "item.getName() == 'B'"
+actions:
+ - "item.setPrice(item.getQuantity() * 30);"
+---
+name: "item C"
+description: "1 item C for 20"
+condition: "item.getName() == 'C'"
+actions:
+ - "item.setPrice(item.getQuantity() * 20);"
+---
+name: "item D"
+description: "1 item D for 15"
+condition: "item.getName() == 'D'"
+actions:
+ - "item.setPrice(item.getQuantity() * 15);"
+---
+name: "promo A"
+description: "3 item A for 130"
+condition: "item.getName().equals('A') && item.getQuantity() / 3 >= 1"
+actions:
+ - "int quotient = item.getQuantity() / 3; item.setPrice(item.getPrice() - quotient * 20)"
+---
+name: "promo B"
+description: "2 item b for 45"
+condition: "item.getName().equals('B') && item.getQuantity() / 2 >= 1"
+actions:
+ - "int quotient = item.getQuantity() / 2; item.setPrice(item.getPrice() - quotient * 15)"
\ No newline at end of file