### Question:
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);  }### Answer:
@Test public void testSimpleNames() throws ScriptException { DefaultNameStrategy nameStrategy = new DefaultNameStrategy(); assertThat(nameStrategy.getFullName("public class Alpha {}")).isEqualTo("Alpha"); assertThat(nameStrategy.getFullName("public class Beta$ {}")).isEqualTo("Beta$"); }
@Test public void testPackageAndNames() throws ScriptException { DefaultNameStrategy nameStrategy = new DefaultNameStrategy(); assertThat(nameStrategy.getFullName("package com.example; public class Alpha {}")).isEqualTo("com.example.Alpha"); }
@Test public void testMultipleLines() throws ScriptException { DefaultNameStrategy nameStrategy = new DefaultNameStrategy(); assertThat(nameStrategy.getFullName("" + "\n" + "package com.example;\n" + "public class Alpha {\n" + "}")) .isEqualTo("com.example.Alpha"); assertThat(nameStrategy.getFullName("" + "\n" + "package \n" + " com.example ;\n" + "\n" + "public\n" + "\tclass\n" + "\n" + "Alpha\n" + "{\n" + "}")) .isEqualTo("com.example.Alpha"); }
@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); }