diff --git a/src/test/java/se/su/dsv/scipro/springdata/TestChecklist.java b/src/test/java/se/su/dsv/scipro/springdata/TestChecklist.java index 05342fa4ad..7a84c42be0 100644 --- a/src/test/java/se/su/dsv/scipro/springdata/TestChecklist.java +++ b/src/test/java/se/su/dsv/scipro/springdata/TestChecklist.java @@ -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. */ @@ -157,6 +133,29 @@ public class TestChecklist { checklistService.hasChangedSinceUserLastOpenDate(checkList, 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 @@ -181,25 +180,28 @@ public class TestChecklist { 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 @Transactional @Rollback 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); - Date newDate = new Date(); - checkListAnswer.setLastModified(newDate); -// Assert.assertTrue(checkList.getUserLastOpenDate().get(employee1).before(newDate)); true - - Assert.assertFalse(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1)); + try { + Thread.sleep(10); + } 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)); }