Skip to content

Commit b6221dc

Browse files
authored
Merge pull request #3975 from cloudfoundry/remove-hamcrest
Migrate tests off Hamcrest to AssertJ and remove the dependency
2 parents 510fd0b + 641a085 commit b6221dc

81 files changed

Lines changed: 1978 additions & 2270 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gradle/libs.versions.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ guava = { module = "com.google.guava:guava", version.ref = "guava" }
8686
# Greenmail
8787
greenmail = { module = "com.icegreen:greenmail", version.ref = "greenmail" }
8888

89-
# Hamcrest
90-
hamcrest = { module = "org.hamcrest:hamcrest" }
91-
9289
# Hibernate
9390
hibernateValidator = { module = "org.hibernate.validator:hibernate-validator" }
9491

metrics-data/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ dependencies {
1414
testImplementation(libs.springBootStarterTest) {
1515
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
1616
}
17-
testImplementation(libs.hamcrest)
1817
testImplementation(libs.junit5JupiterApi)
1918
testImplementation(libs.junit5JupiterParams)
2019
testImplementation(libs.junit5JupiterEngine)

model/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ dependencies {
2929
testImplementation(libs.springBootStarterTest) {
3030
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
3131
}
32-
testImplementation(libs.hamcrest)
3332
testImplementation(libs.junit5JupiterApi)
3433
testImplementation(libs.junit5JupiterParams)
3534
testImplementation(libs.junit5JupiterEngine)

model/src/test/java/org/cloudfoundry/identity/uaa/ProxyingBeanInfoMatcher.java

Lines changed: 0 additions & 99 deletions
This file was deleted.

model/src/test/java/org/cloudfoundry/identity/uaa/client/UaaClientDetailsMatcher.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

model/src/test/java/org/cloudfoundry/identity/uaa/client/UaaClientDetailsTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import tools.jackson.databind.ObjectMapper;
44
import tools.jackson.databind.json.JsonMapper;
55

6-
import org.hamcrest.Matchers;
76
import org.junit.jupiter.api.BeforeEach;
87
import org.junit.jupiter.api.Nested;
98
import org.junit.jupiter.api.Test;
@@ -18,7 +17,6 @@
1817
import java.util.TreeSet;
1918

2019
import static org.assertj.core.api.Assertions.assertThat;
21-
import static org.assertj.core.api.HamcrestCondition.matching;
2220

2321
class UaaClientDetailsTest {
2422

@@ -41,11 +39,10 @@ void setUp() {
4139
void copiesUaaBaseClientDetails() {
4240
testClient.setClientSecret("secret");
4341
UaaClientDetails copy = new UaaClientDetails(testClient);
44-
assertThat(copy).is(matching(UaaClientDetailsMatcher.aUaaClientDetails()
45-
.withClientId("test")
46-
.withClientSecret("secret")
47-
.withScope(Matchers.contains("test.none"))
48-
.withResourceIds(Matchers.emptyIterable())));
42+
assertThat(copy.getClientId()).isEqualTo("test");
43+
assertThat(copy.getClientSecret()).isEqualTo("secret");
44+
assertThat(copy.getScope()).containsExactly("test.none");
45+
assertThat(copy.getResourceIds()).isEmpty();
4946

5047
List<String> authorities = copy.getAuthorities().stream()
5148
.map(GrantedAuthority::getAuthority)
@@ -57,8 +54,9 @@ void copiesUaaBaseClientDetails() {
5754
void copiesAdditionalInformation() {
5855
testClient.setAdditionalInformation(Collections.singletonMap("key", "value"));
5956
UaaClientDetails copy = new UaaClientDetails(testClient);
60-
assertThat(copy).is(matching(UaaClientDetailsMatcher.aUaaClientDetails()
61-
.withAdditionalInformation(Matchers.allOf(Matchers.aMapWithSize(1), Matchers.hasEntry("key", "value")))));
57+
assertThat(copy.getAdditionalInformation())
58+
.hasSize(1)
59+
.containsEntry("key", "value");
6260
}
6361

6462
@Test
@@ -98,7 +96,7 @@ class WhenSettingScope {
9896
void splitsScopesWhichIncludeAComma() {
9997
UaaClientDetails client = new UaaClientDetails(new UaaClientDetails());
10098
client.setScope(Collections.singleton("foo,bar"));
101-
assertThat(client).is(matching(UaaClientDetailsMatcher.aUaaClientDetails().withScope(Matchers.containsInAnyOrder("foo", "bar"))));
99+
assertThat(client.getScope()).containsExactlyInAnyOrder("foo", "bar");
102100
}
103101
}
104102

model/src/test/java/org/cloudfoundry/identity/uaa/test/JsonMatcher.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

model/src/test/java/org/cloudfoundry/identity/uaa/test/JsonTranslation.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
import org.junit.jupiter.api.Test;
77

88
import static org.assertj.core.api.Assertions.assertThat;
9-
import static org.assertj.core.api.HamcrestCondition.matching;
10-
import static org.cloudfoundry.identity.uaa.test.JsonMatcher.isJsonFile;
11-
import static org.cloudfoundry.identity.uaa.test.JsonMatcher.isJsonString;
129
import static org.cloudfoundry.identity.uaa.test.JsonTranslation.WithAllNullFields.EXPECT_EMPTY_JSON;
1310
import static org.cloudfoundry.identity.uaa.test.JsonTranslation.WithAllNullFields.EXPECT_NULLS_IN_JSON;
1411
import static org.cloudfoundry.identity.uaa.test.ModelTestUtils.getResourceAsString;
@@ -65,7 +62,7 @@ void toJson() throws Exception {
6562

6663
String actual = objectMapper.writeValueAsString(subject);
6764

68-
assertThat(actual).is(matching(isJsonFile(subjectClass, jsonFileName)));
65+
assertJsonEquals(actual, getResourceAsString(subjectClass, jsonFileName));
6966
}
7067

7168
@Test
@@ -87,7 +84,7 @@ void withNullFields_checkIsEmptyJson() throws Exception {
8784
validate();
8885

8986
String actual = objectMapper.writeValueAsString(subjectClass.newInstance());
90-
assertThat(actual).is(matching(isJsonString("{}")));
87+
assertJsonEquals(actual, "{}");
9188
}
9289

9390
@Test
@@ -101,6 +98,12 @@ void withNullFields_compareToFile() throws Exception {
10198
assertThat(subjectClass.getResourceAsStream(fileName)).as("file <%s/%s> must exist on classpath, or choose a different %s".formatted(subjectClass.getPackage().getName().replace(".", "/"), fileName, WithAllNullFields.class.getSimpleName())).isNotNull();
10299

103100
String actual = objectMapper.writeValueAsString(subjectClass.newInstance());
104-
assertThat(actual).is(matching(isJsonFile(this.getClass(), fileName)));
101+
assertJsonEquals(actual, getResourceAsString(this.getClass(), fileName));
102+
}
103+
104+
/** Compares two JSON documents structurally (field order and formatting insensitive). */
105+
private void assertJsonEquals(String actualJson, String expectedJson) {
106+
assertThat(objectMapper.readTree(actualJson))
107+
.isEqualTo(objectMapper.readTree(expectedJson));
105108
}
106109
}

server/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ dependencies {
9292
testImplementation(libs.springBootStarterTest) {
9393
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
9494
}
95-
testImplementation(libs.hamcrest)
9695
testImplementation(libs.junit5JupiterApi)
9796
testImplementation(libs.junit5JupiterParams)
9897
testImplementation(libs.junit5JupiterEngine)

0 commit comments

Comments
 (0)