ActorsPackageGenerated implements ActorsPackageGenerator { @NotNull @Override public JavaFile generate(@NonNull List<? extends ActorInterfaceGenerated> interfaces) { final ClassName builderClass = ClassName.get(mPackageName, mClassName); final TypeSpec.Builder builder = TypeSpec.classBuilder(mClassName); builder.addModifiers(Modifier.FINAL); if (mAccessLevel == ActorsPackage.AccessLevel.Public) { builder.addModifiers(Modifier.PUBLIC); } builder.addField(FailureHandler.class, FIELD_ERROR_HANDLER, Modifier.PRIVATE); builder.addField(ProxyFactoryBase.class, FIELD_PROXY_FACTORY, Modifier.PRIVATE); builder.addMethod(generateHandlerSetter(builderClass)); builder.addMethod(generateProxyFactorySetter(builderClass)); TypeSpec threads = generateThreadsClass(); TypeSpec proxyFactory = generateProxyFactory(interfaces); builder.addMethod(generateBuild(threads, proxyFactory, ClassName.get(CrashEarlyFailureHandler.class))); builder.addType(threads); builder.addType(proxyFactory); return JavaFile.builder(mPackageName, builder.build()).build(); } ActorsPackageGenerated(@NotNull ActorsPackageDescription description); @NotNull @Override JavaFile generate(@NonNull List<? extends ActorInterfaceGenerated> interfaces);  }
@Test public void generate_validPackageLevel_withProxies() { ActorsPackageGenerated generated = new ActorsPackageGenerated(mDescription); List<ActorInterfaceGenerated> proxies = new ArrayList<>(); proxies.add(createProxy("com.truecaller.androidactors", "TestProxy")); JavaFile file = generated.generate(proxies); Assert.assertEquals(PACKAGE_NAME, file.packageName); verifyClass(file.typeSpec, false); ClassName self = ClassName.get(file.packageName, file.typeSpec.name); TypeSpec cls = file.typeSpec; verifyErrorHandlerField(cls.fieldSpecs); verifyProxyFactoryField(cls.fieldSpecs); verifyErrorHandlerSetter(self, cls.methodSpecs); verifyProxyFactorySetter(self, cls.methodSpecs); verifyBuildMethod(cls.methodSpecs); verifyProxyFactoryClass(cls.typeSpecs); }
@Test public void generate_validPublicLevel_withoutProxies() { Mockito.doReturn(ActorsPackage.AccessLevel.Public).when(mDescription).getAccessLevel(); ActorsPackageGenerated generated = new ActorsPackageGenerated(mDescription); List<ActorInterfaceGenerated> proxies = new ArrayList<>(); JavaFile file = generated.generate(proxies); Assert.assertEquals(PACKAGE_NAME, file.packageName); verifyClass(file.typeSpec, true); ClassName self = ClassName.get(file.packageName, file.typeSpec.name); TypeSpec cls = file.typeSpec; verifyErrorHandlerField(cls.fieldSpecs); verifyProxyFactoryField(cls.fieldSpecs); verifyErrorHandlerSetter(self, cls.methodSpecs); verifyProxyFactorySetter(self, cls.methodSpecs); verifyBuildMethod(cls.methodSpecs); verifyProxyFactoryClass(cls.typeSpecs); }