Detailed explanation of the technical principles of EQUALSVERIFIER | Release Normal Jar framework in the Java class library

EQUALSVERIFIER is an open source Java library that is easy to test the correctness of Equals and HashCode methods that can easily test the class.It can help developers verify whether these methods follow the corresponding specifications and find potential problems and BUG.EQUALSVERIFIER's technical principles are based on reflex and randomly generated test cases. In Java, Equals and HashCode methods are important methods to determine the equal nature of objects.According to the Java specification, the EQUALS method must meet the following conditions: 1. Authenticity: X.equals (X) must return True. 2. Symmetry: If x.equals (y) returns true, Y.Equals (X) must also return True. 3. Transmission: If x.equals (y) returns true, y.equals (z) returns true, then x.equals (z) must also return true. 4. Consistency: When the object is not modified, call x.equals (y) multiple times should return the same result. 5. X.equals (NULL) must return false. In order to verify whether a class of Equals and HashCode methods meet the above specifications, we usually need to manually write test cases to include different objects and verify their equal nature.This manual test method is both time -consuming and easy to make mistakes.EQUALSVERIFIER provides a way to automate to generate test cases and test the Equals and HashCode methods. EQUALSVERIFIER uses reflection to analyze the structure of the class and generates corresponding test cases.It will automatically find the fields in the class and generate multiple different values for each field, including NULL, default value, equal value, non -equal value, and so on.EqualsVerifier uses the generated test cases to verify the correctness of the Equals and HashCode methods.Through the actual equal nature and expectations of comparative objects, EQUALSVERIFIER can discover potential problems and errors. Below is an example of using Equalsverifier: import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; public class Person { private String name; private int age; // constructors, getters, setters, etc. @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null || obj.getClass() != getClass()) { return false; } Person other = (Person) obj; return name.equals(other.name) && age == other.age; } @Override public int hashCode() { return Objects.hash(name, age); } public static void main(String[] args) { EqualsVerifier.forClass(Person.class) .suppress(Warning.NONFINAL_FIELDS) .verify(); } } In the above example, we define a Person class and rewrite the Equals and HashCode methods.We then use Equalsverifier to generate and verify test cases.Before calling the `Verify ()" method, we can use the `SUPPRESS ()` method to prohibit specific warnings to ignore certain conditions that do not meet the specifications. Through Equalsverifier, we can automatically verify the correctness of the Equals and HashCode methods without manually writing a pile of test cases.This greatly simplifies testing and reduced potential mistakes.Equalsverifier is widely used in various Java class libraries and frameworks to help developers improve code quality and reliability.