@Test public void failSimpleNames() { DefaultNameStrategy nameStrategy = new DefaultNameStrategy(); assertThatThrownBy(() -> { nameStrategy.getFullName(""); }).isInstanceOf(ScriptException.class); assertThatThrownBy(() -> { nameStrategy.getFullName("public class {}"); }).isInstanceOf(ScriptException.class); assertThatThrownBy(() -> { nameStrategy.getFullName("class Alpha {}"); }).isInstanceOf(ScriptException.class); }
@Override public String getFullName(String script) throws ScriptException { String fullPackage = null; Matcher packageMatcher = PACKAGE_PATTERN.matcher(script); if (packageMatcher.find()) { fullPackage = packageMatcher.group(1); } Matcher nameMatcher = NAME_PATTERN.matcher(script); if (nameMatcher.find()) { String name = nameMatcher.group(1); if (fullPackage == null) { return name; } else { return fullPackage + "." + name; } } throw new ScriptException("Could not determine fully qualified class name"); }
DefaultNameStrategy implements NameStrategy { @Override public String getFullName(String script) throws ScriptException { String fullPackage = null; Matcher packageMatcher = PACKAGE_PATTERN.matcher(script); if (packageMatcher.find()) { fullPackage = packageMatcher.group(1); } Matcher nameMatcher = NAME_PATTERN.matcher(script); if (nameMatcher.find()) { String name = nameMatcher.group(1); if (fullPackage == null) { return name; } else { return fullPackage + "." + name; } } throw new ScriptException("Could not determine fully qualified class name"); } }
DefaultNameStrategy implements NameStrategy { @Override public String getFullName(String script) throws ScriptException { String fullPackage = null; Matcher packageMatcher = PACKAGE_PATTERN.matcher(script); if (packageMatcher.find()) { fullPackage = packageMatcher.group(1); } Matcher nameMatcher = NAME_PATTERN.matcher(script); if (nameMatcher.find()) { String name = nameMatcher.group(1); if (fullPackage == null) { return name; } else { return fullPackage + "." + name; } } throw new ScriptException("Could not determine fully qualified class name"); }  }
DefaultNameStrategy implements NameStrategy { @Override public String getFullName(String script) throws ScriptException { String fullPackage = null; Matcher packageMatcher = PACKAGE_PATTERN.matcher(script); if (packageMatcher.find()) { fullPackage = packageMatcher.group(1); } Matcher nameMatcher = NAME_PATTERN.matcher(script); if (nameMatcher.find()) { String name = nameMatcher.group(1); if (fullPackage == null) { return name; } else { return fullPackage + "." + name; } } throw new ScriptException("Could not determine fully qualified class name"); }  @Override String getFullName(String script); }
DefaultNameStrategy implements NameStrategy { @Override public String getFullName(String script) throws ScriptException { String fullPackage = null; Matcher packageMatcher = PACKAGE_PATTERN.matcher(script); if (packageMatcher.find()) { fullPackage = packageMatcher.group(1); } Matcher nameMatcher = NAME_PATTERN.matcher(script); if (nameMatcher.find()) { String name = nameMatcher.group(1); if (fullPackage == null) { return name; } else { return fullPackage + "." + name; } } throw new ScriptException("Could not determine fully qualified class name"); }  @Override String getFullName(String script);  }