I tried to create a new object in timesheet type and assign values.But I have a method call insertTimesheet which takes employeeId. As there is no such value for employeeId in timesheet object , the test gets fail.
@Test
public void testInsertTimesheet() {
Timesheet expectedToSave = new Timesheet( 1001 ,"2019-01-10", "2019-01-05", "comment section is this ", "saved", null, null);
int actualInsertData = timesheetRepository.insertTimesheet(expectedToSave, 100789);
Assertions.assertEquals(expectedToSave, actualInsertData);
}
JdbcTemplate.update()
method will return number of rows effected. if not inserted successfully it will throw DataAccessException
exception.
@Test
public void testInsertTimesheet() {
Timesheet expectedToSave = new Timesheet( 1001 ,"2019-01-10", "2019-01-05", "comment section is this ", "saved", null, null);
int actualInsertData = timesheetRepository.insertTimesheet(expectedToSave, 100789); //In here number of effected rows is 1 so insertTimeSheet() will return 1
Assert.assertEquals(1, actualInsertData); //expected value is 1
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.