Java - AssertionFailerError - Espacios en blanco?

 
Vista:
sin imagen de perfil

AssertionFailerError - Espacios en blanco?

Publicado por Xavi (21 intervenciones) el 04/12/2021 18:18:26
Hola,

Tengo la siguiente clase:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package edu.uoc.pac4;
 
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;
import java.util.stream.Collectors;
 
public class ShoppingCart {
 
    private String clientName;
    private double total;
    private List <Product> cart;
 
    public ShoppingCart(String clientName) {
        this.cart = new ArrayList<>();
        setClientName(clientName);
    }
 
    public List<Product> getCart() {
        return this.cart;
    }
 
    public String getClientName() {return clientName;}
 
    public void setClientName(String clientName) {this.clientName = clientName;}
 
    public double getTotal() {return total;}
 
    public void setTotal(double total) {
        this.total = (double) Math.round(total * 100) / 100;
    }
 
    public boolean add(Product product) throws NullPointerException {
        boolean tractat = false;
        if (product != null) {
            if (product instanceof PhysicalProduct) {
                if (((PhysicalProduct) product).getStock() > 0) {
                    cart.add(product);
                    product.incSales();
                    setTotal(getTotal()+product.getPrice());
                    ((PhysicalProduct) product).setStock(((PhysicalProduct) product).getStock() - 1);
                    tractat = true;
                }
            } else if (product instanceof DigitalProduct) {
                cart.add(product);
                DigitalProduct.incSalesTotal();
                product.incSales();
                setTotal(getTotal()+product.getPrice());
                tractat= true;
            }
        } else {
            throw new NullPointerException("[ERROR] Product object cannot be null");
        }
        return tractat;
    }
 
    public boolean remove(Product product) {
        boolean tractat = false;
        if (product != null) {
            if (this.cart.contains(product)){
                cart.remove(product);
                product.decSales();
                if (product instanceof PhysicalProduct) {
                    ((PhysicalProduct) product).setStock(((PhysicalProduct) product).getStock() + 1);
                } else if (product instanceof DigitalProduct) {
                    DigitalProduct.decSalesTotal();
                }
                setTotal(getTotal()-product.getPrice());
                tractat = true;
            }
        } else {
            throw new NullPointerException("[ERROR] Product object cannot be null");
        }
        return tractat;
    }
 
    public void remove() {
        for (Product product : this.cart) {
            product.decSales();
            if (product instanceof PhysicalProduct) {
                ((PhysicalProduct) product).setStock(((PhysicalProduct) product).getStock() + 1);
            } else if (product instanceof DigitalProduct) {
                DigitalProduct.decSalesTotal();
            }
        }
        cart.clear();
        setTotal(0);
    }
 
    public boolean exists(Product product) {return cart.contains(product);}
 
    public boolean isEmpty() {return cart.isEmpty();}
 
    public TreeMap groupAndSort(boolean orderByPriceDesc) {
        TreeMap<Product, Integer> map = new TreeMap<>();
        if (orderByPriceDesc){
            map = new TreeMap<>(new ProductOrderByPrice().reversed());
        }
        for (Product i : this.cart) {
            map.put(i, Collections.frequency(this.cart, i));
        }
 
        return map;
    }
 
    public void printInvoice(boolean orderByPriceDesc){
        TreeMap<Product, Integer> map = groupAndSort(orderByPriceDesc);
        for (Map.Entry<Product, Integer> entry : map.entrySet()) {
            Product key = entry.getKey();
            Integer u = entry.getValue();
            NumberFormat f = DecimalFormat.getInstance();
            f.setMinimumFractionDigits(1);
            f.setMaximumFractionDigits(2);
            System.out.println(key.getReference() + " - Units: " + u + " - (" + f.format(key.getPrice()) + "€) " + key.getPublicationYear());
        }
    }
 
    public String toString(){
        return "Client: " + this.clientName + " - Products: " + cart.size();
    }
 
    /*****************************
     *      STREAM METHODS
     *****************************/
 
    public List<String> getDigitalProductOrderByName() {
 
        return this.cart.stream().filter(product -> product instanceof DigitalProduct).map(Product::getName).sorted().collect(Collectors.toList());
    }
 
    public void getDistinctReferenceByVAT(VAT vat) {
        this.cart.stream().distinct().filter(product -> product.getVAT() == vat).forEach(product -> System.out.println(product.getReference()));
    }
 
    public double averagePriceBooks() {
        return this.cart.stream().filter(product -> product instanceof Book).mapToDouble(Product::getPrice).average().getAsDouble();
    }
 
}

En concreto estoy codificando el método public void getDistinctReferenceByVAT(VAT vat). Cuando ejecuto me da el error AssertionFailerError. A continuación adjunto una imagen con los resultados esperados y actuales:

test

Como podeis ver el resultado es el mismo pero no me pasa el test. Me dice el siguiente mensaje:

1
Contents have differences only in line separators

Cómo puedo solucionarlo?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

AssertionFailerError - Espacios en blanco?

Publicado por Xavi (21 intervenciones) el 04/12/2021 19:25:27
Solucionado, gracias!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar