Commit 6f763fc2 authored by addya's avatar addya

Test cases written. Finished product ?? (Will double check)

parent fa5c4206
...@@ -5,6 +5,26 @@ ...@@ -5,6 +5,26 @@
<artifactId>SelfCheckout</artifactId> <artifactId>SelfCheckout</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>15</maven.compiler.source> <maven.compiler.source>15</maven.compiler.source>
......
...@@ -39,12 +39,18 @@ ...@@ -39,12 +39,18 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel1" alignment="0" pref="615" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0">
<Component id="jPanel1" min="-2" pref="569" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel1" min="-2" pref="378" max="-2" attributes="0"/> <Group type="102" alignment="0" attributes="0">
<Component id="jPanel1" min="-2" pref="381" max="-2" attributes="0"/>
<EmptySpace min="0" pref="19" max="32767" attributes="0"/>
</Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
...@@ -65,6 +71,27 @@ ...@@ -65,6 +71,27 @@
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblBasket" min="-2" pref="127" max="-2" attributes="0"/>
<Component id="lblTotal" alignment="0" min="-2" pref="127" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblDiscount" min="-2" pref="127" max="-2" attributes="0"/>
<Component id="lbl£" alignment="1" min="-2" pref="18" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="txfPayment" min="-2" pref="134" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnPay" min="-2" pref="66" max="-2" attributes="0"/>
</Group>
<Component id="lblMessage" min="-2" pref="238" max="-2" attributes="0"/>
<Component id="lblMessage2" min="-2" pref="238" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="jScrollPane1" min="-2" pref="156" max="-2" attributes="0"/> <Component id="jScrollPane1" min="-2" pref="156" max="-2" attributes="0"/>
...@@ -92,28 +119,8 @@ ...@@ -92,28 +119,8 @@
</Group> </Group>
</Group> </Group>
</Group> </Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblBasket" min="-2" pref="127" max="-2" attributes="0"/>
<Component id="lblTotal" alignment="0" min="-2" pref="127" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblDiscount" min="-2" pref="127" max="-2" attributes="0"/>
<Component id="lbl£" alignment="1" min="-2" pref="18" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="txfPayment" min="-2" pref="134" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnPay" min="-2" pref="66" max="-2" attributes="0"/>
</Group>
<Component id="lblErrorMessage" min="-2" pref="150" max="-2" attributes="0"/>
</Group>
</Group>
</Group> </Group>
<EmptySpace min="194" pref="133" max="32767" attributes="0"/> <EmptySpace pref="55" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
...@@ -123,8 +130,10 @@ ...@@ -123,8 +130,10 @@
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0"> <Group type="103" groupAlignment="1" attributes="0">
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Component id="lblErrorMessage" min="-2" max="-2" attributes="0"/> <Component id="lblMessage" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/> <EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
<Component id="lblMessage2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="txfPayment" alignment="3" min="-2" pref="30" max="-2" attributes="0"/> <Component id="txfPayment" alignment="3" min="-2" pref="30" max="-2" attributes="0"/>
<Component id="btnPay" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnPay" alignment="3" min="-2" max="-2" attributes="0"/>
...@@ -289,6 +298,7 @@ ...@@ -289,6 +298,7 @@
<SubComponents> <SubComponents>
<Component class="javax.swing.JTextArea" name="txaBasket"> <Component class="javax.swing.JTextArea" name="txaBasket">
<Properties> <Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="columns" type="int" value="20"/> <Property name="columns" type="int" value="20"/>
<Property name="rows" type="int" value="5"/> <Property name="rows" type="int" value="5"/>
</Properties> </Properties>
...@@ -334,6 +344,7 @@ ...@@ -334,6 +344,7 @@
<Color blue="0" green="ff" red="ff" type="rgb"/> <Color blue="0" green="ff" red="ff" type="rgb"/>
</Property> </Property>
<Property name="text" type="java.lang.String" value="Pay"/> <Property name="text" type="java.lang.String" value="Pay"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnPayActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnPayActionPerformed"/>
...@@ -358,7 +369,7 @@ ...@@ -358,7 +369,7 @@
<Property name="text" type="java.lang.String" value="6-10&gt;&gt;&gt;&#xa3;5 off"/> <Property name="text" type="java.lang.String" value="6-10&gt;&gt;&gt;&#xa3;5 off"/>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JLabel" name="lblErrorMessage"> <Component class="javax.swing.JLabel" name="lblMessage">
<Properties> <Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="14" style="2"/> <Font name="Tahoma" size="14" style="2"/>
...@@ -366,7 +377,7 @@ ...@@ -366,7 +377,7 @@
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> <Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="ff" red="ff" type="rgb"/> <Color blue="0" green="ff" red="ff" type="rgb"/>
</Property> </Property>
<Property name="text" type="java.lang.String" value=".........."/> <Property name="verticalAlignment" type="int" value="1"/>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JLabel" name="lbl&#xa3;"> <Component class="javax.swing.JLabel" name="lbl&#xa3;">
...@@ -380,6 +391,17 @@ ...@@ -380,6 +391,17 @@
<Property name="text" type="java.lang.String" value="&#xa3;"/> <Property name="text" type="java.lang.String" value="&#xa3;"/>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JLabel" name="lblMessage2">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="14" style="2"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="verticalAlignment" type="int" value="1"/>
</Properties>
</Component>
</SubComponents> </SubComponents>
</Container> </Container>
</SubComponents> </SubComponents>
......
This diff is collapsed.
...@@ -169,7 +169,7 @@ ...@@ -169,7 +169,7 @@
<Property name="editable" type="boolean" value="false"/> <Property name="editable" type="boolean" value="false"/>
<Property name="columns" type="int" value="20"/> <Property name="columns" type="int" value="20"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="18" style="2"/> <Font name="Tahoma" size="14" style="2"/>
</Property> </Property>
<Property name="rows" type="int" value="5"/> <Property name="rows" type="int" value="5"/>
</Properties> </Properties>
...@@ -232,6 +232,9 @@ ...@@ -232,6 +232,9 @@
</Property> </Property>
<Property name="text" type="java.lang.String" value="Checkout"/> <Property name="text" type="java.lang.String" value="Checkout"/>
</Properties> </Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCheckoutActionPerformed"/>
</Events>
</Component> </Component>
</SubComponents> </SubComponents>
</Container> </Container>
......
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
/* /*
...@@ -18,22 +19,34 @@ public class SelectProducts extends javax.swing.JFrame { ...@@ -18,22 +19,34 @@ public class SelectProducts extends javax.swing.JFrame {
public String[] products = {"Pen", "Book", "Water", "Drink", "Snack", "Sweet", "Chocolate", "Biscuits", "Cake"}; public String[] products = {"Pen", "Book", "Water", "Drink", "Snack", "Sweet", "Chocolate", "Biscuits", "Cake"};
//array of prices //array of prices
public double[] prices = {1, 1, 1, 1, 2, 1, 1, 1, 2}; public double[] prices = {1, 1, 1, 1, 2, 1, 1, 1, 2};
//array of how many of each item is in stock //arraylist of amount of each item left in stock
//its an arraylist so it can be initialised
public ArrayList<Integer> stockArL = new ArrayList<Integer>(); public ArrayList<Integer> stockArL = new ArrayList<Integer>();
//array for the quantity of each item left
public int[] stock;
//temporary array for the quantity of each item left
//this will update each time the user adds an item to their basket
//after they checkout it will finalise and
public int[] tempStock;
//index will be the position of the currently selected item in these arrays //index will be the position of the currently selected item in these arrays
public int index; public int index;
//the basket array must be an arraylist since we add new things to it dynamically using a button
public ArrayList<String> basketArL= new ArrayList<String>();
/** /**
* Creates new form SelectProducts * Creates new form SelectProducts
*/ */
public SelectProducts() { public SelectProducts() {
initComponents(); initComponents();
//------------------Initialising stocks-------------------
//this variable is how many iterations the loop performs //this variable is how many iterations the loop performs
//one iteration is done for eacah product //one iteration is done for eacah product
int amountOfItems=products.length; int amountOfItems=products.length-1;
for (int i=0;i==9;i++){ for (int i=0;i<=amountOfItems;i++){
String z="0"; String z="0";
//if int i is below 10 then a "0" is added to the front //if int i is below 10 then a "0" is added to the front
//e.g. "01, "02", "03" //e.g. "01, "02", "03"
...@@ -54,11 +67,20 @@ public class SelectProducts extends javax.swing.JFrame { ...@@ -54,11 +67,20 @@ public class SelectProducts extends javax.swing.JFrame {
//so 20 is added to the stock arraylist //so 20 is added to the stock arraylist
stockArL.add(20); stockArL.add(20);
} }
Integer[] s = stockArL.toArray(new Integer[9]);
int[] st = Arrays.stream(s).mapToInt(Integer::intValue).toArray();
stock=st;
tempStock=stock;
//-----------------------------------------------
//on the form starting the combobox cmbItems //on the form starting the combobox cmbItems
//is set to display the items in the products array //is set to display the items in the products array
DefaultComboBoxModel dm=new DefaultComboBoxModel(products); DefaultComboBoxModel dm=new DefaultComboBoxModel(products);
cmbProducts.setModel(dm); cmbProducts.setModel(dm);
//the button to add items to basket is enabled at first
//so the user can't add anything without selecting it
btnAddItem.setEnabled(false);
} }
/** /**
...@@ -101,7 +123,7 @@ public class SelectProducts extends javax.swing.JFrame { ...@@ -101,7 +123,7 @@ public class SelectProducts extends javax.swing.JFrame {
txaShowSelected.setEditable(false); txaShowSelected.setEditable(false);
txaShowSelected.setColumns(20); txaShowSelected.setColumns(20);
txaShowSelected.setFont(new java.awt.Font("Tahoma", 2, 18)); // NOI18N txaShowSelected.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N
txaShowSelected.setRows(5); txaShowSelected.setRows(5);
jScrollPane1.setViewportView(txaShowSelected); jScrollPane1.setViewportView(txaShowSelected);
...@@ -128,6 +150,11 @@ public class SelectProducts extends javax.swing.JFrame { ...@@ -128,6 +150,11 @@ public class SelectProducts extends javax.swing.JFrame {
btnCheckout.setBackground(new java.awt.Color(255, 255, 0)); btnCheckout.setBackground(new java.awt.Color(255, 255, 0));
btnCheckout.setText("Checkout"); btnCheckout.setText("Checkout");
btnCheckout.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCheckoutActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout); jPanel1.setLayout(jPanel1Layout);
...@@ -207,6 +234,7 @@ public class SelectProducts extends javax.swing.JFrame { ...@@ -207,6 +234,7 @@ public class SelectProducts extends javax.swing.JFrame {
private void cmbProductsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbProductsActionPerformed private void cmbProductsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbProductsActionPerformed
// TODO add your handling code here: // TODO add your handling code here:
btnAddItem.setEnabled(true);
String display; String display;
String find=cmbProducts.getSelectedItem().toString(); String find=cmbProducts.getSelectedItem().toString();
String current=""; String current="";
...@@ -216,47 +244,18 @@ public class SelectProducts extends javax.swing.JFrame { ...@@ -216,47 +244,18 @@ public class SelectProducts extends javax.swing.JFrame {
//index is equal to i //index is equal to i
//this is the position of the product we want to find //this is the position of the product we want to find
index=i; index=i;
if (tempStock[index]<=0){
display="Item: "+products[i]+"\nPrice: £"+prices[i]+"\nSorry, out of stock.";
btnAddItem.setEnabled(false);
}
else{
display="Item: "+products[i]+"\nPrice: £"+prices[i]; display="Item: "+products[i]+"\nPrice: £"+prices[i];
}
txaShowSelected.setText(display); txaShowSelected.setText(display);
} }
else { else {
}
}
/*
String display;
int index=4;
display="Code: "+codesArL.get(index)+"\nPrice: " + products[index]
+ "\n£" + prices[index] + "\nIn stock: "+stockArL.get(index);
//method .setText() will set the text area to the display string
txaShowSelected.append(display);
//we want to find the selected item in the products array
String find=cmbProducts.getSelectedItem().toString();
//find the index of the selected item
String current="";
//index wil be the index of the item when we find it
//int index=0;
for (int i=0;i<products.length; i++){
current=products[i];
if (current==find){
index=i;
} }
else{
} }
}
//String display is what we will show in the text area txaShowSelected
//we take the corresponding code, product, price and quantity from each array
display="Code: "+codesArL.get(index)+"\nPrice: " + products[index]
+ "\n£" + prices[index] + "\nIn stock: "+stockArL.get(index);
//method .setText() will set the text area to the display string
txaShowSelected.append(display);
*/
}//GEN-LAST:event_cmbProductsActionPerformed }//GEN-LAST:event_cmbProductsActionPerformed
//the variable for the total cost must be defined outside of the action event //the variable for the total cost must be defined outside of the action event
...@@ -264,22 +263,43 @@ public class SelectProducts extends javax.swing.JFrame { ...@@ -264,22 +263,43 @@ public class SelectProducts extends javax.swing.JFrame {
double total=0; double total=0;
private void btnAddItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddItemActionPerformed private void btnAddItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddItemActionPerformed
// TODO add your handling code here: // TODO add your handling code here:
//when the 'Add Item' button is pressed //when the 'Add Item' button is pressed, if there is enough stock left
if (tempStock[index]>0){
//take away 1 from the stock of the added item
int ts=tempStock[index];
ts=ts-1;
tempStock[index]=ts;
//the item in the display should go into the basket //the item in the display should go into the basket
txaBasket.append(products[index]+"\t"+prices[index]+"\n"); txaBasket.append(products[index]+"\t"+prices[index]+"\n");
//we add the item to an arraylist for the basket too //we add the item to the arraylist for the basket too
//somehow we need to pass this arraylist to the second JFrameForm basketArL.add(products[index]);
ArrayList<String> BasketArL= new ArrayList<String>();
BasketArL.add(products[index]);
//we will add the price of the added item to the total cost //we will add the price of the added item to the total cost
total= total + prices[index]; total= total + prices[index];
//then display it with the total label //then display it with the total label
lblTotalCost.setText("Total: £"+total); lblTotalCost.setText("Total: £"+total);
}
else {
String display="Item: "+products[index]+"\nPrice: £"+prices[index]+"\nSorry, out of stock.";
txaShowSelected.setText(display);
btnAddItem.setEnabled(false);
}
}//GEN-LAST:event_btnAddItemActionPerformed }//GEN-LAST:event_btnAddItemActionPerformed
private void btnCheckoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCheckoutActionPerformed
// TODO add your handling code here:
//when they're ready to check out they click this button
//to open the CheckOut JFrame form
this.setVisible(false);
String[] basketArr = new String[basketArL.size()];
basketArr = basketArL.toArray(basketArr);
//the total cost of the items and the array of items in the basket
//are both passed to the next jFrame form
new CheckOut(total, basketArr, products, stock, tempStock).setVisible(true);
}//GEN-LAST:event_btnCheckoutActionPerformed
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
*
* @author addya
*/
public class CheckOutTest {
public CheckOutTest() {
}
@BeforeAll
public static void setUpClass() {
}
@AfterAll
public static void tearDownClass() {
}
@BeforeEach
public void setUp() {
}
@AfterEach
public void tearDown() {
}
/**
* Test of payment when the user gives more money than the cost
*/
@Test
public void testPaymentSuccess() {
System.out.println("payment success");
double cost = 10.50;
double payment = 11.0;
String message="";
if (payment>=cost){
if (payment==cost){
message="Thank you.";
}
else{
double change=payment-cost;
message="Thank you. Your change is £"+change+".";
}
}
else {
message="Insufficient payment >.<";
fail("Message says 'Insufficient payment'.");
}
CheckOut instance = null;
String expResult = "Thank you. Your change is £0.5.";
//String result = instance.payment(cost, payment);
String result = message;
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
//fail("The test case is a prototype.");
}
/**
* Test of payment when the user gives more money than the cost
*/
@Test
public void testPaymentFailure() {
System.out.println("payment failure");
double cost = 10.50;
double payment = 10.0;
String message="";
if (payment>=cost){
if (payment==cost){
message="Thank you.";
}
else{
double change=payment-cost;
message="Thank you. Your change is £"+change+".";
}
fail("System accepts payment.");
}
else {
message="Insufficient payment >.<";
}
CheckOut instance = null;
String expResult = "Insufficient payment >.<";
//String result = instance.payment(cost, payment);
String result = message;
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
//fail("The test case is a prototype.");
}
}
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