MonitorBuilder extends AbstractBuilder<MonitorConfig, MonitorBuilder> { public MonitorConfig build() { MonitorConfig monitorConfig = new MonitorConfig(); super.build(monitorConfig); monitorConfig.setProtocol(protocol); monitorConfig.setAddress(address); monitorConfig.setUsername(username); monitorConfig.setPassword(password); monitorConfig.setGroup(group); monitorConfig.setVersion(version); monitorConfig.setInterval(interval); monitorConfig.setParameters(parameters); monitorConfig.setDefault(isDefault); return monitorConfig; }  MonitorBuilder protocol(String protocol); MonitorBuilder address(String address); MonitorBuilder username(String username); MonitorBuilder password(String password); MonitorBuilder group(String group); MonitorBuilder version(String version); MonitorBuilder interval(String interval); MonitorBuilder isDefault(Boolean isDefault); MonitorBuilder appendParameter(String key, String value); MonitorBuilder appendParameters(Map<String, String> appendParameters); MonitorConfig build();  }
@Test void build() { MonitorBuilder builder = new MonitorBuilder(); builder.protocol("protocol").address("address").group("group").interval("interval").isDefault(true) .password("password").username("username").version("version") .appendParameter("default.num", "one").id("id").prefix("prefix"); MonitorConfig config = builder.build(); MonitorConfig config2 = builder.build(); Assertions.assertEquals("protocol", config.getProtocol()); Assertions.assertEquals("address", config.getAddress()); Assertions.assertEquals("group", config.getGroup()); Assertions.assertEquals("interval", config.getInterval()); Assertions.assertEquals("password", config.getPassword()); Assertions.assertEquals("username", config.getUsername()); Assertions.assertEquals("version", config.getVersion()); Assertions.assertTrue(config.isDefault()); Assertions.assertTrue(config.getParameters().containsKey("default.num")); Assertions.assertEquals("one", config.getParameters().get("default.num")); Assertions.assertEquals("id", config.getId()); Assertions.assertEquals("prefix", config.getPrefix()); Assertions.assertNotSame(config, config2); }