Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Testing done on User and MyCartModel #18

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public void update() {
// Update RecyclerView data
viewAllAdapters.notifyDataSetChanged();
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
53 changes: 53 additions & 0 deletions app/src/test/java/com/example/projecto/UserMyCartIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.projecto;

import static org.junit.Assert.*;

import com.example.projecto.models.MyCartModel;
import com.example.projecto.models.User;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class UserMyCartIT{

private User user;
private MyCartModel cart;

@Before
public void setUp() {
// Reset singleton instances before each test
User.getInstance();
MyCartModel.getInstance();

// Initialize instances
user = User.getInstance("John Doe", "john@example.com", "password123");
cart = MyCartModel.getInstance("Product Name", "100", "2023-05-27", "12:00", "1", 100.0);
}

@Test
public void testUserAndCartIntegration() {
// Update user details
user.setEmail("newemail@example.com");

// Simulate an operation that might use updated user info
String userEmail = user.getEmail();

// For demonstration purposes, assume cart operations depend on user info
cart.setProductName("Product updated for " + userEmail);

// Verify that the cart model correctly reflects the change
assertEquals("Product updated for newemail@example.com", cart.getProductName());
}

@Test
public void testCartValues() {
// Set new values in the cart
cart.setTotalPrice(200.0);
cart.setTotalQuantity("2");

// Verify cart values
assertEquals(200.0, cart.getTotalPrice(), 0.0);
assertEquals("2", cart.getTotalQuantity());
}
}
Loading