Java 模拟的EasyMock更改类

Java 模拟的EasyMock更改类,java,unit-testing,easymock,Java,Unit Testing,Easymock,在我的代码中有一个实例变量 protected IFigure primaryShape 以及使用primaryShape的setter protected void setLineWidth(int width) { if (primaryShape instanceof Shape) { ((Shape) primaryShape).setLineWidth(width); } } 现在我想测试这个setter,在我的testclass中,我有一个模拟:

在我的代码中有一个实例变量

protected IFigure primaryShape
以及使用primaryShape的setter

protected void setLineWidth(int width) {
    if (primaryShape instanceof Shape) {
        ((Shape) primaryShape).setLineWidth(width);
    }
}
现在我想测试这个setter,在我的testclass中,我有一个模拟:

@Mock(type = MockType.NICE, name= "primaryShapeMock", fieldName = "primaryShape")
private MyClassFigure primaryShapeMock;
这个测试方法

@Test
public void testSetLineWitdh(){
    objectUnderTest.setLineWidth(0);
}
这样,我只能测试if案例的真实分支,但如何测试虚假分支?我真的需要为这种情况创建一个新的Testclass吗?或者我可以更改mock的类来在同一个Testclass中测试它吗


提前感谢

instanceof有哪些替代方案?因为该方法是自动生成的。