AdaptiveClassCodeGenerator { public String generate() { if (!hasAdaptiveMethod()) { throw new IllegalStateException("No adaptive method exist on extension " + type.getName() + ", refuse to create the adaptive class!"); } StringBuilder code = new StringBuilder(); code.append(generatePackageInfo()); code.append(generateImports()); code.append(generateClassDeclaration()); Method[] methods = type.getMethods(); for (Method method : methods) { code.append(generateMethod(method)); } code.append("}"); if (logger.isDebugEnabled()) { logger.debug(code.toString()); } return code.toString(); } AdaptiveClassCodeGenerator(Class<?> type, String defaultExtName); String generate();  }
@Test public void testGenerate() throws IOException { AdaptiveClassCodeGenerator generator = new AdaptiveClassCodeGenerator(HasAdaptiveExt.class, "adaptive"); String value = generator.generate(); URL url = getClass().getResource("/org/apache/dubbo/common/extension/adaptive/HasAdaptiveExt$Adaptive"); try (InputStream inputStream = url.openStream()) { String content = IOUtils.read(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); content = content.replaceAll("\r",""); assertTrue(content.contains(value)); } }