Skip to content

Commit 6149156

Browse files
committed
Fix type/name ordering in FeaturesEndpoint
fixes spring-projectsgh-258
1 parent a7caee5 commit 6149156

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private void addFeature(Features features, NamedFeature feature) {
9090
type.getPackage().getImplementationVendor()));
9191
}
9292

93-
class Features {
93+
static class Features {
9494
final List<Feature> enabled = new ArrayList<>();
9595
final List<String> disabled = new ArrayList<>();
9696

@@ -104,13 +104,13 @@ public List<String> getDisabled() {
104104
}
105105

106106

107-
class Feature {
107+
static class Feature {
108108
final String type;
109109
final String name;
110110
final String version;
111111
final String vendor;
112112

113-
public Feature(String type, String name, String version, String vendor) {
113+
public Feature(String name, String type, String version, String vendor) {
114114
this.type = type;
115115
this.name = name;
116116
this.version = version;
@@ -132,5 +132,37 @@ public String getVersion() {
132132
public String getVendor() {
133133
return vendor;
134134
}
135+
136+
@Override
137+
public String toString() {
138+
return "Feature{" +
139+
"type='" + type + '\'' +
140+
", name='" + name + '\'' +
141+
", version='" + version + '\'' +
142+
", vendor='" + vendor + '\'' +
143+
'}';
144+
}
145+
146+
@Override
147+
public boolean equals(Object o) {
148+
if (this == o) return true;
149+
if (o == null || getClass() != o.getClass()) return false;
150+
151+
Feature feature = (Feature) o;
152+
153+
if (type != null ? !type.equals(feature.type) : feature.type != null) return false;
154+
if (name != null ? !name.equals(feature.name) : feature.name != null) return false;
155+
if (version != null ? !version.equals(feature.version) : feature.version != null) return false;
156+
return vendor != null ? vendor.equals(feature.vendor) : feature.vendor == null;
157+
}
158+
159+
@Override
160+
public int hashCode() {
161+
int result = type != null ? type.hashCode() : 0;
162+
result = 31 * result + (name != null ? name.hashCode() : 0);
163+
result = 31 * result + (version != null ? version.hashCode() : 0);
164+
result = 31 * result + (vendor != null ? vendor.hashCode() : 0);
165+
return result;
166+
}
135167
}
136168
}

spring-cloud-commons/src/test/java/org/springframework/cloud/client/actuator/FeaturesEndpointTests.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
import org.springframework.context.annotation.Bean;
1414
import org.springframework.context.annotation.Configuration;
1515

16-
import static org.hamcrest.Matchers.equalTo;
17-
import static org.hamcrest.Matchers.is;
18-
import static org.hamcrest.Matchers.notNullValue;
19-
import static org.junit.Assert.assertThat;
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
2018

2119
/**
2220
* @author Spencer Gibb
@@ -44,9 +42,14 @@ public void close() {
4442
public void invokeWorks() {
4543
FeaturesEndpoint.Features features = this.context.getBean(FeaturesEndpoint.class)
4644
.invoke();
47-
assertThat(features, is(notNullValue()));
48-
assertThat(features.getEnabled().size(), is(equalTo(2)));
49-
assertThat(features.getDisabled().size(), is(equalTo(1)));
45+
assertThat(features).isNotNull();
46+
assertThat(features.getEnabled()).hasSize(2)
47+
.contains(newFeature("foo", Foo.class), newFeature("Baz Feature", Baz.class));
48+
assertThat(features.getDisabled()).hasSize(1).contains("Bar");
49+
}
50+
51+
private FeaturesEndpoint.Feature newFeature(String name, Class<?> type) {
52+
return new FeaturesEndpoint.Feature(name, type.getCanonicalName(), null, null);
5053
}
5154

5255
@Configuration
@@ -60,7 +63,7 @@ Foo foo() {
6063
HasFeatures localFeatures() {
6164
HasFeatures features = HasFeatures.namedFeatures(
6265
new NamedFeature("foo", Foo.class),
63-
new NamedFeature("Bar Feature", Bar.class));
66+
new NamedFeature("Baz Feature", Baz.class));
6467
features.getAbstractFeatures().add(Bar.class);
6568
return features;
6669
}

0 commit comments

Comments
 (0)