Skip to content

Commit b484de8

Browse files
authored
feat: implemnents Customer class with Customer Test (#8)
1 parent cf1545f commit b484de8

File tree

5 files changed

+91
-3
lines changed

5 files changed

+91
-3
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package q1.team1;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
7+
public class Customer {
8+
private String customerId;
9+
private final List<String> cart;
10+
11+
// Constructor
12+
public Customer(String customerId) {
13+
this.customerId = customerId;
14+
this.cart = new ArrayList<>();
15+
}
16+
17+
// Getter for customer ID
18+
public String getCustomerId() {
19+
return customerId;
20+
}
21+
22+
// Setter for customer ID
23+
public void setCustomerId(String customerId) {
24+
this.customerId = customerId;
25+
}
26+
27+
// Get current cart contents
28+
public List<String> getCart() {
29+
return cart;
30+
}
31+
32+
// Add item to cart
33+
public void addItemToCart(String item) {
34+
cart.add(item);
35+
}
36+
37+
// Remove item from cart
38+
public boolean removeItemFromCart(String item) {
39+
return cart.remove(item); // returns true if removed
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package q1.team1;
2+
3+
import java.util.List;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
import static org.junit.jupiter.api.Assertions.assertFalse;
7+
import static org.junit.jupiter.api.Assertions.assertTrue;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class CustomerTest {
11+
12+
@Test
13+
public void testAddItemToCart() {
14+
Customer customer = new Customer("C123");
15+
customer.addItemToCart("Apples");
16+
17+
List<String> cart = customer.getCart();
18+
assertTrue(cart.contains("Apples"));
19+
}
20+
21+
@Test
22+
public void testRemoveItemFromCart() {
23+
Customer customer = new Customer("C123");
24+
customer.addItemToCart("Bananas");
25+
26+
boolean removed = customer.removeItemFromCart("Bananas");
27+
assertTrue(removed);
28+
assertFalse(customer.getCart().contains("Bananas"));
29+
}
30+
31+
@Test
32+
public void testSetAndGetCustomerId() {
33+
Customer customer = new Customer("C123");
34+
customer.setCustomerId("C999");
35+
assertEquals("C999", customer.getCustomerId());
36+
}
37+
38+
@Test
39+
public void testCartInitiallyEmpty() {
40+
Customer customer = new Customer("C123");
41+
assertTrue(customer.getCart().isEmpty());
42+
}
43+
}

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
1820

1921
##############################################################################
2022
#
@@ -84,7 +86,7 @@ done
8486
# shellcheck disable=SC2034
8587
APP_BASE_NAME=${0##*/}
8688
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87-
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
8890

8991
# Use the maximum available, or set MAX_FD != -1 to use that value.
9092
MAX_FD=maximum
@@ -203,7 +205,7 @@ fi
203205
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204206

205207
# Collect all arguments for the java command:
206-
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
208+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207209
# and any embedded shellness will be escaped.
208210
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209211
# treated as '${Hostname}' itself on the command line.

gradlew.bat

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
@rem See the License for the specific language governing permissions and
1414
@rem limitations under the License.
1515
@rem
16+
@rem SPDX-License-Identifier: Apache-2.0
17+
@rem
1618

1719
@if "%DEBUG%"=="" @echo off
1820
@rem ##########################################################################

0 commit comments

Comments
 (0)