diff --git a/.classpath b/.classpath index f00af9b..f0a2fcb 100644 --- a/.classpath +++ b/.classpath @@ -1,10 +1,17 @@ + + - + + + + + + diff --git a/.gitignore b/.gitignore index 7920af5..30e0b36 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ _ReSharper.* bin obj -packages \ No newline at end of file +packages +/testclasses/ diff --git a/IntegrationER.txt b/IntegrationER.txt new file mode 100644 index 0000000..00193fc --- /dev/null +++ b/IntegrationER.txt @@ -0,0 +1,8 @@ +6.00,0.20 +21.00,0.70 +17.00,0.85 +18.00,0.90 +15.00,0.75 +19.00,0.95 +20.00,1.00 +17.00,0.85 \ No newline at end of file diff --git a/src/PrintingKioskSystem/Charge.java b/src/PrintingKioskSystem/Charge.java deleted file mode 100644 index 09b3dde..0000000 --- a/src/PrintingKioskSystem/Charge.java +++ /dev/null @@ -1,94 +0,0 @@ -package PrintingKioskSystem; - -import java.util.*; - -public class Charge { - - - private double charge, surcharge; - private String option,addOption; - private int quantity, addOpt, ttlQtt; - - public int getQuantity() - { - return quantity; - } - public Charge(String option, int quantity) { - this.option = option; - this.quantity = quantity; - } - - public Charge(int addOpt,int ttlQtt) { - this.addOpt = addOpt; - this.ttlQtt = ttlQtt; - } - - public double calNormalCharge() { - - switch(option) { - case "A": charge = getBlackAndWhiteCharge(quantity); break; - case "B": charge = getColourCharge(quantity); break; - case "C": charge = getNormalCharge(quantity); break; - case "D": charge = getPassportCharge(quantity); break; - } - return charge*quantity; - } - - public double calSurcharge() { - - surcharge = getAddOptSurcharge(); - return surcharge*ttlQtt; - } - - - public double getBlackAndWhiteCharge(int quantity){ - if(quantity < 5) - return 0.5; - else if (quantity >= 5 && quantity <= 10) - return 0.4; - else if(quantity >= 11 && quantity <= 20) - return 0.3; - else - return 0.2; - } - - public double getColourCharge(int quantity) { - if(quantity < 5) - return 1; - else if (quantity >= 5 && quantity <= 10) - return 0.9; - else if(quantity >= 11 && quantity <= 20) - return 0.8; - else - return 0.7; - } - - public double getNormalCharge(int quantity) { - if(quantity < 5) - return 1; - else if (quantity >= 5 && quantity <= 10) - return 0.9; - else if(quantity >= 11 && quantity <= 20) - return 0.75; - else - return 0.5; - } - - public double getPassportCharge(int quantity) { - if(quantity < 5) - return 1.2; - else if (quantity >= 5 && quantity <= 10) - return 0.95; - else if(quantity >= 11 && quantity <= 20) - return 0.85; - else - return 0.75; - } - - public double getAddOptSurcharge() { - if(addOpt==1) - return 0.1; - else - return 0.15; - } -} diff --git a/src/PrintingKioskSystem/Objects/IPrintingOrder.java b/src/PrintingKioskSystem/Objects/IPrintingOrder.java deleted file mode 100644 index fe514e8..0000000 --- a/src/PrintingKioskSystem/Objects/IPrintingOrder.java +++ /dev/null @@ -1,25 +0,0 @@ -package PrintingKioskSystem.Objects; - -public class IPrintingOrder { - - public PrintingType printingType; - public PrintingOption printingOpt; - public int quantity; - public double sum; - public boolean isHighQualityPaper=false; - public boolean isDesignEffect=false; - - public double getTotal() { - return 0; - } - public IPrintingOrder(PrintingType pType, PrintingOption pOpt, int qtt) - { - this.printingType=pType; - this.printingOpt=pOpt; - this.quantity=qtt; - } - - - -} - diff --git a/src/PrintingKioskSystem/Objects/PrintingDocument.java b/src/PrintingKioskSystem/Objects/PrintingDocument.java deleted file mode 100644 index 5d49c9e..0000000 --- a/src/PrintingKioskSystem/Objects/PrintingDocument.java +++ /dev/null @@ -1,47 +0,0 @@ -package PrintingKioskSystem.Objects; - -public class PrintingDocument extends IPrintingOrder { - - - public PrintingDocument(PrintingOption pOpt,int qtt) - { - super(PrintingType.Document,pOpt,qtt); - } - @Override - public double getTotal() - { - double charge=0; - if(printingOpt==PrintingOption.BlackWhite) - { - charge=getBlackAndWhiteCharge(); - } - else if(printingOpt==PrintingOption.Colour) - { - charge=getColourCharge(); - } - sum=quantity*charge; - return sum; - } - - public double getBlackAndWhiteCharge(){ - if(quantity < 5) - return 0.5; - else if (quantity >= 5 && quantity <= 10) - return 0.4; - else if(quantity >= 11 && quantity <= 20) - return 0.3; - else - return 0.2; - } - - public double getColourCharge() { - if(quantity < 5) - return 1; - else if (quantity >= 5 && quantity <= 10) - return 0.9; - else if(quantity >= 11 && quantity <= 20) - return 0.8; - else - return 0.7; - } -} diff --git a/src/PrintingKioskSystem/Objects/PrintingOption.java b/src/PrintingKioskSystem/Objects/PrintingOption.java deleted file mode 100644 index 44dee4f..0000000 --- a/src/PrintingKioskSystem/Objects/PrintingOption.java +++ /dev/null @@ -1,9 +0,0 @@ -package PrintingKioskSystem.Objects; - -public enum PrintingOption { - BlackWhite, - Colour, - Normal, - Passport, - Unknown -} diff --git a/src/PrintingKioskSystem/Objects/PrintingPhoto.java b/src/PrintingKioskSystem/Objects/PrintingPhoto.java deleted file mode 100644 index 70cb2fe..0000000 --- a/src/PrintingKioskSystem/Objects/PrintingPhoto.java +++ /dev/null @@ -1,59 +0,0 @@ -package PrintingKioskSystem.Objects; - -public class PrintingPhoto extends IPrintingOrder{ - - public boolean isHighQualityPaper=false; - public boolean isDesignEffect=false; - - public PrintingPhoto(PrintingOption pOpt,int qtt) - { - super(PrintingType.Photo,pOpt,qtt); - } - @Override - public double getTotal() - { - - double charge=0; - if(printingOpt==PrintingOption.Normal) - { - charge=getNormalCharge(); - } - else if(printingOpt==PrintingOption.Passport) - { - charge=getPassportCharge(); - } - if(isHighQualityPaper) - { - charge+=0.10; - } - if(isDesignEffect) - { - charge+=0.15; - } - sum=quantity*charge; - return sum; - } - - public double getNormalCharge() { - if(quantity < 5) - return 1; - else if (quantity >= 5 && quantity <= 10) - return 0.9; - else if(quantity >= 11 && quantity <= 20) - return 0.75; - else - return 0.5; - } - - public double getPassportCharge() { - if(quantity < 5) - return 1.2; - else if (quantity >= 5 && quantity <= 10) - return 0.95; - else if(quantity >= 11 && quantity <= 20) - return 0.85; - else - return 0.75; - } -} - diff --git a/src/PrintingKioskSystem/Objects/PrintingType.java b/src/PrintingKioskSystem/Objects/PrintingType.java deleted file mode 100644 index 9b8d429..0000000 --- a/src/PrintingKioskSystem/Objects/PrintingType.java +++ /dev/null @@ -1,7 +0,0 @@ -package PrintingKioskSystem.Objects; - -public enum PrintingType { - - Document, - Photo -} diff --git a/src/PrintingKioskSystem/Order.java b/src/PrintingKioskSystem/Order.java deleted file mode 100644 index 773490f..0000000 --- a/src/PrintingKioskSystem/Order.java +++ /dev/null @@ -1,149 +0,0 @@ -package PrintingKioskSystem; - -import java.util.ArrayList; -import java.util.Scanner; - -import PrintingKioskSystem.Objects.*; - -public class Order { - - public static ArrayList printingOrders = new ArrayList(); - private static Scanner scanner; - - public static void main(String[] args) { - scanner = new Scanner(System.in); - - boolean error = true, isInvalidInput = false; - String order; - - do { - System.out.print("Enter type of order(D-Document/P-Photo)(E-exit): "); - order = scanner.next().toUpperCase(); - switch (order) { - case "D": - document(); - break; - case "P": - photo(); - break; - case "E": - error = false; - break; - default: - isInvalidInput = true; - break; - } - - if (isInvalidInput) { - System.out.println("Invalid choice. Please enter again"); - isInvalidInput = false; - } else { - boolean er = false; - do { - System.out.print("Proceed to another option? (Y-yes/N-No): "); - String choice = scanner.next().toUpperCase(); - if (choice.equals("Y")) { - error = true; - er = false; - } else if (choice.equals("N")) { - error = false; - er = false; - } else { - System.out.println("Invalid input. Please enter again."); - er = true; - } - } while (er); - - } - - } while (error); - - System.out.println("Proceeding to Billing..."); - double totalBill = 0; - for (int i = 0; i < printingOrders.size(); i++) { - double bill=printingOrders.get(i).getTotal(); - System.out.println((i+1)+": Order "+ printingOrders.get(i).printingOpt + "Quantity= " +printingOrders.get(i).quantity+ " and bill is: " +bill); - totalBill += bill; - } - System.out.print("Your billing total is " + totalBill); - - } - - public static void document() { - String opt; - int Qtt = 0; - boolean isDocumentError; - - do { - isDocumentError = false; - System.out.print("Enter option(A-Black & White/B-Colour): "); - opt = scanner.next().toUpperCase(); - if (opt.equals("A") || opt.equals("B")) { - - System.out.print("Enter quantity in black and white: "); - Qtt = scanner.nextInt(); - PrintingOption pOpt = PrintingOption.Unknown; - if (opt.equals("A")) { - pOpt = PrintingOption.BlackWhite; - } else if (opt.equals("B")) { - pOpt = PrintingOption.Colour; - } - PrintingDocument newDoc = new PrintingDocument(pOpt, Qtt); - printingOrders.add(newDoc); - - } else { - System.out.println("Invalid choice. Please enter again."); - isDocumentError = true; - } - - } while (isDocumentError); - - } - - public static void photo() { - - String opt; - int Qtt; - boolean isPhotoError; - - do { - isPhotoError = false; - System.out.print("Enter option(C-Normal(4R)/D-Passport): "); - opt = scanner.next().toUpperCase(); - if (opt.equals("C") || opt.equals("D")) { - System.out.print("Enter quantity in normal(4R): "); - Qtt = scanner.nextInt(); - - PrintingOption pOpt = PrintingOption.Unknown; - if (opt.equals("C")) { - pOpt = PrintingOption.Normal; - } else if (opt.equals("D")) { - pOpt = PrintingOption.Passport; - } - PrintingPhoto newPhoto = new PrintingPhoto(pOpt, Qtt); - - System.out.println("Additional Option"); - System.out.println("1. High quality paper"); - System.out.println("2. Design effect"); - System.out.println("None (Enter any key to skip)"); - System.out.print("Enter Option: "); - String addOpt = scanner.nextLine(); - scanner.nextLine(); - if (addOpt.equals("1")) { - newPhoto.isHighQualityPaper = true; - } else if (addOpt.equals("2")) { - newPhoto.isDesignEffect = true; - } - - printingOrders.add(newPhoto); - - } else { - System.out.println("Invalid choice. Please enter again."); - isPhotoError = true; - } - - } while (isPhotoError); - - } - -} diff --git a/src/PrintingKioskSystem/Printing.java b/src/PrintingKioskSystem/Printing.java deleted file mode 100644 index 7cd0e6c..0000000 --- a/src/PrintingKioskSystem/Printing.java +++ /dev/null @@ -1,16 +0,0 @@ -package PrintingKioskSystem; - -import java.util.*; - -public class Printing { - public static void main(String[] args) { - - //Table - - - Order order = new Order(); - //order.getMainOpt1(); - } - - -} diff --git a/src/main/java/printing/app/Order.java b/src/main/java/printing/app/Order.java new file mode 100644 index 0000000..44fabfc --- /dev/null +++ b/src/main/java/printing/app/Order.java @@ -0,0 +1,189 @@ +package printing.app; + +import java.util.ArrayList; +import printing.objects.IPrintingOrder; +import java.util.Scanner; + +import printing.objects.*; + +public class Order { + + private static Scanner scanner; + + public static void main(String[] args) { + scanner = new Scanner(System.in); + + boolean error = true, isInvalidInput = false; + String order; + + do { + System.out.print("Enter type of order(D-Document/P-Photo)(E-exit): "); + order = scanner.next().toUpperCase(); + switch (order) { + case "D": + document(); + break; + case "P": + photo(); + break; + case "E": + error = false; + break; + default: + isInvalidInput = true; + break; + } + + if (isInvalidInput) { + System.out.println("Invalid choice. Please enter again"); + isInvalidInput = false; + } else { + boolean er = false; + do { + System.out.print("Proceed to another option? (Y-yes/N-No): "); + String choice = scanner.next().toUpperCase(); + if (choice.equals("Y")) { + error = true; + er = false; + } else if (choice.equals("N")) { + error = false; + er = false; + } else { + System.out.println("Invalid input. Please enter again."); + er = true; + } + } while (er); + + } + + } while (error); + + System.out.println("Proceeding to Billing..."); + double totalBill = 0; + for (int i = 0; i < IPrintingOrder.printingOrders.size(); i++) { + double bill = IPrintingOrder.printingOrders.get(i).getTotal(); + System.out.println((i + 1) + ": Order " + IPrintingOrder.printingOrders.get(i).printingOpt + "Quantity= " + + IPrintingOrder.printingOrders.get(i).quantity + " and bill is: " + bill); + totalBill += bill; + } + System.out.print("Your billing total is " + totalBill); + + } + + public static void document() { + String opt; + int Qtt = 0; + boolean isDocumentError; + boolean isQuantityError; + + do { + isDocumentError = false; + System.out.print("Enter option(A-Black & White/B-Colour): "); + opt = scanner.next().toUpperCase(); + do { + isQuantityError = false; + + if (opt.equals("A") || opt.equals("B")) { + if (opt.equals("A")) { + System.out.print("Enter quantity in black and white: "); + } else if (opt.equals("B")) { + System.out.print("Enter quantity in color: "); + } + try { + Qtt = scanner.nextInt(); + if (Qtt > 50) { + System.out.println("Invalid Quantity, Maximum 50 copies per printing"); + isQuantityError = true; + } else if (Qtt <= 0) { + System.out.println("Invalid Quantity, please enter quantity ranging from 1-50"); + isQuantityError = true; + } else { + PrintingOption pOpt = PrintingOption.Unknown; + if (opt.equals("A")) { + pOpt = PrintingOption.BlackWhite; + } else if (opt.equals("B")) { + pOpt = PrintingOption.Colour; + } + PrintingDocument newDoc = new PrintingDocument(pOpt, Qtt); + IPrintingOrder.printingOrders.add(newDoc); + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Invalid Option please enter integer only"); + } + } else { + System.out.println("Invalid choice. Please enter again."); + isDocumentError = true; + } + } while (isQuantityError); + + } while (isDocumentError); + + } + + public static void photo() { + + String opt; + int Qtt; + boolean isPhotoError; + boolean isQuantityError; + do { + isPhotoError = false; + System.out.print("Enter option(C-Normal(4R)/D-Passport): "); + opt = scanner.next().toUpperCase(); + + do { + isQuantityError = false; + if (opt.equals("C") || opt.equals("D")) { + if (opt.equals("C")) { + System.out.print("Enter quantity in normal(4R): "); + } else if (opt.equals("D")) { + System.out.print("Enter quantity in passport: "); + } + try { + Qtt = scanner.nextInt(); + if (Qtt > 50) { + System.out.println("Invalid Quantity, Maximum 50 copies per printing"); + isQuantityError = true; + } else if (Qtt <= 0) { + System.out.println("Invalid Quantity, please enter quantity ranging from 1-50"); + isQuantityError = true; + } else { + PrintingOption pOpt = PrintingOption.Unknown; + if (opt.equals("C")) { + pOpt = PrintingOption.Normal; + } else if (opt.equals("D")) { + pOpt = PrintingOption.Passport; + } + PrintingPhoto newPhoto = new PrintingPhoto(pOpt, Qtt); + + System.out.println("Additional Option"); + System.out.println("1. High quality paper"); + System.out.println("2. Design effect"); + System.out.println("None (Enter any key to skip)"); + System.out.print("Enter Option: "); + String addOpt = scanner.nextLine(); + scanner.nextLine(); + if (addOpt.equals("1")) { + newPhoto.setIsHighQualityEffect(true); + } else if (addOpt.equals("2")) { + newPhoto.setIsDesignEffect(true); + } + + IPrintingOrder.printingOrders.add(newPhoto); + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Invalid Option please enter integer only"); + } + } else { + System.out.println("Invalid choice. Please enter again."); + isPhotoError = true; + } + } while (isQuantityError); + + } while (isPhotoError); + + } + +} diff --git a/src/main/java/printing/app/PhotoPrinter.java b/src/main/java/printing/app/PhotoPrinter.java new file mode 100644 index 0000000..cd6dd2d --- /dev/null +++ b/src/main/java/printing/app/PhotoPrinter.java @@ -0,0 +1,20 @@ +package printing.app; + +import java.util.ArrayList; + +import printing.objects.IPrintingOrder; + +public class PhotoPrinter { + + IPrintingOrder order; + ArrayList orderArr; + + public PhotoPrinter(IPrintingOrder order) { + this.order = order; + } + + public void queueRequest() { + orderArr = order.getRequest(); + order.updateRequest(orderArr); + } +} diff --git a/src/main/java/printing/objects/IPrintingOrder.java b/src/main/java/printing/objects/IPrintingOrder.java new file mode 100644 index 0000000..159fb60 --- /dev/null +++ b/src/main/java/printing/objects/IPrintingOrder.java @@ -0,0 +1,33 @@ +package printing.objects; + +import java.util.ArrayList; + +public class IPrintingOrder { + + public static ArrayList printingOrders = new ArrayList(); + public PrintingType printingType; + public PrintingOption printingOpt; + public int quantity; + public double sum; + public boolean isHighQualityPaper = false; + public boolean isDesignEffect = false; + + public double getTotal() { + return 0; + } + + public IPrintingOrder(PrintingType pType, PrintingOption pOpt, int qtt) { + this.printingType = pType; + this.printingOpt = pOpt; + this.quantity = qtt; + } + + public ArrayList getRequest() { + + return printingOrders; + } + + public void updateRequest(ArrayList orderArr) { + // place the request into queue for printing + } +} diff --git a/src/main/java/printing/objects/PrintingDocument.java b/src/main/java/printing/objects/PrintingDocument.java new file mode 100644 index 0000000..6f52d99 --- /dev/null +++ b/src/main/java/printing/objects/PrintingDocument.java @@ -0,0 +1,51 @@ +package printing.objects; + +public class PrintingDocument extends IPrintingOrder { + + public PrintingDocument(PrintingOption pOpt, int qtt) { + super(PrintingType.Document, pOpt, qtt); + } + + @Override + public double getTotal() { + double charge = 0; + if (printingOpt == PrintingOption.BlackWhite) { + charge = getBlackAndWhiteCharge(); + } else if (printingOpt == PrintingOption.Colour) { + charge = getColourCharge(); + } + sum = quantity * charge; + return sum; + } + + public double getBlackAndWhiteCharge() { + if (quantity <= 0) + throw new IllegalArgumentException("Invalid Quantity, quantity cannot be negative"); + else if (quantity > 50) + throw new IllegalArgumentException("Invalid Quantity, Maximum 50 copies per printing"); + if (quantity < 5) + return 0.5; + else if (quantity >= 5 && quantity <= 10) + return 0.4; + else if (quantity >= 11 && quantity <= 20) + return 0.3; + else + return 0.2; + } + + public double getColourCharge() { + if (quantity <= 0) + throw new IllegalArgumentException("Invalid Quantity, quantity cannot be negative"); + else if (quantity > 50) + throw new IllegalArgumentException("Invalid Quantity, Maximum 50 copies per printing"); + if (quantity < 5) + return 1; + else if (quantity >= 5 && quantity <= 10) + return 0.9; + else if (quantity >= 11 && quantity <= 20) + return 0.8; + else + return 0.7; + } + +} diff --git a/src/main/java/printing/objects/PrintingOption.java b/src/main/java/printing/objects/PrintingOption.java new file mode 100644 index 0000000..e90f826 --- /dev/null +++ b/src/main/java/printing/objects/PrintingOption.java @@ -0,0 +1,5 @@ +package printing.objects; + +public enum PrintingOption { + BlackWhite, Colour, Normal, Passport, Unknown +} diff --git a/src/main/java/printing/objects/PrintingPhoto.java b/src/main/java/printing/objects/PrintingPhoto.java new file mode 100644 index 0000000..1b8b8ee --- /dev/null +++ b/src/main/java/printing/objects/PrintingPhoto.java @@ -0,0 +1,78 @@ +package printing.objects; + +public class PrintingPhoto extends IPrintingOrder { + + private boolean isHighQualityPaper = false; + private boolean isDesignEffect = false; + + public PrintingPhoto(PrintingOption pOpt, int qtt) { + super(PrintingType.Photo, pOpt, qtt); + } + + @Override + public double getTotal() { + + double charge = 0; + if (printingOpt == PrintingOption.Normal) { + charge = getNormalCharge(); + } else if (printingOpt == PrintingOption.Passport) { + charge = getPassportCharge(); + } + sum = quantity * charge; + return sum; + } + + public double getNormalCharge() { + double charge = 0; + if (quantity <= 0) + throw new IllegalArgumentException("Invalid Quantity, quantity cannot be negative"); + else if (quantity > 50) + throw new IllegalArgumentException("Invalid Quantity, Maximum 50 copies per printing"); + if (quantity < 5) + charge = 1; + else if (quantity >= 5 && quantity <= 10) + charge = 0.9; + else if (quantity >= 11 && quantity <= 20) + charge = 0.75; + else + charge = 0.5; + if (isHighQualityPaper) { + charge += 0.10; + } + if (isDesignEffect) { + charge += 0.15; + } + return charge; + } + + public double getPassportCharge() { + double charge = 0; + if (quantity <= 0) + throw new IllegalArgumentException("Invalid Quantity, quantity cannot be negative"); + else if (quantity > 50) + throw new IllegalArgumentException("Invalid Quantity, Maximum 50 copies per printing"); + if (quantity < 5) + charge = 1.2; + else if (quantity >= 5 && quantity <= 10) + charge = 0.95; + else if (quantity >= 11 && quantity <= 20) + charge = 0.85; + else + charge = 0.75; + if (isHighQualityPaper) { + charge += 0.10; + } + if (isDesignEffect) { + charge += 0.15; + } + return charge; + } + + public void setIsHighQualityEffect(boolean isHighQualityPaper) { + this.isHighQualityPaper = isHighQualityPaper; + } + + public void setIsDesignEffect(boolean isDesignEffect) { + this.isDesignEffect = isDesignEffect; + } +} diff --git a/src/main/java/printing/objects/PrintingType.java b/src/main/java/printing/objects/PrintingType.java new file mode 100644 index 0000000..077245f --- /dev/null +++ b/src/main/java/printing/objects/PrintingType.java @@ -0,0 +1,6 @@ +package printing.objects; + +public enum PrintingType { + + Document, Photo +} diff --git a/src/test/java/printing/objects/IntegrationTest.java b/src/test/java/printing/objects/IntegrationTest.java new file mode 100644 index 0000000..b97d753 --- /dev/null +++ b/src/test/java/printing/objects/IntegrationTest.java @@ -0,0 +1,130 @@ +package printing.objects; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +import org.junit.Test; + +public class IntegrationTest { + ArrayList linesRead = readER(); + IPrintingOrder orderDocumentBW = new PrintingDocument(PrintingOption.BlackWhite, 30); + IPrintingOrder orderDocumentColour = new PrintingDocument(PrintingOption.Colour, 30); + IPrintingOrder orderNormalHighQuality = new PrintingPhoto(PrintingOption.Normal, 20); + IPrintingOrder orderNormalDesign = new PrintingPhoto(PrintingOption.Normal, 20); + IPrintingOrder orderNormal = new PrintingPhoto(PrintingOption.Normal, 20); + IPrintingOrder orderPassportHighQuality = new PrintingPhoto(PrintingOption.Passport, 20); + IPrintingOrder orderPassportDesign = new PrintingPhoto(PrintingOption.Passport, 20); + IPrintingOrder orderPassport = new PrintingPhoto(PrintingOption.Passport, 20); + + @Test + public void testDocumentBW() { + double totalER = Double.parseDouble(linesRead.get(0)[0]); + double chargeER = Double.parseDouble(linesRead.get(0)[1]); + double totalAR = orderDocumentBW.getTotal(); + double chargeAR = ((PrintingDocument) orderDocumentBW).getBlackAndWhiteCharge(); + assertEquals(totalER, totalAR, 0); + assertEquals(chargeER, chargeAR, 0); + } + + @Test + public void testDocumentColour() { + double totalER = Double.parseDouble(linesRead.get(1)[0]); + double chargeER = Double.parseDouble(linesRead.get(1)[1]); + double totalAR = orderDocumentColour.getTotal(); + double chargeAR = ((PrintingDocument) orderDocumentColour).getColourCharge(); + assertEquals(totalER, totalAR, 0); + assertEquals(chargeER, chargeAR, 0); + } + + @Test + public void testNormalHighQuality() { + double totalER = Double.parseDouble(linesRead.get(2)[0]); + double chargeER = Double.parseDouble(linesRead.get(2)[1]); + ((PrintingPhoto) orderNormalHighQuality).setIsHighQualityEffect(true); + double totalAR = orderNormalHighQuality.getTotal(); + double chargeAR = ((PrintingPhoto) orderNormalHighQuality).getNormalCharge(); + assertEquals(totalER, totalAR, 0); + assertEquals(chargeER, chargeAR, 0); + } + + @Test + public void testNormalDesign() { + double totalER = Double.parseDouble(linesRead.get(3)[0]); + double chargeER = Double.parseDouble(linesRead.get(3)[1]); + ((PrintingPhoto) orderNormalDesign).setIsDesignEffect(true); + double totalAR = orderNormalDesign.getTotal(); + double chargeAR = ((PrintingPhoto) orderNormalDesign).getNormalCharge(); + assertEquals(totalER, totalAR, 0); + assertEquals(chargeER, chargeAR, 0); + } + + @Test + public void testNormal() { + double totalER = Double.parseDouble(linesRead.get(4)[0]); + double chargeER = Double.parseDouble(linesRead.get(4)[1]); + double totalAR = orderNormal.getTotal(); + double chargeAR = ((PrintingPhoto) orderNormal).getNormalCharge(); + assertEquals(totalER, totalAR, 0); + assertEquals(chargeER, chargeAR, 0); + } + + @Test + public void testPassportHighQuality() { + double totalER = Double.parseDouble(linesRead.get(5)[0]); + double chargeER = Double.parseDouble(linesRead.get(5)[1]); + ((PrintingPhoto) orderPassportHighQuality).setIsHighQualityEffect(true); + double totalAR = orderPassportHighQuality.getTotal(); + double chargeAR = ((PrintingPhoto) orderPassportHighQuality).getPassportCharge(); + assertEquals(totalER, totalAR, 0); + assertEquals(chargeER, chargeAR, 0); + } + + @Test + public void testPassportDesign() { + double totalER = Double.parseDouble(linesRead.get(6)[0]); + double chargeER = Double.parseDouble(linesRead.get(6)[1]); + ((PrintingPhoto) orderPassportDesign).setIsDesignEffect(true); + double totalAR = orderPassportDesign.getTotal(); + double chargeAR = ((PrintingPhoto) orderPassportDesign).getPassportCharge(); + assertEquals(totalER, totalAR, 0); + assertEquals(chargeER, chargeAR, 0); + } + + @Test + public void testPassport() { + double totalER = Double.parseDouble(linesRead.get(7)[0]); + double chargeER = Double.parseDouble(linesRead.get(7)[1]); + double totalAR = orderPassport.getTotal(); + double chargeAR = ((PrintingPhoto) orderPassport).getPassportCharge(); + assertEquals(totalER, totalAR, 0); + assertEquals(chargeER, chargeAR, 0); + } + + public ArrayList readER() { + ArrayList linesRead = new ArrayList(); + String fileName = "IntegrationER.txt"; + Scanner inputStream = null; + try { + inputStream = new Scanner(new File(fileName)); + } + + catch (FileNotFoundException e) { + System.out.println("Error opening the file " + fileName); + System.exit(0); + } + + while (inputStream.hasNextLine()) { + String singleLine = inputStream.nextLine(); + String[] tokens = singleLine.split(","); + linesRead.add(tokens); + } + + inputStream.close(); + return linesRead; + } + +} diff --git a/src/test/java/printing/objects/OrderTest.java b/src/test/java/printing/objects/OrderTest.java new file mode 100644 index 0000000..3f0e849 --- /dev/null +++ b/src/test/java/printing/objects/OrderTest.java @@ -0,0 +1,278 @@ +package printing.objects; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; + +@RunWith(JUnitParamsRunner.class) +public class OrderTest { + + private Object[] paramForDocumentGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Colour, 1, 1.00 }, + new Object[] { PrintingOption.Colour, 4, 4.00 }, new Object[] { PrintingOption.Colour, 5, 4.50 }, + new Object[] { PrintingOption.Colour, 10, 9.00 }, new Object[] { PrintingOption.Colour, 11, 8.80 }, + new Object[] { PrintingOption.Colour, 20, 16.00 }, new Object[] { PrintingOption.Colour, 21, 14.70 }, + new Object[] { PrintingOption.Colour, 50, 35.00 }, }; + } + + // Valid Test for Document Colour + @Test + @Parameters(method = "paramForDocumentGetTotalBVA") + public void DocumentColourValidTestGetTotalBVA(PrintingOption pOpt, int qtt, double ER) { + IPrintingOrder testDocument = new PrintingDocument(pOpt, qtt); + double AR = testDocument.getTotal(); + assertEquals(ER, AR, 0); + + } + + // Invalid Test For Document Colour + private Object[] InvalidParamForDocumentColourGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Colour, 0 }, new Object[] { PrintingOption.Colour, 51 }, }; + } + + @Test(expected = IllegalArgumentException.class) + @Parameters(method = "InvalidParamForDocumentColourGetTotalBVA") + public void DocumentColourInvalidTestGetTotalBVA(PrintingOption pOpt, int qtt) { + IPrintingOrder testDocument = new PrintingDocument(pOpt, qtt); + double AR = testDocument.getTotal(); + } + + // Valid Test for Document Black and White + private Object[] paramForDocumentBWGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.BlackWhite, 1, 0.50 }, + new Object[] { PrintingOption.BlackWhite, 4, 2.00 }, + new Object[] { PrintingOption.BlackWhite, 5, 2.00 }, + new Object[] { PrintingOption.BlackWhite, 10, 4.00 }, + new Object[] { PrintingOption.BlackWhite, 11, 3.30 }, + new Object[] { PrintingOption.BlackWhite, 20, 6.00 }, + new Object[] { PrintingOption.BlackWhite, 21, 4.20 }, + new Object[] { PrintingOption.BlackWhite, 50, 10.00 }, }; + } + + @Test + @Parameters(method = "paramForDocumentBWGetTotalBVA") + public void DocumentBWValidTestGetTotalBVA(PrintingOption pOpt, int qtt, double ER) { + IPrintingOrder testDocument = new PrintingDocument(pOpt, qtt); + double AR = testDocument.getTotal(); + assertEquals(ER, AR, 0); + + } + + // Invalid Test For Document Black and White + private Object[] InvalidParamForDocumenBWtGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.BlackWhite, 0 }, + new Object[] { PrintingOption.BlackWhite, 51 }, }; + } + + @Test(expected = IllegalArgumentException.class) + @Parameters(method = "InvalidParamForDocumenBWtGetTotalBVA") + public void DocumentBWInvalidTestGetTotalBVA(PrintingOption pOpt, int qtt) { + IPrintingOrder testDocument = new PrintingDocument(pOpt, qtt); + double AR = testDocument.getTotal(); + } + + // Valid Test For Photo High Quality + private Object[] paramForPhotoNormalHighQualityGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Normal, 1, 1.10 }, + new Object[] { PrintingOption.Normal, 4, 4.40 }, new Object[] { PrintingOption.Normal, 5, 5.00 }, + new Object[] { PrintingOption.Normal, 10, 10.00 }, new Object[] { PrintingOption.Normal, 11, 9.35 }, + new Object[] { PrintingOption.Normal, 20, 17.00 }, new Object[] { PrintingOption.Normal, 21, 12.60 }, + new Object[] { PrintingOption.Normal, 50, 30.00 }, }; + } + + @Test + @Parameters(method = "paramForPhotoNormalHighQualityGetTotalBVA") + public void PhotoNormalHighQualityValidTestGetTotalBVA(PrintingOption pOpt, int qtt, double ER) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + ((PrintingPhoto) testPhoto).setIsHighQualityEffect(true); + double AR = testPhoto.getTotal(); + assertEquals(ER, AR, 0); + } + + // Invalid Test For Photo Normal High Quality + private Object[] InvalidParamForPhotoNormalHighQualityGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Normal, 0 }, new Object[] { PrintingOption.Normal, 51 }, }; + } + + @Test(expected = IllegalArgumentException.class) + @Parameters(method = "InvalidParamForPhotoNormalHighQualityGetTotalBVA") + public void PhotoNormalHighQualityInvalidTestGetTotalBVA(PrintingOption pOpt, int qtt) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + ((PrintingPhoto) testPhoto).setIsHighQualityEffect(true); + double AR = testPhoto.getTotal(); + } + + // Valid Test For Photo Normal Design + private Object[] paramForPhotoNormalDesignGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Normal, 1, 1.15 }, + new Object[] { PrintingOption.Normal, 4, 4.60 }, new Object[] { PrintingOption.Normal, 5, 5.25 }, + new Object[] { PrintingOption.Normal, 10, 10.50 }, new Object[] { PrintingOption.Normal, 11, 9.90 }, + new Object[] { PrintingOption.Normal, 20, 18.00 }, new Object[] { PrintingOption.Normal, 21, 13.65 }, + new Object[] { PrintingOption.Normal, 50, 32.50 }, }; + } + + @Test + @Parameters(method = "paramForPhotoNormalDesignGetTotalBVA") + public void PhotoNormalDesignValidTestGetTotalBVA(PrintingOption pOpt, int qtt, double ER) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + ((PrintingPhoto) testPhoto).setIsDesignEffect(true); + double AR = testPhoto.getTotal(); + assertEquals(ER, AR, 0); + + } + + // Invalid Test For Photo Normal Design + private Object[] InvalidParamForPhotoNormalDesignGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Normal, 0 }, new Object[] { PrintingOption.Normal, 51 }, }; + } + + @Test(expected = IllegalArgumentException.class) + @Parameters(method = "InvalidParamForPhotoNormalDesignGetTotalBVA") + public void PhotoNormalDesignInvalidTestGetTotalBVA(PrintingOption pOpt, int qtt) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + ((PrintingPhoto) testPhoto).setIsDesignEffect(true); + double AR = testPhoto.getTotal(); + } + + // Valid Test For Photo Normal + private Object[] paramForPhotoNormalGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Normal, 1, 1.00 }, + new Object[] { PrintingOption.Normal, 4, 4.00 }, new Object[] { PrintingOption.Normal, 5, 4.50 }, + new Object[] { PrintingOption.Normal, 10, 9.00 }, new Object[] { PrintingOption.Normal, 11, 8.25 }, + new Object[] { PrintingOption.Normal, 20, 15.00 }, new Object[] { PrintingOption.Normal, 21, 10.50 }, + new Object[] { PrintingOption.Normal, 50, 25.0 }, }; + } + + @Test + @Parameters(method = "paramForPhotoNormalGetTotalBVA") + public void PhotoNormalValidTestGetTotalBVA(PrintingOption pOpt, int qtt, double ER) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + double AR = testPhoto.getTotal(); + assertEquals(ER, AR, 0); + + } + + // Invalid Test For Photo Normal + private Object[] InvalidParamForPhotoNormalGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Normal, 0 }, new Object[] { PrintingOption.Normal, 51 }, }; + } + + @Test(expected = IllegalArgumentException.class) + @Parameters(method = "InvalidParamForPhotoNormalGetTotalBVA") + public void PhotoNormalInvalidTestGetTotalBVA(PrintingOption pOpt, int qtt) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + double AR = testPhoto.getTotal(); + } + + // Valid Test For Photo Passport High Quality + private Object[] paramForPhotoPassportHighQualityGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Passport, 1, 1.30 }, + new Object[] { PrintingOption.Passport, 4, 5.20 }, new Object[] { PrintingOption.Passport, 5, 5.25 }, + new Object[] { PrintingOption.Passport, 10, 10.50 }, + new Object[] { PrintingOption.Passport, 11, 10.45 }, + new Object[] { PrintingOption.Passport, 20, 19.00 }, + new Object[] { PrintingOption.Passport, 21, 17.85 }, + new Object[] { PrintingOption.Passport, 50, 42.50 }, }; + } + + @Test + @Parameters(method = "paramForPhotoPassportHighQualityGetTotalBVA") + public void PhotoPassportHighQualityValidTestGetTotalBVA(PrintingOption pOpt, int qtt, double ER) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + ((PrintingPhoto) testPhoto).setIsHighQualityEffect(true); + double AR = testPhoto.getTotal(); + assertEquals(ER, AR, 0.0005); + + } + + // Invalid Test For Photo Passport High Quality + private Object[] InvalidParamForPhotoPassportHighQualityGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Passport, 0 }, + new Object[] { PrintingOption.Passport, 51 }, }; + } + + @Test(expected = IllegalArgumentException.class) + @Parameters(method = "InvalidParamForPhotoPassportHighQualityGetTotalBVA") + public void PhotoPassportHighQualityInvalidTestGetTotalBVA(PrintingOption pOpt, int qtt) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + ((PrintingPhoto) testPhoto).setIsHighQualityEffect(true); + double AR = testPhoto.getTotal(); + } + + // Valid Test For Photo Passport Design + private Object[] paramForPhotoPassportDesignGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Passport, 1, 1.35 }, + new Object[] { PrintingOption.Passport, 4, 5.40 }, new Object[] { PrintingOption.Passport, 5, 5.50 }, + new Object[] { PrintingOption.Passport, 10, 11.00 }, + new Object[] { PrintingOption.Passport, 11, 11.00 }, + new Object[] { PrintingOption.Passport, 20, 20.00 }, + new Object[] { PrintingOption.Passport, 21, 18.90 }, + new Object[] { PrintingOption.Passport, 50, 45.00 }, }; + } + + @Test + @Parameters(method = "paramForPhotoPassportDesignGetTotalBVA") + public void PhotoPassportDesignValidTestGetTotalBVA(PrintingOption pOpt, int qtt, double ER) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + ((PrintingPhoto) testPhoto).setIsDesignEffect(true); + double AR = testPhoto.getTotal(); + assertEquals(ER, AR, 0.0005); + + } + + // Invalid Test For Photo Passport Design + private Object[] InvalidParamForPhotoPassportDesignGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Passport, 0 }, + new Object[] { PrintingOption.Passport, 51 }, }; + } + + @Test(expected = IllegalArgumentException.class) + @Parameters(method = "InvalidParamForPhotoPassportDesignGetTotalBVA") + public void PhotoPassportDesignInvalidTestGetTotalBVA(PrintingOption pOpt, int qtt) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + ((PrintingPhoto) testPhoto).setIsDesignEffect(true); + double AR = testPhoto.getTotal(); + } + + // Valid Test For Photo Passport + private Object[] paramForPhotoPassportGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Passport, 1, 1.20 }, + new Object[] { PrintingOption.Passport, 4, 4.80 }, new Object[] { PrintingOption.Passport, 5, 4.75 }, + new Object[] { PrintingOption.Passport, 10, 9.50 }, new Object[] { PrintingOption.Passport, 11, 9.35 }, + new Object[] { PrintingOption.Passport, 20, 17.00 }, + new Object[] { PrintingOption.Passport, 21, 15.75 }, + new Object[] { PrintingOption.Passport, 50, 37.50 }, }; + } + + @Test + @Parameters(method = "paramForPhotoPassportGetTotalBVA") + public void PhotoPassportValidTestGetTotalBVA(PrintingOption pOpt, int qtt, double ER) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + double AR = testPhoto.getTotal(); + assertEquals(ER, AR, 0); + + } + + // Invalid Test For Photo Passport + private Object[] InvalidParamForPhotoPassportGetTotalBVA() { + return new Object[] { new Object[] { PrintingOption.Passport, 0 }, + new Object[] { PrintingOption.Passport, 51 }, }; + } + + @Test(expected = IllegalArgumentException.class) + @Parameters(method = "InvalidParamForPhotoPassportGetTotalBVA") + public void PhotoPassportInvalidTestGetTotalBVA(PrintingOption pOpt, int qtt) { + IPrintingOrder testPhoto = new PrintingPhoto(pOpt, qtt); + double AR = testPhoto.getTotal(); + } + +} diff --git a/src/test/java/printing/objects/PhotoPrinterTest.java b/src/test/java/printing/objects/PhotoPrinterTest.java new file mode 100644 index 0000000..2cd5fcc --- /dev/null +++ b/src/test/java/printing/objects/PhotoPrinterTest.java @@ -0,0 +1,38 @@ +package printing.objects; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Test; +import org.mockito.InOrder; +import org.mockito.Mockito; + +import printing.app.PhotoPrinter; + +public class PhotoPrinterTest { + + @Test + public void testQueueRequest() { + // Mock the class that contain method of getRequest that will return the array + // of orders + IPrintingOrder orderMock = mock(IPrintingOrder.class); + // Mock the class that contain array of orders + IPrintingOrder getOrderMock = mock(IPrintingOrder.class); + // When getRequest is called, always return the fixed array of orders + when(orderMock.getRequest()).thenReturn(orderMock.printingOrders); + // Pass the mock to the printer class the contains the queueRequest method + PhotoPrinter print = new PhotoPrinter(orderMock); + InOrder inOrder = Mockito.inOrder(orderMock); + + print.queueRequest(); + // Assert equals the array of orders return from getRequest with Actual array of + // orders + assertEquals(orderMock.getRequest(), getOrderMock.printingOrders); + // Verify array of orders used for updateRequest method with actual array of + // orders + inOrder.verify(orderMock).updateRequest(getOrderMock.printingOrders); + + } + +} diff --git a/src/test/java/printing/objects/TestSuiteCase.java b/src/test/java/printing/objects/TestSuiteCase.java new file mode 100644 index 0000000..d0c62cb --- /dev/null +++ b/src/test/java/printing/objects/TestSuiteCase.java @@ -0,0 +1,10 @@ +package printing.objects; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(value = Suite.class) +@SuiteClasses(value = { IntegrationTest.class, OrderTest.class, PhotoPrinterTest.class, }) +public class TestSuiteCase { +}