I'm trying to compare two Objects, by comparing their instance variables one by one. I keep getting the same error (while comparing the name only)
this is the error I keep getting: java.lang.AssertionError: The two instances are not equal, they have different names
Here is my code:
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null || getClass() != obj.getClass()) return false; Beverage beverage = (Beverage) obj; if(this.name == null || beverage.name == null ) return false; if (!Objects.equals(name, beverage.name)) return false; if (Double.compare(beverage.price, price) != 0) return false; if (Double.compare(beverage.discount, discount) != 0) return false; return sugarLevel == beverage.sugarLevel; }The error is only with the name and the same message every time, I have tried multiple solutions but none of them worked