Skip to content

Commit

Permalink
Merge pull request #11709 from geoand/assertj-deprecation
Browse files Browse the repository at this point in the history
Replace AssertJ's deprecated hasOnlyOneElementSatisfying
  • Loading branch information
gastaldi authored Aug 28, 2020
2 parents 4eef21d + 02d441d commit dc82d4f
Show file tree
Hide file tree
Showing 43 changed files with 141 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private void checkRepoArg(Index index, Class<?> baseClass, Class<?> soughtClass,
private void checkRepoArg(Index index, Class<?> baseClass, Class<?> soughtClass, String expectedArg) {
List<Type> args = JandexUtil.resolveTypeParameters(name(baseClass), name(soughtClass),
index);
assertThat(args).hasOnlyOneElementSatisfying(t -> {
assertThat(args).singleElement().satisfies(t -> {
assertThat(t.toString()).isEqualTo(expectedArg);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ void testWithMissingKeysAndIgnoreFailureConfigured() throws IOException {

Iterable<ConfigSource> configSources = sut.getConfigSources(null);
assertThat(configSources).hasSize(2);
assertThat(configSources).filteredOn(c -> c.getName().contains("first")).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).filteredOn(c -> c.getName().contains("first")).singleElement().satisfies(c -> {
assertThat(c.getOrdinal()).isEqualTo(EXPECTED_ORDINAL);
assertThat(c.getProperties()).containsOnly(entry("some.first", "whatever"));
});
assertThat(configSources).filteredOn(c -> c.getName().contains("third")).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).filteredOn(c -> c.getName().contains("third")).singleElement().satisfies(c -> {
assertThat(c.getOrdinal()).isEqualTo(EXPECTED_ORDINAL);
assertThat(c.getProperties()).containsOnly(entry("some.third", "other"));
});
Expand All @@ -108,11 +108,11 @@ void testRawKeysWithoutPrefix() throws IOException {

Iterable<ConfigSource> configSources = sut.getConfigSources(null);
assertThat(configSources).hasSize(2);
assertThat(configSources).filteredOn(c -> c.getName().contains("message")).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).filteredOn(c -> c.getName().contains("message")).singleElement().satisfies(c -> {
assertThat(c.getOrdinal()).isEqualTo(EXPECTED_ORDINAL);
assertThat(c.getProperties()).containsOnly(entry("greeting.message", "hello"));
});
assertThat(configSources).filteredOn(c -> c.getName().contains("name")).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).filteredOn(c -> c.getName().contains("name")).singleElement().satisfies(c -> {
assertThat(c.getOrdinal()).isEqualTo(EXPECTED_ORDINAL);
assertThat(c.getProperties()).containsOnly(entry("greeting.name", "quarkus"));
});
Expand All @@ -137,11 +137,11 @@ void testRawKeysWithPrefix() throws IOException {

Iterable<ConfigSource> configSources = sut.getConfigSources(null);
assertThat(configSources).hasSize(2);
assertThat(configSources).filteredOn(c -> c.getName().contains("message")).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).filteredOn(c -> c.getName().contains("message")).singleElement().satisfies(c -> {
assertThat(c.getOrdinal()).isEqualTo(EXPECTED_ORDINAL);
assertThat(c.getProperties()).containsOnly(entry("greeting.message", "hello"));
});
assertThat(configSources).filteredOn(c -> c.getName().contains("name")).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).filteredOn(c -> c.getName().contains("name")).singleElement().satisfies(c -> {
assertThat(c.getOrdinal()).isEqualTo(EXPECTED_ORDINAL);
assertThat(c.getProperties()).containsOnly(entry("greeting.name", "quarkus"));
});
Expand All @@ -165,12 +165,12 @@ void testPropertiesKeysWithoutPrefix() throws IOException {

Iterable<ConfigSource> configSources = sut.getConfigSources(null);
assertThat(configSources).hasSize(2);
assertThat(configSources).filteredOn(c -> c.getName().contains("first")).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).filteredOn(c -> c.getName().contains("first")).singleElement().satisfies(c -> {
assertThat(c.getOrdinal()).isEqualTo(EXPECTED_ORDINAL);
assertThat(c.getProperties()).containsOnly(entry("greeting.message", "hi"),
entry("greeting.name", "quarkus"));
});
assertThat(configSources).filteredOn(c -> c.getName().contains("second")).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).filteredOn(c -> c.getName().contains("second")).singleElement().satisfies(c -> {
assertThat(c.getOrdinal()).isEqualTo(EXPECTED_ORDINAL);
assertThat(c.getProperties()).containsOnly(entry("other.key", "value"));
});
Expand All @@ -195,12 +195,12 @@ void testPropertiesKeysWithPrefix() throws IOException {

Iterable<ConfigSource> configSources = sut.getConfigSources(null);
assertThat(configSources).hasSize(2);
assertThat(configSources).filteredOn(c -> c.getName().contains("first")).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).filteredOn(c -> c.getName().contains("first")).singleElement().satisfies(c -> {
assertThat(c.getOrdinal()).isEqualTo(EXPECTED_ORDINAL);
assertThat(c.getProperties()).containsOnly(entry("greeting.message", "hi"),
entry("greeting.name", "quarkus"));
});
assertThat(configSources).filteredOn(c -> c.getName().contains("second")).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).filteredOn(c -> c.getName().contains("second")).singleElement().satisfies(c -> {
assertThat(c.getOrdinal()).isEqualTo(EXPECTED_ORDINAL);
assertThat(c.getProperties()).containsOnly(entry("other.key", "value"));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void testOnlyLiteralData() {

List<ConfigSource> configSources = sut.toConfigSources(configMap.getMetadata().getName(), configMap.getData());

assertThat(configSources).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("some.key", "someValue"),
entry("some.other", "someOtherValue"));
assertThat(c.getName()).contains("testOnlyLiteralData");
Expand All @@ -45,7 +45,7 @@ void testOnlySingleMatchingPropertiesData() {

List<ConfigSource> configSources = sut.toConfigSources(configMap.getMetadata().getName(), configMap.getData());

assertThat(configSources).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("key1", "value1"), entry("key2", "value2"),
entry("some.key", "someValue"));
assertThat(c.getName()).contains("testOnlySingleMatchingPropertiesData");
Expand All @@ -69,7 +69,7 @@ void testOnlySingleMatchingYamlData() {

List<ConfigSource> configSources = sut.toConfigSources(configMap.getMetadata().getName(), configMap.getData());

assertThat(configSources).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("key1", "value1"), entry("key2", "value2"),
entry("some.key", "someValue"));
assertThat(c.getName()).contains("testOnlySingleMatchingYamlData");
Expand Down Expand Up @@ -102,20 +102,20 @@ void testWithAllKindsOfData() {

assertThat(configSources).hasSize(4);
assertThat(configSources).filteredOn(c -> c.getName().toLowerCase().contains("literal"))
.hasOnlyOneElementSatisfying(c -> {
.singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("some.key", "someValue"));
});
assertThat(configSources).filteredOn(c -> c.getName().toLowerCase().contains("application.properties"))
.hasOnlyOneElementSatisfying(c -> {
.singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("key1", "value1"), entry("app.key", "val"));
});
assertThat(configSources).filteredOn(c -> c.getName().toLowerCase().contains("application.yaml"))
.hasOnlyOneElementSatisfying(c -> {
.singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("key2", "value2"),
entry("some.otherKey", "someOtherValue"));
});
assertThat(configSources).filteredOn(c -> c.getName().toLowerCase().contains("application.yml"))
.hasOnlyOneElementSatisfying(c -> {
.singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("key3", "value3"));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void testOnlyLiteralData() {

List<ConfigSource> configSources = sut.toConfigSources(configMap.getMetadata().getName(), configMap.getData());

assertThat(configSources).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("some.key", "someValue"),
entry("some.other", "someOtherValue"));
assertThat(c.getName()).contains("testOnlyLiteralData");
Expand All @@ -46,7 +46,7 @@ void testOnlySingleMatchingPropertiesData() {

List<ConfigSource> configSources = sut.toConfigSources(secret.getMetadata().getName(), secret.getData());

assertThat(configSources).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("key1", "value1"), entry("key2", "value2"),
entry("some.key", "someValue"));
assertThat(c.getName()).contains("testOnlySingleMatchingPropertiesData");
Expand All @@ -70,7 +70,7 @@ void testOnlySingleMatchingYamlData() {

List<ConfigSource> configSources = sut.toConfigSources(configMap.getMetadata().getName(), configMap.getData());

assertThat(configSources).hasOnlyOneElementSatisfying(c -> {
assertThat(configSources).singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("key1", "value1"), entry("key2", "value2"),
entry("some.key", "someValue"));
assertThat(c.getName()).contains("testOnlySingleMatchingYamlData");
Expand Down Expand Up @@ -103,20 +103,20 @@ void testWithAllKindsOfData() {

assertThat(configSources).hasSize(4);
assertThat(configSources).filteredOn(c -> c.getName().toLowerCase().contains("literal"))
.hasOnlyOneElementSatisfying(c -> {
.singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("some.key", "someValue"));
});
assertThat(configSources).filteredOn(c -> c.getName().toLowerCase().contains("application.properties"))
.hasOnlyOneElementSatisfying(c -> {
.singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("key1", "value1"), entry("app.key", "val"));
});
assertThat(configSources).filteredOn(c -> c.getName().toLowerCase().contains("application.yaml"))
.hasOnlyOneElementSatisfying(c -> {
.singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("key2", "value2"),
entry("some.otherKey", "someOtherValue"));
});
assertThat(configSources).filteredOn(c -> c.getName().toLowerCase().contains("application.yml"))
.hasOnlyOneElementSatisfying(c -> {
.singleElement().satisfies(c -> {
assertThat(c.getProperties()).containsOnly(entry("key3", "value3"));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testNamedDataSourceInjection() {

private void assertProperConnection(MongoClient client, int expectedPort) {
assertThat(client).isInstanceOfSatisfying(MongoClientImpl.class, c -> {
assertThat(c.getCluster().getSettings().getHosts()).hasOnlyOneElementSatisfying(sa -> {
assertThat(c.getCluster().getSettings().getHosts()).singleElement().satisfies(sa -> {
assertThat(sa.getPort()).isEqualTo(expectedPort);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void assertProperConnection(ReactiveMongoClient client, int expectedPort
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
assertThat(c.getClusterDescription().getClusterSettings().getHosts()).hasOnlyOneElementSatisfying(sa -> {
assertThat(c.getClusterDescription().getClusterSettings().getHosts()).singleElement().satisfies(sa -> {
assertThat(sa.getPort()).isEqualTo(expectedPort);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void assertProperConnection(ReactiveMongoClient client, int expectedPort
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
assertThat(c.getClusterDescription().getClusterSettings().getHosts()).hasOnlyOneElementSatisfying(sa -> {
assertThat(c.getClusterDescription().getClusterSettings().getHosts()).singleElement().satisfies(sa -> {
assertThat(sa.getPort()).isEqualTo(expectedPort);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MissingRestControllerTest {
public void testBuildLogs() {
List<LogRecord> buildLogRecords = prodModeTestResults.getRetainedBuildLogRecords();
assertThat(buildLogRecords).isNotEmpty();
assertThat(buildLogRecords).hasOnlyOneElementSatisfying(r -> {
assertThat(buildLogRecords).singleElement().satisfies(r -> {
assertThat(r.getMessage())
.contains("a mapping annotation but the class itself")
.contains(NonAnnotatedController.class.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void assertGeneratedResources() throws IOException {
assertThat(d.getSpec()).satisfies(deploymentSpec -> {
assertThat(deploymentSpec.getTemplate()).satisfies(t -> {
assertThat(t.getSpec()).satisfies(podSpec -> {
assertThat(podSpec.getContainers()).hasOnlyOneElementSatisfying(container -> {
assertThat(podSpec.getContainers()).singleElement().satisfies(container -> {
assertThat(container.getImagePullPolicy()).isEqualTo("Always"); // expect the default value
assertThat(container.getPorts()).hasOnlyOneElementSatisfying(p -> {
assertThat(container.getPorts()).singleElement().satisfies(p -> {
assertThat(p.getContainerPort()).isEqualTo(8080);
});
});
Expand All @@ -87,7 +87,7 @@ public void assertGeneratedResources() throws IOException {
assertThat(m.getNamespace()).isNull();
});
assertThat(s.getSpec()).satisfies(spec -> {
assertThat(spec.getPorts()).hasSize(1).hasOnlyOneElementSatisfying(p -> {
assertThat(spec.getPorts()).hasSize(1).singleElement().satisfies(p -> {
assertThat(p.getPort()).isEqualTo(8080);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void assertGeneratedResources() throws IOException {
List<HasMetadata> openshiftList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("openshift.yml"));

assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).hasOnlyOneElementSatisfying(h -> {
assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> {
assertThat(h.getMetadata()).satisfies(m -> {
assertThat(m.getName()).isEqualTo("basic-openshift");
assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus");
Expand All @@ -54,7 +54,7 @@ public void assertGeneratedResources() throws IOException {
});
});

assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).hasOnlyOneElementSatisfying(h -> {
assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).singleElement().satisfies(h -> {
assertThat(h).isInstanceOfSatisfying(Service.class, s -> {
assertThat(s.getMetadata()).satisfies(m -> {
assertThat(m.getNamespace()).isNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void assertGeneratedResources() throws IOException {
List<HasMetadata> kubernetesList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("knative.yml"));

assertThat(kubernetesList).filteredOn(i -> "ConfigMap".equals(i.getKind())).hasOnlyOneElementSatisfying(c -> {
assertThat(kubernetesList).filteredOn(i -> "ConfigMap".equals(i.getKind())).singleElement().satisfies(c -> {
assertThat(c.getMetadata()).satisfies(m -> assertThat(m.getName()).isEqualTo("config-autoscaler"));
assertThat(c).isInstanceOfSatisfying(ConfigMap.class, m -> {
assertThat(m.getData()).contains(entry("container-concurrency", "100"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void assertGeneratedResources() throws IOException {
List<HasMetadata> kubernetesList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("knative.yml"));

assertThat(kubernetesList).filteredOn(i -> "ConfigMap".equals(i.getKind())).hasOnlyOneElementSatisfying(c -> {
assertThat(kubernetesList).filteredOn(i -> "ConfigMap".equals(i.getKind())).singleElement().satisfies(c -> {
assertThat(c.getMetadata()).satisfies(m -> assertThat(m.getName()).isEqualTo("config-autoscaler"));
assertThat(c).isInstanceOfSatisfying(ConfigMap.class, m -> {
assertThat(m.getData()).contains(entry("requests-per-second-target-default", "150"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void assertGeneratedResources() throws IOException {
List<HasMetadata> kubernetesList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("knative.yml"));

assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> {
assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).singleElement().satisfies(i -> {
assertThat(i).isInstanceOfSatisfying(Service.class, s -> {
assertThat(s.getMetadata().getAnnotations()).contains(entry("autoscaling.knative.dev/minScale", "3"));
assertThat(s.getMetadata().getAnnotations()).contains(entry("autoscaling.knative.dev/maxScale", "5"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void assertGeneratedResources() throws IOException {
List<HasMetadata> kubernetesList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("knative.yml"));

assertThat(kubernetesList).filteredOn(i -> "ConfigMap".equals(i.getKind())).hasOnlyOneElementSatisfying(c -> {
assertThat(kubernetesList).filteredOn(i -> "ConfigMap".equals(i.getKind())).singleElement().satisfies(c -> {
assertThat(c.getMetadata()).satisfies(m -> assertThat(m.getName()).isEqualTo("config-autoscaler"));
assertThat(c).isInstanceOfSatisfying(ConfigMap.class, m -> {
assertThat(m.getData()).contains(entry("enable-scale-to-zero", "false"));
Expand Down
Loading

0 comments on commit dc82d4f

Please sign in to comment.