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