actually it works, you just need to add some waiting in between updating dates
This commit is contained in:
parent
68f76ae00b
commit
7849c8ff54
@ -123,30 +123,6 @@ public class TestChecklist {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* If we run method, the date should get updated.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
@Transactional
|
|
||||||
@Rollback
|
|
||||||
public void testupdateUserLastOpenDate() {
|
|
||||||
/**
|
|
||||||
* Since the date is null ATM, we need to put a new date and save the checklist.
|
|
||||||
*/
|
|
||||||
Date oldDate = new Date();
|
|
||||||
checkList.getUserLastOpenDate().put(employee1, oldDate);
|
|
||||||
checkList = checklistService.save(checkList);
|
|
||||||
/**
|
|
||||||
* Then we run the method, which should update the date to a newer date.
|
|
||||||
*/
|
|
||||||
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
|
||||||
Date newDate = checkList.getUserLastOpenDate().get(employee1);
|
|
||||||
/**
|
|
||||||
* The old date should now be before the new date.
|
|
||||||
*/
|
|
||||||
Assert.assertTrue(oldDate.before(newDate));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If we run method with user, getUserLastOpenUpdate for user should no longer be null.
|
* If we run method with user, getUserLastOpenUpdate for user should no longer be null.
|
||||||
*/
|
*/
|
||||||
@ -157,6 +133,29 @@ public class TestChecklist {
|
|||||||
checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1);
|
checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1);
|
||||||
Assert.assertNotSame(null, checkList.getUserLastOpenDate().get(employee1));
|
Assert.assertNotSame(null, checkList.getUserLastOpenDate().get(employee1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we run method, the date should get updated.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testupdateUserLastOpenDate2() {
|
||||||
|
|
||||||
|
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
|
Date oldDate = checkList.getUserLastOpenDate().get(employee1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
|
Date newDate = checkList.getUserLastOpenDate().get(employee1);
|
||||||
|
|
||||||
|
Assert.assertTrue(oldDate.before(newDate));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User has not yet opened the checklist with the new functionality. We have no way of knowing
|
* User has not yet opened the checklist with the new functionality. We have no way of knowing
|
||||||
@ -181,25 +180,28 @@ public class TestChecklist {
|
|||||||
Assert.assertFalse(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1));
|
Assert.assertFalse(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We run the update method to get a date. Then we set an answers lastModified to a later date.
|
||||||
|
* The method should return true, since this would mean changes have been made after the user
|
||||||
|
* last opened the checklist.
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
@Rollback
|
@Rollback
|
||||||
public void testhasChangedSinceUserLastOpenDate4() {
|
public void testhasChangedSinceUserLastOpenDate4() {
|
||||||
// Assert.assertTrue(checkList.getUserLastOpenDate().get(employee1)==null); true
|
|
||||||
|
|
||||||
// Date lastModified = checkListAnswer.getLastModified();
|
|
||||||
// Assert.assertTrue(lastModified!=null); true
|
|
||||||
|
|
||||||
// checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
|
||||||
// Assert.assertTrue(checkList.getUserLastOpenDate().get(employee1)!=null); true
|
|
||||||
|
|
||||||
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
Date newDate = new Date();
|
|
||||||
checkListAnswer.setLastModified(newDate);
|
|
||||||
|
|
||||||
// Assert.assertTrue(checkList.getUserLastOpenDate().get(employee1).before(newDate)); true
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
Assert.assertFalse(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1));
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
checkListAnswer.setLastModified(new Date());
|
||||||
|
checkListAnswerDao.save(checkListAnswer);
|
||||||
|
|
||||||
|
Assert.assertTrue(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user