### Question:
LongestTraceStorageStrategy implements TraceStorageStrategy { @Override public RequestTrace getTraceForRemoval(Collection<RequestTrace> traces, int maxSize, RequestTrace traceToRemove) { if (traces == null || traces.isEmpty() || traces.size() <= maxSize) { return null; } return traceToRemove != null && traces.contains(traceToRemove) ? traceToRemove : findShortestTrace(traces); }  @Override RequestTrace getTraceForRemoval(Collection<RequestTrace> traces, int maxSize, RequestTrace traceToRemove);  }### Answer:
@Test public void shortestTraceIsRemovedAboveMaxSize() { int maxSize = 10; List<RequestTrace> traces = new ArrayList<>(); for (int i = 0; i < maxSize; i++) { traces.add(createTrace(1000000000L * (i+1))); } List<RequestTrace> added = new ArrayList<>(); List<RequestTrace> removed = new ArrayList<>(); for (int i = 0; i < maxSize; i++) { RequestTrace newTrace = createTrace(1000000000L * (i+1) - 500000000L); added.add(newTrace); traces.add(newTrace); RequestTrace traceForRemoval = strategy.getTraceForRemoval(traces, maxSize, null); assertTrue(traceForRemoval.getElapsedTime() <= newTrace.getElapsedTime()); for (int j = 0; j < maxSize; j++) { RequestTrace candidate = traces.get(j); assertSame(candidate, strategy.getTraceForRemoval(traces, maxSize, candidate)); } removed.add(traceForRemoval); traces.remove(traceForRemoval); } added.removeAll(removed); assertEquals(maxSize/2, added.size()); }