Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
danielFesenmeyer opened this issue Jul 18, 2019 · 0 comments

Comments

@danielFesenmeyer
Copy link

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();
   }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant