NameUtils { private static String approximateSimpleName(Class<?> clazz, boolean dropOuterClassNames) { checkArgument(!clazz.isAnonymousClass(), "Attempted to get simple name of anonymous class"); return approximateSimpleName(clazz.getName(), dropOuterClassNames); }  static String approximateSimpleName(Object object); static String approximateSimpleName(Object object, String anonymousValue); static String approximatePTransformName(Class<?> clazz);  }
@Test public void testDropsStandardSuffixes() { assertEquals("Embedded", NameUtils.approximateSimpleName("EmbeddedDoFn", true)); assertEquals("Embedded", NameUtils.approximateSimpleName("EmbeddedFn", true)); assertEquals("Embedded", NameUtils.approximateSimpleName("EmbeddedDoFn", false)); assertEquals("Embedded", NameUtils.approximateSimpleName("EmbeddedFn", false)); }
@Test public void testDropsStandardSuffixesInAllComponents() { assertEquals("Embedded", NameUtils.approximateSimpleName("SomeDoFn$EmbeddedDoFn", true)); assertEquals("Embedded", NameUtils.approximateSimpleName("SomeFn$EmbeddedFn", true)); assertEquals("Some.Embedded", NameUtils.approximateSimpleName("SomeDoFn$EmbeddedDoFn", false)); assertEquals("Some.Embedded", NameUtils.approximateSimpleName("SomeFn$EmbeddedFn", false)); }
@Test public void testDropsOuterClassNamesTrue() { assertEquals("Bar", NameUtils.approximateSimpleName("Foo$1$Bar", true)); assertEquals("Foo$1", NameUtils.approximateSimpleName("Foo$1", true)); assertEquals("Foo$1$2", NameUtils.approximateSimpleName("Foo$1$2", true)); }
@Test public void testDropsOuterClassNamesFalse() { assertEquals("Foo.Bar", NameUtils.approximateSimpleName("Foo$1$Bar", false)); assertEquals("Foo.1", NameUtils.approximateSimpleName("Foo$1", false)); assertEquals("Foo.2", NameUtils.approximateSimpleName("Foo$1$2", false)); }
@Test public void testSimpleName() { assertEquals("Embedded", NameUtils.approximateSimpleName(new EmbeddedDoFn())); }
@Test public void testAnonSimpleName() throws Exception { assertEquals("Anonymous", NameUtils.approximateSimpleName(new EmbeddedDoFn() {})); }
@Test public void testNestedSimpleName() { EmbeddedDoFn fn = new EmbeddedDoFn(); EmbeddedDoFn inner = fn.getEmbedded(); assertEquals("DeeperEmbedded", NameUtils.approximateSimpleName(inner)); }
@Test public void testApproximateSimpleNameOverride() { NameOverride overriddenName = () -> "CUSTOM_NAME"; assertEquals("CUSTOM_NAME", NameUtils.approximateSimpleName(overriddenName)); }
@Test public void testApproximateSimpleNameCustomAnonymous() { Object overriddenName = new Object() {}; assertEquals("CUSTOM_NAME", NameUtils.approximateSimpleName(overriddenName, "CUSTOM_NAME")); }