我正在尝试为以下 Java 代码编写 JUnit 测试用例:
private java.lang.Object __equalsCalc = null;
public synchronized boolean equals(java.lang.Object obj) {
if (!(obj instanceof Crop))
return false;
Crop other = (Crop) obj;
if (obj == null) return false;
if (this == obj) return true;
if (__equalsCalc != null) {
return (__equalsCalc == obj);
}
}
我写的测试用例如下:
public void testCrop() {
Crop cp = new Crop();
Object obj = false;
cp.equals(obj);
assertSame(obj instanceof Crop, false);
}
public void testCrop1() {
Crop other = (Crop) obj;
// assertSame(other.equals(obj), true);
assertEquals(obj, other);
}
的测试用例instanceof
工作正常,但在检查if(obj == null) return false;
测试用例时失败: