我收到此错误并且已经研究过,因为我不是在调用Mocked类而是实际的类?我已经多次查看它,简单地调用模拟似乎非常简单。我得到的主要错误是
通缉但未被援引:
dsIn.setItemString(1,“MAKE”,“MAKE”);
但是,此模拟还有其他互动:
dsIn.getItemNumber(1,“APPROVED”);
dsIn.setItemString(1,“VIN”,“VIN”);
dsIn.setItemObject(1,“MAKE”,null);
然后它继续通过其他人。
以下是要测试的课程:
if(dsIn.getItemNumber(1,"APPROVED") == 1) {
throw new TRDIException("Cannot change Approved record");
}
String sql;
sql = "select c.EQUIPMENT_NAME, c.VIN, c.MAKE, c.MODEL,c.EQUIPMENT_CLASS_CODE_ID,c.SALVAGE_VALUE,c.GARAGE_ASSIGNED,c.EQ_LOCATION_ID, c.DEPT_PM_NOTIFY, " +
"GET_DEPR_VALUE(c.EQUIPMENT_ID) AS EQ_CURRENT_VALUE " +
" from EQUIPMENT_INVENTORY c where c.EQUIPMENT_ID = " + newValueIn ;
DataStore ds = dl.createDataStore(sql);
ds.retrieve();
dsIn.setItemString(1,"VIN",ds.getItemString(1,"VIN"));
dsIn.setItemObject(1,"MAKE",ds.getItemObject(1,"MAKE"));
dsIn.setItemObject(1,"MODEL",ds.getItemObject(1,"MODEL"));
dsIn.setItemObject(1,"EQUIPMENT_CLASS_CODE_ID",ds.getItemObject(1,"EQUIPMENT_CLASS_CODE_ID"));
dsIn.setItemObject(1,"GARAGE_ASSIGNED",ds.getItemObject(1,"GARAGE_ASSIGNED"));
dsIn.setItemObject(1,"EQ_LOCATION_ID",ds.getItemObject(1,"EQ_LOCATION_ID"));
dsIn.setItemObject(1,"SALVAGE_VALUE",ds.getItemObject(1,"SALVAGE_VALUE"));
if(dsIn.getItemNumber(1,"APPROVED") == 1) {
throw new TRDIException("Cannot change approved record");
}
以下是测试类:
@RunWith(Parameterized.class)
public class TestFillEqDisposalAttr extends TestGroovy {
@Mock
private DataLayer dl;
@Mock
private DataStore dsIn;
@Mock
private DataStore ds;
private String newValueIn;
@Parameter
public String client;
@Parameters(name = "{index}: {0}")
public static Object[] data() {
return new Object[]{
"test"
};
}
@Before
public void setUp() throws Exception {
//groovy script file to test
groovyScriptFile = new File(GROOVY_SCRIPTS_FOLDER + "/" + client + "/test.groovy");
MockitoAnnotations.initMocks(this);
Mockito.when(dl.createDataStore(Mockito.anyString())).thenReturn(ds);
newValueIn = "1";
//groovy script parameters
addGroovyBindingVariable(GroovyScriptArgName.DATALAYER, dl);
addGroovyBindingVariable(GroovyScriptArgName.DATASTORE, dsIn);
addGroovyBindingVariable(GroovyScriptArgName.NEW_VALUE, newValueIn);
}
/**
*/
@Test
public void testEqDisposalAttr() throws IOException, TRDIException {
Mockito.when(ds.getItemString(1, "VIN")).thenReturn("VIN");
Mockito.when(ds.getItemString(1, "MAKE")).thenReturn("MAKE");
Mockito.when(ds.getItemString(1, "MODEL")).thenReturn("MODEL");
Mockito.when(ds.getItemString(1, "EQUIPMENT_CLASS_CODE_ID")).thenReturn("EQUIPMENT_CLASS_CODE_ID");
Mockito.when(ds.getItemString(1, "GARAGE_ASSIGNED")).thenReturn("GARAGE_ASSIGNED");
Mockito.when(ds.getItemString(1, "EQ_LOCATION_ID")).thenReturn("EQ_LOCATION_ID");
Mockito.when(ds.getItemString(1, "SALVAGE_VALUE")).thenReturn("SALVAGE_VALUE");
evaluate();
String sql = "select c.EQUIPMENT_NAME, c.VIN, c.MAKE, c.MODEL,c.EQUIPMENT_CLASS_CODE_ID,c.SALVAGE_VALUE,c.GARAGE_ASSIGNED,c.EQ_LOCATION_ID, c.DEPT_PM_NOTIFY, " +
"GET_DEPR_VALUE(c.EQUIPMENT_ID) AS EQ_CURRENT_VALUE " +
" from EQUIPMENT_INVENTORY c where c.EQUIPMENT_ID = " + newValueIn ;
Mockito.verify(dl).createDataStore(sql);
Mockito.verify(ds).retrieve();
Mockito.verify(dsIn).setItemString(1, "VIN", "VIN");
Mockito.verify(dsIn).setItemString(1, "MAKE", "MAKE");
Mockito.verify(dsIn).setItemString(1, "MODEL", "MODEL");
Mockito.verify(dsIn).setItemString(1, "EQUIPMENT_CLASS_CODE_ID", "EQUIPMENT_CLASS_CODE_ID");
Mockito.verify(dsIn).setItemString(1, "GARAGE_ASSIGNED", "GARAGE_ASSIGNED");
Mockito.verify(dsIn).setItemString(1, "EQ_LOCATION_ID", "EQ_LOCATION_ID");
Mockito.verify(dsIn).setItemString(1, "SALVAGE_VALUE", "SALVAGE_VALUE");
}