dimanche 31 janvier 2021

How this test can be fixed?

I am beginner to java and testing. I am getting error with the test @shouldAddOrderToTheList() : Expected :5 Actual :1. Could you please point to me what is wrong and how it can be fixed?

class ShopTestSuite {


    Shop shop = new Shop();

    Order order1 = new Order(12.30, LocalDate.of(2020, 12, 12), "marta123");
    Order order2 = new Order(67.89, LocalDate.of(2019, 1, 12), "Tomek_K");
    Order order3 = new Order(123.90, LocalDate.of(2020, 2, 2), "Sylwia");
    Order order4 = new Order(22.90, LocalDate.of(2020, 6, 20), "Sylwia");


    @Test
    public void shouldAddOrderToTheList() {
        // When
        shop.addOrder(new Order(23, LocalDate.now(), "zz"));
        // Then
        assertEquals(5, shop.getAllOrders().size());
    }

CLASS SHOP

public class Shop {

    private Set<Order> orders = new HashSet<>();

   public void addOrder (Order order) {
       this.orders.add(order);

   }

  public Set<Order> getAllOrders(){
        return this.orders;
    }
  
  }

Aucun commentaire:

Enregistrer un commentaire