@Test public void testTuneInterfaces(@TuneProvider(INTERFACES) Tune tune) { TypeSpec.Builder builder = TypeSpec.classBuilder("Test"); TypeModel model = new TypeModel(); List<GenericVariableModel> genericVariables = Collections.singletonList(new GenericVariableModel("T")); MetaInfo metaInfo = new MetaInfo(null, null, getTypeVariables(genericVariables, tune.getChords())); new InterfaceHandler(tune, metaInfo, null).process(builder, model); TypeSpec spec = builder.build(); assertEquals("Test", spec.name, "Wrong class name found"); List<TypeName> interfaces = spec.superinterfaces; assertEquals(2, interfaces.size(), "No interfaces found"); TypeName interfaceType = interfaces.get(0); assertTrue(interfaceType instanceof ClassName, "Wrong type of TypeName found"); ClassName interfaceClassName = (ClassName) interfaceType; assertAll("Class and package name assertions", () -> assertEquals("java.io", interfaceClassName.packageName()), () -> assertEquals("Serializable", interfaceClassName.simpleName())); TypeName interfaceTypeThree = interfaces.get(1); assertTrue(interfaceTypeThree instanceof ParameterizedTypeName); ParameterizedTypeName interfaceThreeClassName = (ParameterizedTypeName) interfaceTypeThree; assertAll("Class and package name assertions", () -> assertEquals("com.flipkart.lyrics.test.classes", interfaceThreeClassName.rawType.packageName()), () -> assertEquals("GenericInterface", interfaceThreeClassName.rawType.simpleName())); assertEquals(1, interfaceThreeClassName.typeArguments.size(), "Mismatch in number of generic variables"); }
@Override public void process(TypeSpec.Builder typeSpec, TypeModel typeModel) { Set<VariableModel> interfaceDefinitions = new HashSet<>(); interfaceDefinitions.addAll(tune.interfaces()); interfaceDefinitions.addAll(typeModel.getInterfaces()); if (interfaceDefinitions.size() == 0) { return; } List<TypeName> interfaces = interfaceDefinitions.stream() .map(model -> getResolvedTypeName(model, metaInfo.getGenericVariables(), tune.getChords())) .collect(Collectors.toList()); typeSpec.addSuperinterfaces(interfaces); }
InterfaceHandler extends Handler { @Override public void process(TypeSpec.Builder typeSpec, TypeModel typeModel) { Set<VariableModel> interfaceDefinitions = new HashSet<>(); interfaceDefinitions.addAll(tune.interfaces()); interfaceDefinitions.addAll(typeModel.getInterfaces()); if (interfaceDefinitions.size() == 0) { return; } List<TypeName> interfaces = interfaceDefinitions.stream() .map(model -> getResolvedTypeName(model, metaInfo.getGenericVariables(), tune.getChords())) .collect(Collectors.toList()); typeSpec.addSuperinterfaces(interfaces); } }
InterfaceHandler extends Handler { @Override public void process(TypeSpec.Builder typeSpec, TypeModel typeModel) { Set<VariableModel> interfaceDefinitions = new HashSet<>(); interfaceDefinitions.addAll(tune.interfaces()); interfaceDefinitions.addAll(typeModel.getInterfaces()); if (interfaceDefinitions.size() == 0) { return; } List<TypeName> interfaces = interfaceDefinitions.stream() .map(model -> getResolvedTypeName(model, metaInfo.getGenericVariables(), tune.getChords())) .collect(Collectors.toList()); typeSpec.addSuperinterfaces(interfaces); } InterfaceHandler(Tune tune, MetaInfo metaInfo, RuleSet ruleSet); }
InterfaceHandler extends Handler { @Override public void process(TypeSpec.Builder typeSpec, TypeModel typeModel) { Set<VariableModel> interfaceDefinitions = new HashSet<>(); interfaceDefinitions.addAll(tune.interfaces()); interfaceDefinitions.addAll(typeModel.getInterfaces()); if (interfaceDefinitions.size() == 0) { return; } List<TypeName> interfaces = interfaceDefinitions.stream() .map(model -> getResolvedTypeName(model, metaInfo.getGenericVariables(), tune.getChords())) .collect(Collectors.toList()); typeSpec.addSuperinterfaces(interfaces); } InterfaceHandler(Tune tune, MetaInfo metaInfo, RuleSet ruleSet); @Override void process(TypeSpec.Builder typeSpec, TypeModel typeModel); }
InterfaceHandler extends Handler { @Override public void process(TypeSpec.Builder typeSpec, TypeModel typeModel) { Set<VariableModel> interfaceDefinitions = new HashSet<>(); interfaceDefinitions.addAll(tune.interfaces()); interfaceDefinitions.addAll(typeModel.getInterfaces()); if (interfaceDefinitions.size() == 0) { return; } List<TypeName> interfaces = interfaceDefinitions.stream() .map(model -> getResolvedTypeName(model, metaInfo.getGenericVariables(), tune.getChords())) .collect(Collectors.toList()); typeSpec.addSuperinterfaces(interfaces); } InterfaceHandler(Tune tune, MetaInfo metaInfo, RuleSet ruleSet); @Override void process(TypeSpec.Builder typeSpec, TypeModel typeModel);  }