@Test public void testClassNameParsing() { assertThat(Compilations.getPublicClassName( "public class A { public static void main(String[] args) {} } class B {}")) .isEqualTo("A"); assertThat(Compilations.getPublicClassName("public class X extends Object {}")) .isEqualTo("X"); assertThat(Compilations.getPublicClassName( "public class X extends Object {} public class Y extends Object {}")) .isEqualTo("X"); assertThat(Compilations .getPublicClassName("class X extends Object {} public class Y extends Object {}")) .isEqualTo("Y"); assertThat(Compilations .getPublicClassName("class X extends Object {}\npublic class Y extends Object {}")) .isEqualTo("Y"); assertThat(Compilations .getPublicClassName("class X extends Object {}public class Y extends Object {}")) .isEqualTo("Y"); assertThat(Compilations.getPublicClassName("class X extends Object {}")).isEqualTo(""); }
@VisibleForTesting static String getPublicClassName(String source) { Matcher matcher = CLASS_NAME_PATTERN.matcher(source); if (matcher.find()) { return getPackagePrefix(source) + matcher.group(1); } else { return ""; } }
Compilations { @VisibleForTesting static String getPublicClassName(String source) { Matcher matcher = CLASS_NAME_PATTERN.matcher(source); if (matcher.find()) { return getPackagePrefix(source) + matcher.group(1); } else { return ""; } } }
Compilations { @VisibleForTesting static String getPublicClassName(String source) { Matcher matcher = CLASS_NAME_PATTERN.matcher(source); if (matcher.find()) { return getPackagePrefix(source) + matcher.group(1); } else { return ""; } } private  Compilations(); }
Compilations { @VisibleForTesting static String getPublicClassName(String source) { Matcher matcher = CLASS_NAME_PATTERN.matcher(source); if (matcher.find()) { return getPackagePrefix(source) + matcher.group(1); } else { return ""; } } private  Compilations(); static Class<?> compile(String source); }
Compilations { @VisibleForTesting static String getPublicClassName(String source) { Matcher matcher = CLASS_NAME_PATTERN.matcher(source); if (matcher.find()) { return getPackagePrefix(source) + matcher.group(1); } else { return ""; } } private  Compilations(); static Class<?> compile(String source);  }