ReferenceBuilder extends AbstractReferenceBuilder<ReferenceConfig, ReferenceBuilder<T>> { public ReferenceConfig<T> build() { ReferenceConfig<T> reference = new ReferenceConfig<>(); super.build(reference); reference.setInterface(interfaceName); if (interfaceClass != null) { reference.setInterface(interfaceClass); } reference.setClient(client); reference.setUrl(url); reference.setMethods(methods); reference.setConsumer(consumer); reference.setProtocol(protocol); reference.setServices(services); return reference; }  static ReferenceBuilder newBuilder(); ReferenceBuilder<T> id(String id); ReferenceBuilder<T> interfaceName(String interfaceName); ReferenceBuilder<T> interfaceClass(Class<?> interfaceClass); ReferenceBuilder<T> client(String client); ReferenceBuilder<T> url(String url); ReferenceBuilder<T> addMethods(List<MethodConfig> methods); ReferenceBuilder<T> addMethod(MethodConfig method); ReferenceBuilder<T> consumer(ConsumerConfig consumer); ReferenceBuilder<T> protocol(String protocol); ReferenceBuilder<T> services(String service, String... otherServices); ReferenceConfig<T> build();  }
@Test void build() { ConsumerConfig consumer = new ConsumerConfig(); MethodConfig method = new MethodConfig(); ReferenceBuilder<DemoService> builder = new ReferenceBuilder<>(); builder.id("id") .interfaceClass(DemoService.class) .protocol("protocol") .client("client") .url("url") .consumer(consumer) .addMethod(method) .services("test-service", "test-service2"); ReferenceConfig config = builder.build(); ReferenceConfig config2 = builder.build(); Assertions.assertEquals("org.apache.dubbo.config.api.DemoService", config.getInterface()); Assertions.assertEquals(DemoService.class, config.getInterfaceClass()); Assertions.assertEquals("protocol", config.getProtocol()); Assertions.assertEquals("client", config.getClient()); Assertions.assertEquals("url", config.getUrl()); Assertions.assertEquals(consumer, config.getConsumer()); Assertions.assertEquals("test-service,test-service2", config.getServices()); Assertions.assertEquals(ofSet("test-service", "test-service2"), config.getSubscribedServices()); Assertions.assertTrue(config.getMethods().contains(method)); Assertions.assertEquals(1, config.getMethods().size()); Assertions.assertNotSame(config, config2); }