meanbeanlib / meanbean

Automated JavaBean Testing
Apache License 2.0
15 stars 3 forks source link

Testing verify that all class members are set correctly for a particular instance #1

Closed mobasherswl closed 4 years ago

mobasherswl commented 4 years ago

The example class is given below. See setName method, where the value passed is set to both class members. The unit test passes without any error. Am I missing something?

`public class User { private String name; private String title;

public String getName() {
    return name;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public void setName(String name) {
    this.name=name;
    title=name;
}

@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    User user = (User) o;
    return Objects.equals(name, user.name) &&
            Objects.equals(title, user.title);
}

@Override
public int hashCode() {
    return Objects.hash(name, title);
}

@Override
public String toString() {
    return "User{" +
            "name='" + name + '\'' +
            ", title='" + title + '\'' +
            '}';
}

}`

meanbeanlib commented 4 years ago

Bean verification checks that a call to Foo setter results in a change visible from Foo getter:

setFoo(xyz)
xyz.equals(getFoo())

It does not check if a call to Foo setter might result in a change to another property:

setFoo(xyz)
!xyz.equals(getBar()) ??

It's easy to see though why users might want the library to detect such likely unintended behavior. An improvement will be made to the library to detect it.

Thanks for reporting.

meanbeanlib commented 4 years ago

With 3.0.0-m6 release, such a bean should be detected.

meanbeanlib commented 4 years ago

Please give that a try.

Gitter chat was also created as another venue for asking questions.