@Test public void typeSpecShouldOnlyImplementOneInterface() { TypeSpec typeSpec = entanglingClass.createTypeSpec(); assertThat(typeSpec.superinterfaces, hasSize(1)); }
@VisibleForTesting TypeSpec createTypeSpec() { TypeSpec.Builder result = TypeSpec.classBuilder(className) .addModifiers(PUBLIC) .addTypeVariable(TypeVariableName.get("T", ClassName.bestGuess(targetClass))); result.addSuperinterface(ClassName.get("java.util", "Observer")); result.addMethod(createEntangleMethod()); result.addMethod(createDetangleMethod()); result.addMethod(createUpdateMethod()); result.addField(FieldSpec.builder(TypeVariableName.get("T", ClassName.bestGuess(targetClass)), "target") .addModifiers(PRIVATE) .build()); result.addField(FieldSpec.builder(String.class, "id").initializer("\"$L\"", connectionId) .addModifiers(PRIVATE) .build()); return result.build(); }
EntanglingClass { @VisibleForTesting TypeSpec createTypeSpec() { TypeSpec.Builder result = TypeSpec.classBuilder(className) .addModifiers(PUBLIC) .addTypeVariable(TypeVariableName.get("T", ClassName.bestGuess(targetClass))); result.addSuperinterface(ClassName.get("java.util", "Observer")); result.addMethod(createEntangleMethod()); result.addMethod(createDetangleMethod()); result.addMethod(createUpdateMethod()); result.addField(FieldSpec.builder(TypeVariableName.get("T", ClassName.bestGuess(targetClass)), "target") .addModifiers(PRIVATE) .build()); result.addField(FieldSpec.builder(String.class, "id").initializer("\"$L\"", connectionId) .addModifiers(PRIVATE) .build()); return result.build(); } }
EntanglingClass { @VisibleForTesting TypeSpec createTypeSpec() { TypeSpec.Builder result = TypeSpec.classBuilder(className) .addModifiers(PUBLIC) .addTypeVariable(TypeVariableName.get("T", ClassName.bestGuess(targetClass))); result.addSuperinterface(ClassName.get("java.util", "Observer")); result.addMethod(createEntangleMethod()); result.addMethod(createDetangleMethod()); result.addMethod(createUpdateMethod()); result.addField(FieldSpec.builder(TypeVariableName.get("T", ClassName.bestGuess(targetClass)), "target") .addModifiers(PRIVATE) .build()); result.addField(FieldSpec.builder(String.class, "id").initializer("\"$L\"", connectionId) .addModifiers(PRIVATE) .build()); return result.build(); } EntanglingClass(String classPackage, String className, String targetClass, String fieldName, String connectionId); }
EntanglingClass { @VisibleForTesting TypeSpec createTypeSpec() { TypeSpec.Builder result = TypeSpec.classBuilder(className) .addModifiers(PUBLIC) .addTypeVariable(TypeVariableName.get("T", ClassName.bestGuess(targetClass))); result.addSuperinterface(ClassName.get("java.util", "Observer")); result.addMethod(createEntangleMethod()); result.addMethod(createDetangleMethod()); result.addMethod(createUpdateMethod()); result.addField(FieldSpec.builder(TypeVariableName.get("T", ClassName.bestGuess(targetClass)), "target") .addModifiers(PRIVATE) .build()); result.addField(FieldSpec.builder(String.class, "id").initializer("\"$L\"", connectionId) .addModifiers(PRIVATE) .build()); return result.build(); } EntanglingClass(String classPackage, String className, String targetClass, String fieldName, String connectionId);  }
EntanglingClass { @VisibleForTesting TypeSpec createTypeSpec() { TypeSpec.Builder result = TypeSpec.classBuilder(className) .addModifiers(PUBLIC) .addTypeVariable(TypeVariableName.get("T", ClassName.bestGuess(targetClass))); result.addSuperinterface(ClassName.get("java.util", "Observer")); result.addMethod(createEntangleMethod()); result.addMethod(createDetangleMethod()); result.addMethod(createUpdateMethod()); result.addField(FieldSpec.builder(TypeVariableName.get("T", ClassName.bestGuess(targetClass)), "target") .addModifiers(PRIVATE) .build()); result.addField(FieldSpec.builder(String.class, "id").initializer("\"$L\"", connectionId) .addModifiers(PRIVATE) .build()); return result.build(); } EntanglingClass(String classPackage, String className, String targetClass, String fieldName, String connectionId);   }