polish: Use ObjectUtils#isEmpty(Object). (#745)
Co-authored-by: Moderne <team@moderne.io> Co-authored-by: Spencer Gibb <spencer@gibb.us>
This commit is contained in:
committed by
GitHub
parent
24b4c1adaa
commit
c5558cc597
@@ -37,8 +37,8 @@ import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.cloud.consul.config.ConsulConfigProperties.Format.FILES;
|
||||
|
||||
@@ -150,7 +150,7 @@ public class ConfigWatch implements ApplicationEventPublisherAware, SmartLifecyc
|
||||
|
||||
// use the consul ACL token if found
|
||||
String aclToken = this.properties.getAclToken();
|
||||
if (StringUtils.isEmpty(aclToken)) {
|
||||
if (ObjectUtils.isEmpty(aclToken)) {
|
||||
aclToken = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -51,7 +51,7 @@ public class ConsulConfigBootstrapConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulConfigProperties consulConfigProperties(Environment env) {
|
||||
ConsulConfigProperties properties = new ConsulConfigProperties();
|
||||
if (StringUtils.isEmpty(properties.getName())) {
|
||||
if (ObjectUtils.isEmpty(properties.getName())) {
|
||||
properties.setName(env.getProperty("spring.application.name", "application"));
|
||||
}
|
||||
return properties;
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.cloud.consul.config.ConsulPropertySources.Context;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
@@ -214,6 +215,7 @@ public class ConsulConfigDataLocationResolver implements ConfigDataLocationResol
|
||||
.bind(ConsulConfigProperties.PREFIX, Bindable.of(ConsulConfigProperties.class), bindHandler)
|
||||
.orElseGet(ConsulConfigProperties::new);
|
||||
|
||||
|
||||
if (!StringUtils.hasText(properties.getName())) {
|
||||
properties.setName(binder.bind("spring.application.name", String.class).orElse("application"));
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -197,10 +198,10 @@ public class ConsulAutoRegistration extends ConsulRegistration {
|
||||
}
|
||||
|
||||
// add metadata from other properties. See createTags above.
|
||||
if (!StringUtils.isEmpty(properties.getInstanceZone())) {
|
||||
if (!ObjectUtils.isEmpty(properties.getInstanceZone())) {
|
||||
metadata.put(properties.getDefaultZoneMetadataName(), properties.getInstanceZone());
|
||||
}
|
||||
if (!StringUtils.isEmpty(properties.getInstanceGroup())) {
|
||||
if (!ObjectUtils.isEmpty(properties.getInstanceGroup())) {
|
||||
metadata.put("group", properties.getInstanceGroup());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationP
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -119,7 +119,7 @@ public class ConsulAutoServiceRegistration extends AbstractAutoServiceRegistrati
|
||||
@SuppressWarnings("deprecation")
|
||||
protected String getAppName() {
|
||||
String appName = this.properties.getServiceName();
|
||||
return StringUtils.isEmpty(appName) ? super.getAppName() : appName;
|
||||
return ObjectUtils.isEmpty(appName) ? super.getAppName() : appName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.cloud.consul.test.ConsulTestcontainers;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
@@ -64,7 +64,7 @@ public class ConsulAutoServiceRegistrationCustomizedAgentAddressTests {
|
||||
assertThat(service.getPort().intValue()).as("service port is 0").isNotEqualTo(0);
|
||||
assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService1-AA");
|
||||
assertThat(service.getService()).as("service name was wrong").isEqualTo("myprefix-myTestService-AA");
|
||||
assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must be empty").isTrue();
|
||||
assertThat(ObjectUtils.isEmpty(service.getAddress())).as("service address must be empty").isTrue();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.cloud.consul.test.ConsulTestcontainers;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
@@ -77,7 +77,7 @@ public class ConsulAutoServiceRegistrationCustomizedManagementServicePortTests {
|
||||
assertThat(service.getPort().intValue()).as("service port was 0").isNotEqualTo(0);
|
||||
assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService1-GG");
|
||||
assertThat(service.getService()).as("service name was wrong").isEqualTo("myprefix-myTestService-GG");
|
||||
assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse();
|
||||
assertThat(ObjectUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse();
|
||||
assertThat(service.getAddress()).as("service address must equals hostname from discovery properties")
|
||||
.isEqualTo(this.discoveryProperties.getHostname());
|
||||
|
||||
@@ -89,7 +89,7 @@ public class ConsulAutoServiceRegistrationCustomizedManagementServicePortTests {
|
||||
.isEqualTo("myTestService1-GG-management");
|
||||
assertThat(managementService.getService()).as("management service name was wrong")
|
||||
.isEqualTo("myprefix-myTestService-GG-management");
|
||||
assertThat(StringUtils.isEmpty(managementService.getAddress()))
|
||||
assertThat(ObjectUtils.isEmpty(managementService.getAddress()))
|
||||
.as("management service address must not be empty").isFalse();
|
||||
assertThat(managementService.getAddress())
|
||||
.as("management service address must equals hostname from discovery properties")
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.cloud.consul.test.ConsulTestcontainers;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
@@ -72,7 +72,7 @@ public class ConsulAutoServiceRegistrationManagementDisabledServiceTests {
|
||||
assertThat(service.getPort().intValue()).as("service port was 0").isNotEqualTo(0);
|
||||
assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService1-NM");
|
||||
assertThat(service.getService()).as("service name was wrong").isEqualTo("myTestService-NM");
|
||||
assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse();
|
||||
assertThat(ObjectUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse();
|
||||
assertThat(service.getAddress()).as("service address must equals hostname from discovery properties")
|
||||
.isEqualTo(this.discoveryProperties.getHostname());
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.cloud.consul.test.ConsulTestcontainers;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
@@ -68,7 +68,7 @@ public class ConsulAutoServiceRegistrationManagementServiceTests {
|
||||
assertThat(service.getPort().intValue()).as("service port was 0").isNotEqualTo(0);
|
||||
assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService-EE-0");
|
||||
assertThat(service.getService()).as("service name was wrong").isEqualTo("myTestService-EE");
|
||||
assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse();
|
||||
assertThat(ObjectUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse();
|
||||
assertThat(service.getAddress()).as("service address must equals hostname from discovery properties")
|
||||
.isEqualTo(this.discoveryProperties.getHostname());
|
||||
|
||||
@@ -79,7 +79,7 @@ public class ConsulAutoServiceRegistrationManagementServiceTests {
|
||||
.isEqualTo("myTestService-EE-0-management");
|
||||
assertThat(managementService.getService()).as("management service name was wrong")
|
||||
.isEqualTo("myTestService-EE-management");
|
||||
assertThat(StringUtils.isEmpty(managementService.getAddress()))
|
||||
assertThat(ObjectUtils.isEmpty(managementService.getAddress()))
|
||||
.as("management service address must not be empty").isFalse();
|
||||
assertThat(managementService.getAddress())
|
||||
.as("management service address must equals hostname from discovery properties")
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.cloud.consul.test.ConsulTestcontainers;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
@@ -70,7 +70,7 @@ public class ConsulAutoServiceRegistrationTests {
|
||||
.isFalse();
|
||||
assertThat(service.getId()).as("service id was wrong").isEqualTo(this.registration.getInstanceId());
|
||||
assertThat(service.getService()).as("service name was wrong").isEqualTo("myTestService1-FF-something");
|
||||
assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse();
|
||||
assertThat(ObjectUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse();
|
||||
assertThat(service.getAddress()).as("service address must equals hostname from discovery properties")
|
||||
.isEqualTo(this.discoveryProperties.getHostname());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user