jparams / to-string-verifier

To String Verifier provides an easy and convenient way to test the toString method on your class.
MIT License
32 stars 6 forks source link

Fields of type Instant are not supported. #22

Closed danielFesenmeyer closed 4 years ago

danielFesenmeyer commented 5 years ago

The following test fails:

public class InstantNotSupportedTest
{

   private static class ClassWithInstant {
      private Instant theInstant;

      @Override
      public String toString()
      {
         return "ClassWithInstant{" + "theInstant=" + theInstant + '}';
      }
   }

   @Test
   public void testToString() {
      ToStringVerifier.forClass(ClassWithInstant.class)
         .withClassName(NameStyle.SIMPLE_NAME)
         .verify();
   }

}

It throws this error: java.time.DateTimeException: Invalid value for NanoOfSecond (valid values 0 - 999999999): 1361563254

Of course, I could use sth like ".withPrefabValue(Instant.class, Instant.now())", but what if my class contains multiple fields of type Instant? The test will then not fail when I switch the field references in the toString() implementation. What about adding a method like "withPrefabValueFactory(T, Supplier)"?

jparams commented 4 years ago

Fix in 1.4.6

Instant is now supported by default. For other unsupported types, we now have the method: withValueProvider