MatchFunction implements DDMExpressionFunction.Function2<String, String, Boolean> { @Override public Boolean apply(String value, String regex) { try { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(value); return matcher.matches(); } catch (Exception exception) { if (_log.isDebugEnabled()) { _log.debug(exception, exception); } } return false; }  @Override Boolean apply(String value, String regex); @Override String getName(); static final String NAME; }
@Test public void testInvalidRegex() { MatchFunction matchFunction = new MatchFunction(); Boolean result = matchFunction.apply( "test@liferay", "\\\\S+[@\\S+\\.\\S+"); Assert.assertFalse(result); }
@Test public void testNotMatch() { MatchFunction matchFunction = new MatchFunction(); Boolean result = matchFunction.apply( "test@liferay", "\\S+@\\S+\\.\\S+"); Assert.assertFalse(result); }
@Test public void testValidMatch() { MatchFunction matchFunction = new MatchFunction(); Boolean result = matchFunction.apply( "test@liferay.com", "\\S+@\\S+\\.\\S+"); Assert.assertTrue(result); }