List of usage examples for org.apache.commons.collections4 Predicate Predicate
Predicate
From source file:org.xwiki.extension.job.history.internal.DefaultExtensionJobHistoryTest.java
@Test public void addGetRecords() throws Exception { ExtensionJobHistoryConfiguration config = this.mocker.getInstance(ExtensionJobHistoryConfiguration.class); when(config.getStorage()).thenReturn(testFolder.getRoot()); long now = new Date().getTime(); ExtensionJobHistoryRecord firstRecord = new ExtensionJobHistoryRecord("install", new InstallRequest(), null, null, new Date(now - 7000)); ExtensionJobHistoryRecord secondRecord = new ExtensionJobHistoryRecord("uninstall", new UninstallRequest(), null, null, new Date(now + 4000)); ExtensionJobHistory history = this.mocker.getComponentUnderTest(); history.addRecord(firstRecord);/*from www . jav a 2 s .c o m*/ history.addRecord(secondRecord); // Get all records. Predicate<ExtensionJobHistoryRecord> all = PredicateUtils .allPredicate(Collections.<Predicate<ExtensionJobHistoryRecord>>emptyList()); assertEquals(Arrays.asList(secondRecord, firstRecord), history.getRecords(all, null, -1)); // Limit the number of returned records. assertEquals(Arrays.asList(secondRecord), history.getRecords(all, null, 1)); // Get records from offset. assertEquals(Arrays.asList(firstRecord), history.getRecords(all, secondRecord.getId(), -1)); // Filter the records by job type. assertEquals(Arrays.asList(firstRecord), history.getRecords(new Predicate<ExtensionJobHistoryRecord>() { @Override public boolean evaluate(ExtensionJobHistoryRecord record) { return "install".equals(record.getJobType()); } }, null, -1)); }