Skip to content

Commit fcdbd5f

Browse files
committed
Code-cleanup: Removed unnecessary this, re-used getScheme()
1 parent 0bcc303 commit fcdbd5f

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,7 +82,7 @@ public DefaultServiceInstance() {
8282
* @return URI of the form (secure)?https:http + "host:port".
8383
*/
8484
public static URI getUri(ServiceInstance instance) {
85-
String scheme = (instance.isSecure()) ? "https" : "http";
85+
String scheme = instance.getScheme();
8686
String uri = String.format("%s://%s:%s", scheme, instance.getHost(), instance.getPort());
8787
return URI.create(uri);
8888
}
@@ -175,7 +175,7 @@ public int hashCode() {
175175

176176
@Override
177177
public String getScheme() {
178-
return this.isSecure() ? "https" : "http";
178+
return isSecure() ? "https" : "http";
179179
}
180180

181181
}

spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryClientPropertiesMappingTests.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,18 +27,16 @@
2727
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2828
import org.springframework.boot.test.context.SpringBootTest;
2929
import org.springframework.cloud.client.ServiceInstance;
30-
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClient;
3130
import org.springframework.context.annotation.Configuration;
3231
import org.springframework.test.context.junit4.SpringRunner;
3332

3433
import static org.assertj.core.api.BDDAssertions.then;
3534

3635
/**
37-
* Tests for mapping properties to instances in {@link SimpleDiscoveryClient}
36+
* Tests for mapping properties to instances in {@link SimpleReactiveDiscoveryClient}
3837
*
3938
* @author Daniel Gerber
4039
*/
41-
4240
@RunWith(SpringRunner.class)
4341
@SpringBootTest(properties = { "spring.application.name=service0",
4442
"spring.cloud.discovery.client.simple.instances.service1[0].uri=http://s11:8080",
@@ -55,25 +53,25 @@ public class SimpleReactiveDiscoveryClientPropertiesMappingTests {
5553

5654
@Test
5755
public void propsShouldGetCleanlyMapped() {
58-
then(this.props.getInstances().size()).isEqualTo(2);
59-
then(this.props.getInstances().get("service1").size()).isEqualTo(2);
60-
then(this.props.getInstances().get("service1").get(0).getHost()).isEqualTo("s11");
61-
then(this.props.getInstances().get("service1").get(0).getPort()).isEqualTo(8080);
62-
then(this.props.getInstances().get("service1").get(0).getUri()).isEqualTo(URI.create("http://s11:8080"));
63-
then(this.props.getInstances().get("service1").get(0).isSecure()).isEqualTo(false);
64-
65-
then(this.props.getInstances().get("service2").size()).isEqualTo(2);
66-
then(this.props.getInstances().get("service2").get(0).getHost()).isEqualTo("s21");
67-
then(this.props.getInstances().get("service2").get(0).getPort()).isEqualTo(8080);
68-
then(this.props.getInstances().get("service2").get(0).getUri()).isEqualTo(URI.create("https://s21:8080"));
69-
then(this.props.getInstances().get("service2").get(0).isSecure()).isEqualTo(true);
56+
then(props.getInstances().size()).isEqualTo(2);
57+
then(props.getInstances().get("service1").size()).isEqualTo(2);
58+
then(props.getInstances().get("service1").get(0).getHost()).isEqualTo("s11");
59+
then(props.getInstances().get("service1").get(0).getPort()).isEqualTo(8080);
60+
then(props.getInstances().get("service1").get(0).getUri()).isEqualTo(URI.create("http://s11:8080"));
61+
then(props.getInstances().get("service1").get(0).isSecure()).isEqualTo(false);
62+
63+
then(props.getInstances().get("service2").size()).isEqualTo(2);
64+
then(props.getInstances().get("service2").get(0).getHost()).isEqualTo("s21");
65+
then(props.getInstances().get("service2").get(0).getPort()).isEqualTo(8080);
66+
then(props.getInstances().get("service2").get(0).getUri()).isEqualTo(URI.create("https://s21:8080"));
67+
then(props.getInstances().get("service2").get(0).isSecure()).isEqualTo(true);
7068
}
7169

7270
@Test
7371
public void testDiscoveryClientShouldResolveSimpleValues() {
74-
then(this.discoveryClient.description()).isEqualTo("Simple Reactive Discovery Client");
72+
then(discoveryClient.description()).isEqualTo("Simple Reactive Discovery Client");
7573

76-
Flux<ServiceInstance> services = this.discoveryClient.getInstances("service1");
74+
Flux<ServiceInstance> services = discoveryClient.getInstances("service1");
7775
StepVerifier.create(services)
7876
.expectNextMatches(inst -> inst.getHost().equals("s11") && inst.getPort() == 8080
7977
&& inst.getUri().toString().equals("http://s11:8080") && !inst.isSecure()
@@ -86,9 +84,9 @@ public void testDiscoveryClientShouldResolveSimpleValues() {
8684

8785
@Test
8886
public void testGetANonExistentServiceShouldReturnAnEmptyList() {
89-
then(this.discoveryClient.description()).isEqualTo("Simple Reactive Discovery Client");
87+
then(discoveryClient.description()).isEqualTo("Simple Reactive Discovery Client");
9088

91-
Flux<ServiceInstance> services = this.discoveryClient.getInstances("nonexistent");
89+
Flux<ServiceInstance> services = discoveryClient.getInstances("nonexistent");
9290

9391
StepVerifier.create(services).expectNextCount(0).expectComplete().verify();
9492
}

0 commit comments

Comments
 (0)