Skip to content

Commit

Permalink
#1563 - Deprecate PayloadMetadata.getPropertyMetadata(…).
Browse files Browse the repository at this point in the history
This method is currently used in test cases only and the just introduced ability to rename property makes the method not reliably usable as the way it is named doesn't convey which name is to be used. It currently is the potentially renamed value. Moving to the actual property name as input creates stronger boundaries to assume a type backing the metadata, which we want to avoid.
  • Loading branch information
odrotbohm committed Jun 29, 2021
1 parent 8347554 commit c6a6d37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ public interface PayloadMetadata {
*/
Stream<PropertyMetadata> stream();

/**
* @deprecated since 1.4, for removal in 1.5. Prefer {@link #stream()} and selecting individual
* {@code PropertyMetadata} instances yourself.
*/
@Deprecated
default Optional<PropertyMetadata> getPropertyMetadata(String name) {
return stream().filter(it -> it.hasName(name)).findFirst();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ void considersAccessorAvailablility() {

PayloadMetadata metadata = PropertyUtils.getExposedProperties(MethodExposurePayload.class);

assertThat(metadata.getPropertyMetadata("readWrite")) //
assertThat(getProperty(metadata, "readWrite")) //
.map(PropertyMetadata::isReadOnly) //
.hasValue(false);

assertThat(metadata.getPropertyMetadata("readOnly")) //
assertThat(getProperty(metadata, "readOnly")) //
.map(PropertyMetadata::isReadOnly) //
.hasValue(true);
}
Expand All @@ -154,15 +154,15 @@ void considersJsr303Annotations() {

InputPayloadMetadata metadata = PropertyUtils.getExposedProperties(Jsr303SamplePayload.class);

assertThat(metadata.getPropertyMetadata("nonNull")).hasValueSatisfying(it -> {
assertThat(getProperty(metadata, "nonNull")).hasValueSatisfying(it -> {
assertThat(it.isRequired()).isTrue();
});

assertThat(metadata.getPropertyMetadata("pattern")).hasValueSatisfying(it -> {
assertThat(getProperty(metadata, "pattern")).hasValueSatisfying(it -> {
assertThat(it.getPattern()).hasValue("\\w");
});

assertThat(metadata.getPropertyMetadata("annotated")).hasValueSatisfying(it -> {
assertThat(getProperty(metadata, "annotated")).hasValueSatisfying(it -> {
assertThat(it.getPattern()).hasValue("regex");
});
}
Expand All @@ -172,7 +172,7 @@ void considersPropertyWithoutReader() throws Exception {

InputPayloadMetadata metadata = PropertyUtils.getExposedProperties(WithoutReaderMethod.class);

assertThat(metadata.getPropertyMetadata("firstname")).isPresent();
assertThat(getProperty(metadata, "firstname")).isPresent();
}

@TestFactory
Expand Down Expand Up @@ -252,8 +252,7 @@ static class TypeAnnotated {}

static class MethodExposurePayload {

@Getter
@Setter String readWrite;
@Getter @Setter String readWrite;
@Getter String readOnly;
}

Expand Down Expand Up @@ -308,7 +307,7 @@ static class InputTypes {

public void verify(InputPayloadMetadata metadata) {

assertThat(metadata.getPropertyMetadata(property))
assertThat(PropertyUtilsTest.getProperty(metadata, property))
.map(PropertyMetadata::getInputType)
.hasValue(type.toString());
}
Expand Down

0 comments on commit c6a6d37

Please sign in to comment.