@Test public void testMatches() { NoteData note = new NoteData(); long creationTimestamp = System.currentTimeMillis(); note.setCreationDate(new Date(creationTimestamp)); Matcher<NoteData> matcher = new DateRangeMatcher(null, null); Assert.assertTrue(matcher.matches(note)); matcher = new DateRangeMatcher(new Date(creationTimestamp - 1), null); Assert.assertTrue(matcher.matches(note)); matcher = new DateRangeMatcher(null, new Date(creationTimestamp - 1)); Assert.assertFalse(matcher.matches(note)); matcher = new DateRangeMatcher(null, new Date(creationTimestamp + 1)); Assert.assertTrue(matcher.matches(note)); matcher = new DateRangeMatcher(new Date(creationTimestamp + 1), null); Assert.assertFalse(matcher.matches(note)); matcher = new DateRangeMatcher(new Date(creationTimestamp - 1), new Date( creationTimestamp + 1)); Assert.assertTrue(matcher.matches(note)); }
@Override public boolean matches(NoteData entity) { if (startDate == null && endDate == null) { return true; } Date date = entity.getCreationDate(); return (startDate == null || date.after(startDate)) && (endDate == null || date.before(endDate)); }
DateRangeMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (startDate == null && endDate == null) { return true; } Date date = entity.getCreationDate(); return (startDate == null || date.after(startDate)) && (endDate == null || date.before(endDate)); } }
DateRangeMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (startDate == null && endDate == null) { return true; } Date date = entity.getCreationDate(); return (startDate == null || date.after(startDate)) && (endDate == null || date.before(endDate)); } DateRangeMatcher(Date startDate, Date endDate); }
DateRangeMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (startDate == null && endDate == null) { return true; } Date date = entity.getCreationDate(); return (startDate == null || date.after(startDate)) && (endDate == null || date.before(endDate)); } DateRangeMatcher(Date startDate, Date endDate); @Override boolean matches(NoteData entity); }
DateRangeMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (startDate == null && endDate == null) { return true; } Date date = entity.getCreationDate(); return (startDate == null || date.after(startDate)) && (endDate == null || date.before(endDate)); } DateRangeMatcher(Date startDate, Date endDate); @Override boolean matches(NoteData entity);  }