Skip to content

Test does not fail when excluded field has a different label in toString #23

@danielFesenmeyer

Description

@danielFesenmeyer

Let's assume I have a field named "password", but it is labeled as "pwd" in the toString() method. I would expect that the following test should fail, but it passes. Maybe this could be fixed by failing if the test contains any unexpected fields? (I did not find an option for this.)

import org.junit.Test;

import com.jparams.verifier.tostring.NameStyle;
import com.jparams.verifier.tostring.ToStringVerifier;

public class PasswordWithWrongFieldLabelShouldThrowTest
{

   private static class ClassWithPassword
   {
      private String password;

      @Override
      public String toString()
      {
         return "ClassWithPassword{" + "pwd=" + password + '}';
      }
   }

   @Test
   public void testToString() {
      ToStringVerifier.forClass(ClassWithPassword.class)
         .withClassName(NameStyle.SIMPLE_NAME)
         .withIgnoredFields("password")
         .withFailOnExcludedFields(true)
         .verify();
   }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions