Skip to content

Commit

Permalink
HV-2029 Allow same group convert rules on the methods in class hierar…
Browse files Browse the repository at this point in the history
…chies
  • Loading branch information
marko-bekhta committed Sep 3, 2024
1 parent 3aa8de7 commit 97f8505
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,12 @@ private static Map<Class<?>, Class<?>> mergeGroupConversion(Map<Class<?>, Class<
Map<Class<?>, Class<?>> mergedGroupConversions = new HashMap<>( groupConversions.size() + otherGroupConversions.size() );

for ( Entry<Class<?>, Class<?>> otherGroupConversionEntry : otherGroupConversions.entrySet() ) {
if ( groupConversions.containsKey( otherGroupConversionEntry.getKey() ) ) {
Class<?> convertTo = groupConversions.get( otherGroupConversionEntry.getKey() );
if ( convertTo != null && !convertTo.equals( otherGroupConversionEntry.getValue() ) ) {
throw LOG.getMultipleGroupConversionsForSameSourceException(
otherGroupConversionEntry.getKey(),
CollectionHelper.<Class<?>>asSet(
groupConversions.get( otherGroupConversionEntry.getKey() ),
convertTo,
otherGroupConversionEntry.getValue() ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,28 @@ public void groupConversionOnParameter() throws Exception {
);
}

@Test
public void groupConversionOnParameterInHierarchy() throws Exception {
Set<ConstraintViolation<User6>> violations = getValidator().forExecutables().validateParameters(
new User6Extended(),
User6Extended.class.getMethod( "setAddresses", List.class ),
new List<?>[] { Arrays.asList( new Address() ) }
);

assertThat( violations ).containsOnlyViolations(
violationOf( NotNull.class ).withPropertyPath( pathWith()
.method( "setAddresses" )
.parameter( "addresses", 0 )
.property( "street1", true, null, 0, List.class, 0 )
),
violationOf( Size.class ).withPropertyPath( pathWith()
.method( "setAddresses" )
.parameter( "addresses", 0 )
.property( "zipCode", true, null, 0, List.class, 0 )
)
);
}

@Test
public void groupConversionOnReturnValue() throws Exception {
Set<ConstraintViolation<User7>> violations = getValidator().forExecutables().validateReturnValue(
Expand Down Expand Up @@ -333,7 +355,19 @@ public PhoneNumber getPhoneNumber() {

private static class User6 {

public void setAddresses(@Valid @ConvertGroup(from = Default.class, to = BasicPostal.class) List<Address> addresses) {
public void setAddresses(
@Valid @ConvertGroup(from = Default.class, to = BasicPostal.class) List<Address> addresses
) {
}
}

private static class User6Extended extends User6 {

@Override
public void setAddresses(
@Valid @ConvertGroup(from = Default.class, to = BasicPostal.class) List<Address> addresses
) {
// do nothing as well
}
}

Expand Down

0 comments on commit 97f8505

Please sign in to comment.