WhenPatternMatcher { public boolean matches(String text) { if (args.isEmpty()) { return when.equalsIgnoreCase(text); } try { return extractArguments(text).size() == args.size(); } catch (Exception e) { return false; } } WhenPatternMatcher(String when); boolean matches(String text); boolean hasArguments(); Map<String, String> getOperationArguments(String stepText);  }
@Test public void testMatcherWithoutArguments() { WhenPatternMatcher matcher = new WhenPatternMatcher("a search for something"); assertTrue(matcher.matches("a search for something")); assertFalse(matcher.matches("a search for test is not done")); }
@Test public void testMatcherWithSingleArgument() { WhenPatternMatcher matcher = new WhenPatternMatcher("a search for {owner} is done"); assertTrue(matcher.matches("a search for owner is done")); assertTrue(matcher.matches("a search for \"test\" is done")); assertTrue(matcher.matches("a search for \"value with space\" is done")); assertFalse(matcher.matches("a search for test is not done")); assertFalse(matcher.matches("a search \" for test is not done")); assertFalse(matcher.matches("another search for test is not done")); assertFalse(matcher.matches("test is not done")); assertFalse(matcher.matches("a search for test")); }