### Question:
BundleFilterTimeRange implements BundleFilter { @Override public boolean filter(Bundle bundle) { ValueLong timeValue = time.getValue(bundle).asLong(); if (timeValue == null) { return defaultExit; } long unixTime = timeValue.getLong(); if (before != null && unixTime > tbefore) { return false; } if (after != null && unixTime < tafter) { return false; } return defaultExit; } @JsonCreator  BundleFilterTimeRange(@JsonProperty(value = "time", required = true) AutoField time,
                                 @JsonProperty("before") String before,
                                 @JsonProperty("after") String after,
                                 @JsonProperty("defaultExit") boolean defaultExit,
                                 @JsonProperty("timeFormat") String timeFormat,
                                 @JsonProperty("timeZone") String timeZone); @Override boolean filter(Bundle bundle);  }### Answer:
@Test public void testBeforeNoTimezone() throws IOException { BundleFilterTimeRange filter1 = Configs.decodeObject(BundleFilterTimeRange.class, BEFORE_160923); BundleFilterTimeRange filter2 = Configs.decodeObject(BundleFilterTimeRange.class, BEFORE_150925); assertTrue("Expected true since 160922 is earlier than 160923", filter1.filter(bundle)); assertFalse("Expected false since 160922 is later than 150925", filter2.filter(bundle)); }
@Test public void testAfterNoTimezone() throws IOException { BundleFilterTimeRange filter1 = Configs.decodeObject(BundleFilterTimeRange.class, AFTER_160921); BundleFilterTimeRange filter2 = Configs.decodeObject(BundleFilterTimeRange.class, AFTER_170921); assertTrue("Expected true since 160922 is later than 160921", filter1.filter(bundle)); assertFalse("Expected false since 160922 is earlier than 170921", filter2.filter(bundle)); }
@Test public void testMinusBefore() throws IOException { BundleFilterTimeRange filter = Configs.decodeObject(BundleFilterTimeRange.class, "time:TIME, before:-100000"); assertFalse(filter.filter(bundle)); }
@Test public void testBeforeAfterInRange() throws IOException { String str = "time:TIME, before:20170101, after:20120101, timeFormat:YYYYMMDD"; BundleFilterTimeRange filter = Configs.decodeObject(BundleFilterTimeRange.class, str); filter.filter(bundle); assertTrue( filter.filter(bundle)); }
@Test public void testBeforeAfterOutRange() throws IOException { String str = "time:TIME, before:1212011213, after:1301011415, defaultExit:true, " + "timeFormat:yyMMddHHmm, timeZone=Australia/Brisbane"; BundleFilterTimeRange filter = Configs.decodeObject(BundleFilterTimeRange.class, str); assertFalse(filter.filter(bundle)); }