0% found this document useful (0 votes)
2 views

10d

Uploaded by

quanglahe172142
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

10d

Uploaded by

quanglahe172142
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Q1:

ERROR 1

Defect ID: DF001


Defect Name: Uninitialized Variable
Line of Code: line 2
Defect Description: The BufferedWriter writer is declared but not initialized before being used. It maybe
cause NullPointerException
Fixing Solution:
Initialize “writer” in the openFile()

ERROR 2

Defect ID: DF002


Defect Name: Naming conversion error.
Line of Code: line 3
Defect Description: The method does follow Java’s naming conventions
Fixing Solution:
use CamelCase for this name : filePath;

ERROR 3

Defect ID: DF003


Defect Name: Variable have not been declared
Line of Code: line 15
Defect Description: declare a variable but forget to initialize its value, and then use this variable in the
program
Fixing Solution:
Initialize the value of the variable before using it: String line = null;

ERROR 4

Defect ID: DF004


Defect Name: Cannot find symbol line
Line of Code: line 15
Defect Description: Attempt to use a variable that has not been previously declared
Fixing Solution:
Declare variables before use:
String line = “”;
System.out.println(line);

ERROR 5
Defect ID: DF005
Defect Name: Missing check null before closing
Line of Code: line 23
Defect Description: This code mischecks the “reader” variable null. If reader is null, calling readFile() will
cause NullPointerException
Fixing Solution:
if(reader !=null){
reader.close();
}

ERROR 6

Defect ID: DF006


Defect Name: Missing Null Check for reader in readFile()
Line of Code: line 17
Defect Description: The code assumes that reader is initialized, but it may not be if openFile() fails to
initialize it.
Fixing Solution: Add a null check before attempting to read:
if(reader == null){
System.out.println("Reader is not initialized. Cannot read the file.");
return;
}

Q2:

ID:TC1; Test for no item in order; Input Parameter: itemPrices: 0, customerType: “VIP”, isVIP: false,
discountCode: null; Expected result: “No items in order

Test code:

@Test(expected = IllegalArgumentException.class)

public void testNoItemsInOrder() {

OrderCalculator calculator = new OrderCalculator();

calculator.calculatorTotalPrice(new double[]{}, "VIP", false, null);

}
ID:TC2; Test for VIP customer with no discount code; Input Parameter: itemPrices: [100,200],
customerType: “VIP”, isVIP: true, discountCode: null; Expected result: 240.0

Test code:

@Test(expected = IllegalArgumentException.class)

