FlickrAgent extends AbstractAgent { protected String getSearchPhrase(String request) { String phrase = null; Matcher matcher = pattern.matcher(request); if (matcher.find()) { if (matcher.group(2) != null) { phrase = matcher.group(2).trim(); } } return phrase; } FlickrAgent(HttpClient client, String apikey); @Override AgentResponse process(AgentRequest request);  }
@Test public void testRegex() { HttpClient client = mock(HttpClient.class); FlickrAgent agent = new FlickrAgent(client, "key"); assertEquals("apple", agent.getSearchPhrase("show me an apple")); assertEquals("apple", agent.getSearchPhrase("Show me an apple")); assertEquals("apple", agent.getSearchPhrase("Show me a apple")); assertEquals("apple", agent.getSearchPhrase("Show me the apple")); assertEquals("apple", agent.getSearchPhrase("Show me apple")); assertEquals("apple", agent.getSearchPhrase("Show me a apple ")); assertEquals("apple pie", agent.getSearchPhrase("Show me an apple pie")); }