-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Milestone
Description
Situation
There are two classes that extend each other. The methods hashCode() and equals() were both generated by Eclipse.
public class Parent {
int foo;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + foo;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Parent other = (Parent) obj;
if (foo != other.foo)
return false;
return true;
}
}
public class Child extends Parent {
int bar;
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + bar;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
Child other = (Child) obj;
if (bar != other.bar)
return false;
return true;
}
}This is the base test for the class Child:
public class ChildTest {
@Test
public void baseTest() {
SingleThreadExecutor executor = new SingleThreadExecutor();
assertTrue(executor.execute(Child.class,
Arrays.asList(new GetterIsSetterCheck(), new HashcodeAndEqualsCheck(), new PublicVariableCheck())));
}
}Issue
The following line in the Childs function equals() is not tested:
if (getClass() != obj.getClass())
return false;I guess it needs an object that is an instance of Parent but not a Child to test this case.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels