### Question:
SearchResultExtractor implements Extractor<List<Integer>> { @Override public List<Integer> extract(List<String> messages) { final List<Integer> uids = Lists.newArrayList(); for (int i = 0, messagesSize = messages.size(); i < messagesSize; i++) { String message = messages.get(i); if (null == message || message.isEmpty()) continue; try { if (Command.OK_SUCCESS.matcher(message).matches() || Command.isEndOfSequence(message) || MessageStatusExtractor.HELPFUL_NOTIFICATION_PATTERN.matcher(message).matches()) continue; } catch (ExtractionException ee) { log.error("Warning: error parsing search results! {}", messages, ee); continue; } message = message.substring("* search".length()); if (message.trim().isEmpty()) continue; for (String piece : message.split("[ ]+")) { if (piece.isEmpty()) continue; try { uids.add(Integer.valueOf(piece)); } catch (NumberFormatException nfe) { log.error("Unable to parse search result {}", message, nfe); } } } return uids; }  @Override List<Integer> extract(List<String> messages);  }### Answer:
@Test public void testExtract() throws Exception { List<String> messages = ImmutableList.of( "* search 123 3 6 4 -10" ); assertEquals(Arrays.asList(123, 3, 6, 4, -10), new SearchResultExtractor().extract(messages)); }
@Test public void testExtractLonger() throws Exception { List<String> messages = ImmutableList.of( "* search 42187 275543 287963 298411 298834 299843 305799 306131 319620 323938 328364 329370 329566 329599 331454 332401 338293 339646 341368 342169 342969 343541 344924 345047 345730 348037 349247 351914 351941 351945 352041 352461 352462", "* Ok SEARCH completed (Success)" ); String thing = "[42187 275543 287963 298411 298834 299843 305799 306131 319620 323938 328364 329370 329566 329599 331454 332401 338293 339646 341368 342169 342969 343541 344924 345047 345730 348037 349247 351914 351941 351945 352041 352461 352462]".replace(" ", ", "); assertEquals(thing, new SearchResultExtractor().extract(messages).toString()); }
@Test public void testExtractNoResults() throws Exception { List<String> messages = ImmutableList.of( "* search" ); assertEquals(0, new SearchResultExtractor().extract(messages).size()); }