Skip to content

FAQ

Frequently Asked Questions

Here you’ll find any frequently asked questions and their answers. If you have a question that you can’t find an answer to here, please Contact Us.

Can I pass a Mock object to the testEqualsMethod and testHashCodeMethod?

No. EqualsMethodTester.testEqualsMethod() and HashCodeMethodTester.testHashCodeMethod() test a specific object. You cannot mock what you are trying to test.

Can I test property significance for my equals methods?

Yes, this is standard behaviour for the EqualsMethodTester.testEqualsMethod().

Can I test property significance for my hashCode methods?

No, not yet. We’re adding that feature to the HashCodeMethodTester.testHashCodeMethod() in the near future. Bear with us.

How do I configure Mean Bean’s logging?

Mean Bean uses Apache Commons Logging. When testing Mean Bean we configure its logging with the following log4j.properties file placed in the src/test/resources. You can see it in the test jar available for download from version 0.0.5 onwards.

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=INFO, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

How do I create a Configuration?

To create a Configuration, create a new ConfigurationBuilder, set the configuration properties you want to override, then invoke build. E.g.

Configuration configuration = new ConfigurationBuilder().ignoreProperty("lastName").build();

How do I ignore a property when testing my getter and setter methods?

To ignore a property (or properties) when testing the getter and setter methods of a JavaBean, create a Configuration, ignore a property on it, and pass the configuration to the testEqualsMethod. For example, to ignore the property lastName:

Configuration configuration = new ConfigurationBuilder().ignoreProperty("lastName").build();
EqualsMethodTester equalsMethodTester = new EqualsMethodTester();
equalsMethodTester.testEqualsMethod(MyClass.class, configuration);

How do I test my equals method?

To test the equals method of a class use an EqualsMethodTester. E.g.

EqualsMethodTester equalsMethodTester = new EqualsMethodTester();
equalsMethodTester.testEqualsMethod(MyClass.class);

How do I test my getter and setter methods?

To test the getter and setter methods of a JavaBean, use a BeanTester. E.g.

BeanTester beanTester = new BeanTester();
beanTester.testBean(MyJavaBeanDomainObject.class);

How do I test my hashCode method?

To test the hashCode method of a class, use a HashCodeMethodTester. E.g.

HashCodeMethodTester hashCodeMethodTester = new HashCodeMethodTester();
hashCodeMethodTester.testHashCodeMethod(MyClass.class);

What is a property?

A property is a member field of an object that can be accessed by a getter and/or setter. For example:

class Person {

   private String firstName;
   private String lastName;

   public String getFirstName() {
      return firstName;
   }

   public void setFirstName(String firstName) {
      this.firstName = firstName;
   }

   public void setLastName(String lastName) {
      this.lastName = lastName;
   }

   public String getFullName() {
      return lastName + ", " + firstName;
   }
}

A property is read-only if it has only a getter method, like the “fullName” property of Person. A property is write-only if it has only a setter method, like the “lastName” property of Person. A property is readable and writable if it has both a getter and setter method, like the “firstName” property of Person.

At present Mean Bean only tests public read/write properties in a class, like “firstName” in the above code snippet.

What is an “Insignificant Property”?

An “insignificant property” is one that is not considered by an equals and/or hashCode method. That is, a property of an object that will not affect its logical equivalence to another object. A “significant property” therefore is one that is considered by an equals and/or hashCode method.

What is a “Significant Property”?

A “significant property” is one that is considered by an equals and/or hashCode method. That is, a property of an object that will affect its logical equivalence to another object. An “insignificant property” is therefore one that is not considered by an equals and/or hashCode method.

What is the difference between Mean Bean versions 1.0.0 through to 1.0.5?

When trying to get Mean Bean into Maven Central repo the pom had to be altered several times. These are the only changes between Mean Bean versions 1.0.0 through to 1.0.5 – there are no functional changes.

What is the difference between Mean Bean versions 1.x and 2.0.0?

Mean Bean version 2.0.0 massively simplified the testing of equals and hashCode methods by requiring that only the class under test be specified, not that an EquivalentFactory be provided.

Which properties does testBean test?

At present Mean Bean only tests public read/write properties in a class. We call these getter/setter pairs. If there is demand for testing of read-only and write-only properties, we will add this functionality in the future. We already plan to extend testing to other visibilities.

Why is it called Mean Bean?

It’s my wife’s nickname. Graham Williamson