### Question:
FileModificationDateFileFilterRule implements FileFilterRule { @Override public boolean match(File file) throws FilterRuleNotAppliableException { long lastModified = file.getLastModified(); if (-1 == lastModified) { throw new FilterRuleNotAppliableException("The file or directory doesn't have any modification date"); } switch (op) { case OP_IS: return date.isEqualTo(lastModified); case OP_ISNT: return !date.isEqualTo(lastModified); case OP_IS_BEFORE: return date.isBefore(lastModified); case OP_IS_AFTER: return date.isAfter(lastModified); } return false; } FileModificationDateFileFilterRule(DateValue date, int operator); @Override String getRuleType(); static String[] getAllOperators(); @Override int getOperator(); @Override String getOperatorName(); @Override OperandValue getValue(); @Override boolean match(File file); @Override String toString(); static final String TYPE_NAME; static final int OP_IS; static final int OP_ISNT; static final int OP_IS_BEFORE; static final int OP_IS_AFTER; }### Answer:
@Test public void testOpIs() throws Exception { FileModificationDateFileFilterRule filterRule = new FileModificationDateFileFilterRule(new DateValue(OLD_DATE_TIME), FileModificationDateFileFilterRule.OP_IS); assertTrue(filterRule.match(testNode)); testNode.setLastModified(newtime); assertFalse(filterRule.match(testNode)); }
@Test public void testOpIsnt() throws Exception { FileModificationDateFileFilterRule filterRule = new FileModificationDateFileFilterRule(new DateValue(OLD_DATE_TIME), FileModificationDateFileFilterRule.OP_ISNT); testNode.setLastModified(newtime); assertTrue(filterRule.match(testNode)); }
@Test public void testOpIsAfter() throws Exception { FileModificationDateFileFilterRule filterRule = new FileModificationDateFileFilterRule(new DateValue(NEW_DATE_TIME), FileModificationDateFileFilterRule.OP_IS_AFTER); testNode.setLastModified(oldtime); assertNotEquals(oldtime, newtime); assertTrue(filterRule.match(testNode)); }
@Test public void testOpIsBefore() throws Exception { FileModificationDateFileFilterRule filterRule = new FileModificationDateFileFilterRule(new DateValue(OLD_DATE_TIME), FileModificationDateFileFilterRule.OP_IS_BEFORE); testNode.setLastModified(newtime); assertNotEquals(oldtime, newtime); assertTrue(filterRule.match(testNode)); }
@Test public void testOpDefault() throws Exception { FileModificationDateFileFilterRule filterRule = new FileModificationDateFileFilterRule(new DateValue(NEW_DATE_TIME), -1); assertFalse(filterRule.match(testNode)); }
@Test public void throwFilterRuleNotAppliableExceptionAll() throws Exception { FileModificationDateFileFilterRule filterRule = new FileModificationDateFileFilterRule(new DateValue(NEW_DATE_TIME), FileModificationDateFileFilterRule.OP_IS); testNode.setLastModified(-1); assertThrows(FilterRuleNotAppliableException.class, () -> filterRule.match(testNode)); }