public void testVIPCustomerWithNoDiscountCode() {

OrderCalculator calculator = new OrderCalculator();

double total = calculator.calculatorTotalPrice(new double[]{100, 200}, "VIP", true, null);

assertEquals(240.0, total, 0.01); //20% discount

ID:TC3; Test for VIP customer with discount code; Input Parameter: itemPrices: [100,200], customerType:
“VIP”, isVIP: true, discountCode: “SALE10”; Expected result: 210.0

Test code:

@Test(expected = IllegalArgumentException.class)

public void testVIPCustomerWithDiscountCode() {

OrderCalculator calculator = new OrderCalculator();

double total = calculator.calculatorTotalPrice(new double[]{100, 200}, "VIP", true, "SALE10");

assertEquals(210.0, total, 0.01); //30% discount

ID:TC4; Test for Regular customer with no discount code; Input Parameter: itemPrices: [100,200],
customerType: “Regular”, isVIP: false, discountCode: null, Expected result: 285.0

Test code:

@Test(expected = IllegalArgumentException.class)

public void testRegularCustomerWithNoDiscountCode() {

OrderCalculator calculator = new OrderCalculator();

double total = calculator.calculatorTotalPrice(new double[]{100, 200}, "Regular", false, null);

assertEquals(285.0, total, 0.01); //5% discount

}
ID:TC5; Test for Regular customer with discount code; Input Parameter: itemPrices: [100,200],
customerType: “Regular”, isVIP: false, discountCode: “WELCOME5”, Expected result: 285.0

Test code:

@Test(expected = IllegalArgumentException.class)

public void testRegularCustomerWithDiscountCode() {

OrderCalculator calculator = new OrderCalculator();

double total = calculator.calculatorTotalPrice(new double[]{100, 200}, "Regular", false,


"WELCOME5");

assertEquals(270.0, total, 0.01); //10% discount

ID:TC6; Test for invalid item price; Input Parameter: itemPrices: [-1,0], customerType: “VIP”, isVIP: false,
discountCode: null, Expected result: "Item price must be greater than zero."

Test code:

@Test(expected = IllegalArgumentException.class)

public void testInvalidItemPrice() {

OrderCalculator calculator = new OrderCalculator();

calculator.calculatorTotalPrice(new double[]{-1, 0}, "VIP", false, null);

ID:TC7; Test for invalid customer type; Input Parameter: itemPrices: [100], customerType: “member”,
isVIP: false, discountCode: null, Expected result: IllegalArgumentException.

Test code:

@Test(expected = IllegalArgumentException.class)

public void testInvalidCustomerType() {

OrderCalculator calculator = new OrderCalculator();

calculator.calculatorTotalPrice(new double[]{100}, "member", false, null);

}
ID:TC8; Test for invalid customer type; Input Parameter: itemPrices: [100], customerType: “VIP”, isVIP:
false, discountCode: “HELLOWORLD”, Expected result: IllegalArgumentException.

Test code:

@Test(expected = IllegalArgumentException.class)

public void testInvalidDiscountCode() {

OrderCalculator calculator = new OrderCalculator();

calculator.calculatorTotalPrice(new double[]{100}, "VIP", false, "HELLOWORLD");

Q3:
Test Case 1: Normal Flow - Successful Order with PayPal

● Test case ID: TC001


● Test case description: Test successful order with PayPal
● Preconditions:
○ Customer must logged into system
○ Shopping cart contains at least one item(product A with $50)
● Test Steps:
○ Customer adds a product A to their cart.
○ Customer process to checkout
○ System display the total amount, including discounts.
○ Customer provides payment with PayPal.
○ System processes the payment.
○ System confirms the order and generates an order confirmation
● Expected Results:
○ The system processes the payment successfully.
○ The system confirms the order and displays the estimated delivery time.
● Notes: Normal Flow (NF)

Test Case 2: Normal Flow - Successful Order with Discount Code

● Test case ID: TC002


● Test case Description: Test successful order with a valid discount code applied.
● Preconditions:
○ Customer must logged into system
○ Shopping cart contains at least one item(product A with $50)
● Test Steps:
○ Customer adds a product A to their cart.
○ Customer applied discount code(“SAVE10”)
○ System validates the discount code.
○ Customer process to checkout
○ System display the total amount, including discounts.
○ Customer provides payment with PayPal.
○ System processes the payment.
○ System confirms the order and generates an order confirmation
● Expected Results:
○ The system applies the discount successfully.
○ The system processes the payment successfully.
○ The system confirms the order and displays the estimated delivery time.
● Notes: Normal Flow (NF)

Test Case 3: Alternative Flow – Empty cart

● Test case ID: TC003


● Test case description: Test attempt to place an order with an empty cart.
● Preconditions:
○ Customer must logged into system
○ Shopping cart contains at least one item
● Test Steps:
○ Customer attempts to place an order without adding items to the cart.
● Expected Results:
○ System displays a message prompting the customer to add items to the cart before
proceeding.
● Notes: Alternative flow(AL1)

Test Case 4: Alternative Flow – Expired Discount Code

● Test case ID: TC004


● Test case description: Test order with an expired discount code.
● Preconditions:
○ Customer must logged into system
○ Shopping cart contains at least one item(product A with $50)
● Test Steps:
○ Customer adds a product A to their cart.
○ Customer applied discount code(“EXPRIEDCODE”)
○ System displays an error message about the expired discount code.
○ Customer proceeds with the order without applying a discount.
○ Customer process to checkout
○ System display the total amount, including discounts.
○ Customer provides payment with PayPal.
○ System processes the payment.
○ System confirms the order and generates an order confirmation
● Expected Results:
○ System displays an error message indicating that the discount code is expired.
○ System allows the customer to proceed without a discount.
● Notes: Alternative flow(AL2)

Test Case 5: Alternative Flow – Payment Failure

● Test case ID: TC005


● Test case description: Test payment failure due to insufficient funds or incorrect card details.
● Preconditions:
○ Customer must logged into system
○ Shopping cart contains at least one item(product A with $50)
● Test Steps:
○ Customer adds a product A to their cart.
○ Customer process to checkout
○ System display the total amount
○ Customer proceeds to payment and selects credit card payment.
○ Customer enters invalid credit card details (incorrect card number).
○ System attempts to process the payment.
● Expected Results:
○ System displays a payment failure message ("Insufficient funds or invalid card details.").
○ System prompts the customer to retry payment with correct details or another payment
method.
● Notes: Alternative flow(AL3)

You might also like