I\'m trying to get the hang of Java. Unit testing is pretty important to me and so recently I\'ve started to use JUnit. It was tough to begin with but I\'m getting the hang
You need to overrride equals, the equals method in the superclass Object checks for references if both references point to the same object equals is true if not false, so you need to write down an equals method that will check your objects content and check if the values are the same, it is also recommended that you override your hashCode method too.
An example could be:
Custom a= new Custom("");
Custom b= a;
//b would be equal a. because they reference the same object.
Custom c= new Custom("");
//c would not be equal to a, although the value is the same.
to learn more you could check: Why do I need to override the equals and hashCode methods in Java?
assertEquals will use Object#equals for each object being compared. Looks like your class ILogTest doesn't override equals method, so calling Object#equals will just compare the references by itself, and since they're different object references, the result will be false.
You have two options:
public boolean equals(Object o) in ILogTest.assertEquals on the relevant fields that implement equals method e.g. String, Integer, Long, etc. This one requires more code but is useful when you cannot modify the class(es) being asserted.If you are using a modern IDE for development (like Eclipse, IntelliJ etc), they can generate these methods for you. Check that out for two reasons: 1) to save time 2) To prevent possible bugs.
In eclipse IDE, you can do so by selecting source -> generate hashCode() and equals().
One more thing, when you implement of of these two, you have to implement the other one as well.