### Question:
AbstractFilteringGreedyRerankStrategy implements GreedyRerankStrategy { @Nullable @Override public Result nextItem(long userId, int n, List<? extends Result> items, List<? extends Result> candidates) { int numToInspect = computeNumToInspect(n, items.size(), candidates.size()); Result bestResult = null; double bestScore = 0; for (int i = 0; i < numToInspect; i++) { Result candidate = candidates.get(i); if (satisfiesConstraint(userId, n, items, candidate)) { return candidate; } } return null; }  @Nullable @Override Result nextItem(long userId, int n, List<? extends Result> items, List<? extends Result> candidates);  }### Answer:
@Test public void testParametersPassedCorrectly() { final long theUserId = 10; final int theN = 100; final List<Result> theItems = new ArrayList<>(); theItems.add(Results.create(0,0)); AbstractFilteringGreedyRerankStrategy selector = new AbstractFilteringGreedyRerankStrategy() { @Override protected boolean satisfiesConstraint(long userId, int n, List<? extends Result> items, Result candidate) { assertEquals(theUserId, userId); assertEquals(theN, n); assertEquals(theItems, items); return true; } }; List<Result> candidates = new ArrayList<>(); candidates.add(Results.create(1,1)); candidates.add(Results.create(2,2)); candidates.add(Results.create(3,3)); candidates.add(Results.create(4,4)); Result result = selector.nextItem(theUserId, theN, theItems, candidates); assertNotNull(result); assertEquals(1, result.getId()); }
@Test public void testFirstTrueResult() { List<Result> selected = new ArrayList<>(); List<Result> candidates = new ArrayList<>(); candidates.add(Results.create(1,1)); candidates.add(Results.create(2,2)); candidates.add(Results.create(3,3)); candidates.add(Results.create(4,4)); Result result = oddOnly.nextItem(0, -1, selected, candidates); assertNotNull(result); assertEquals(2, result.getId()); }
@Test public void testNullIfNoTrue() { List<Result> selected = new ArrayList<>(); List<Result> candidates = new ArrayList<>(); candidates.add(Results.create(1,1)); candidates.add(Results.create(3,3)); Result result = oddOnly.nextItem(0, -1, selected, candidates); assertNull(result); }