@Test public void validate_shouldThrowExeception_whenRegexStringIsEmpty() throws Exception { str = "abc"; boolean threwException = false; try { regexMatcher.validate(str, ""); } catch (IllegalArgumentException expectedException) { threwException = true; } assertEquals(true, threwException); }
public boolean validate(String dataStr, String regex) { if (regex == null || regex.equals("")) { throw new IllegalArgumentException("regex field cannot is be null or empty!"); } else { Pattern p = Pattern.compile(regex); return validate(dataStr, p); } }
RegexMatcher { public boolean validate(String dataStr, String regex) { if (regex == null || regex.equals("")) { throw new IllegalArgumentException("regex field cannot is be null or empty!"); } else { Pattern p = Pattern.compile(regex); return validate(dataStr, p); } } }
RegexMatcher { public boolean validate(String dataStr, String regex) { if (regex == null || regex.equals("")) { throw new IllegalArgumentException("regex field cannot is be null or empty!"); } else { Pattern p = Pattern.compile(regex); return validate(dataStr, p); } }  }
RegexMatcher { public boolean validate(String dataStr, String regex) { if (regex == null || regex.equals("")) { throw new IllegalArgumentException("regex field cannot is be null or empty!"); } else { Pattern p = Pattern.compile(regex); return validate(dataStr, p); } }  boolean validate(String dataStr, String regex); boolean find(String dataStr, String regex); boolean validate(String dataStr, Pattern pattern); boolean find(String dataStr, Pattern pattern); }
RegexMatcher { public boolean validate(String dataStr, String regex) { if (regex == null || regex.equals("")) { throw new IllegalArgumentException("regex field cannot is be null or empty!"); } else { Pattern p = Pattern.compile(regex); return validate(dataStr, p); } }  boolean validate(String dataStr, String regex); boolean find(String dataStr, String regex); boolean validate(String dataStr, Pattern pattern); boolean find(String dataStr, Pattern pattern);  }