Skip to content

Commit

Permalink
Fixes Issue #303: do not loose resolved attribute generic parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
daivanov committed Apr 10, 2022
1 parent efd78aa commit 7a618b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/main/java/uk/co/jemos/podam/api/PodamFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -911,19 +911,24 @@ private Object manufactureAttributeValue(Object pojo,

Class<?> pojoClass = (pojo instanceof Class ? (Class<?>) pojo : pojo.getClass());
Class<?> realAttributeType;
AtomicReference<Type[]> elementGenericTypeArgs = new AtomicReference<Type[]>(PodamConstants.NO_TYPES);
if (attributeType != genericAttributeType
&& Object.class.equals(attributeType)
&& genericAttributeType instanceof TypeVariable) {
AtomicReference<Type[]> elementGenericTypeArgs
= new AtomicReference<Type[]>(PodamConstants.NO_TYPES);
realAttributeType = TypeManufacturerUtil.resolveGenericParameter(genericAttributeType,
typeArgsMap, elementGenericTypeArgs);
} else {
realAttributeType = attributeType;
}

Type[] genericTypeArgsAll = TypeManufacturerUtil.mergeActualAndSuppliedGenericTypes(
attributeType, genericAttributeType, genericTypeArgs, typeArgsMap);
Type[] genericTypeArgsAll;
if (elementGenericTypeArgs.get().length > 0) {
genericTypeArgsAll = ArrayUtils.addAll(elementGenericTypeArgs.get(), genericTypeArgs);
} else {
genericTypeArgsAll = genericTypeArgs;
}
genericTypeArgsAll = TypeManufacturerUtil.mergeActualAndSuppliedGenericTypes(
attributeType, genericAttributeType, genericTypeArgsAll, typeArgsMap);

AttributeMetadata attributeMetadata = new AttributeMetadata(
attributeName, realAttributeType, genericAttributeType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void podamShouldHandleOptionalListOfStrings() throws Exception {
OptionalList pojo = podamInvocationSteps.whenIInvokeTheFactoryForClassWithFullConstructor(OptionalList.class, podamFactory);
podamValidationSteps.thePojoMustBeOfTheType(pojo, OptionalList.class);
podamValidationSteps.thePojoMustBeOfTheType(pojo.getOptionalList(), Optional.class);
podamValidationSteps.theCollectionShouldNotBeNullOrEmptyAndContainElementsOfType(pojo.getOptionalList().get(), Object.class);
podamValidationSteps.theCollectionShouldNotBeNullOrEmptyAndContainElementsOfType(pojo.getOptionalList().get(), String.class);
}

//------------------> Private methods
Expand Down

0 comments on commit 7a618b1

Please sign in to comment.