ActorInterfaceGeneratedImpl implements ActorInterfaceGenerator { @NotNull public JavaFile generate(NamesProvider namesProvider) { TypeSpec.Builder _class = TypeSpec.classBuilder(getProxyName()); _class.addModifiers(Modifier.FINAL, Modifier.PUBLIC); _class.addField(MessageSender.class, MESSAGE_SENDER_FIELD, Modifier.PRIVATE, Modifier.FINAL); _class.addSuperinterface(ClassName.get(mActor)); _class.addJavadoc("@hide"); _class.addMethod(generateConstructor()); _class.addMethod(generateCompareMethod()); TypeName actorType = TypeName.get(mActor.asType()); for (Message message : mMessages) { TypeSpec messageType = message.generate(actorType, namesProvider); _class.addType(messageType); _class.addMethod(generateMethod(message, messageType)); } return JavaFile.builder(extractActorPackage(mActor), _class.build()).build(); } ActorInterfaceGeneratedImpl(@NotNull ActorInterfaceDescription _interface); @NotNull JavaFile generate(NamesProvider namesProvider); @NotNull @Override String getProxyName(); @NotNull @Override String getProxyPackage();  }
@Test public void generate_flatClassName_SimpleActor() { setTypeElement(SimpleActor.class); ActorInterfaceGeneratedImpl generated = new ActorInterfaceGeneratedImpl(mDescription); JavaFile file = generated.generate(mNamesProvider); Assert.assertEquals("com.truecaller.androidactors.cases", file.packageName); Assert.assertEquals("SimpleActor$Proxy", file.typeSpec.name); }
@Test public void generate_nestedInInterfaceName_NestedActor() { setTypeElement(ActorContainerInterface.NestedActor.class); ActorInterfaceGeneratedImpl generated = new ActorInterfaceGeneratedImpl(mDescription); JavaFile file = generated.generate(mNamesProvider); Assert.assertEquals("com.truecaller.androidactors.cases", file.packageName); Assert.assertEquals("ActorContainerInterface$NestedActor$Proxy", file.typeSpec.name); }
@Test public void generate_nestedInClassName_NestedActor() { setTypeElement(ActorContainerClass.NestedActor.class); ActorInterfaceGeneratedImpl generated = new ActorInterfaceGeneratedImpl(mDescription); JavaFile file = generated.generate(mNamesProvider); Assert.assertEquals("com.truecaller.androidactors.cases", file.packageName); Assert.assertEquals("ActorContainerClass$NestedActor$Proxy", file.typeSpec.name); }
@Test public void generate_validMethods_SimpleActor() { setTypeElement(SimpleActor.class); List<Method> methods = new ArrayList<>(); methods.add(method("save", argument("key", TypeKind.LONG), argument("value", String.class.getCanonicalName(), true))); methods.add(method("get", String.class.getCanonicalName(), argument("key", TypeKind.LONG))); Mockito.doReturn(methods).when(mDescription).methods(); ActorInterfaceGeneratedImpl generated = new ActorInterfaceGeneratedImpl(mDescription); JavaFile file = generated.generate(mNamesProvider); validateSaveMethod(file.typeSpec.methodSpecs); validateGetMethod(file.typeSpec.methodSpecs); }