Skip to content

Commit

Permalink
Issue #269: Do not populate collections and maps with null values. Ar…
Browse files Browse the repository at this point in the history
…rays and non-Java core collections are still populated.
  • Loading branch information
daivanov committed Jan 6, 2019
1 parent 9c34b32 commit 7076fed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
8 changes: 5 additions & 3 deletions src/main/java/uk/co/jemos/podam/api/PodamFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,10 @@ private void fillCollection(ManufacturingContext manufacturingCtx,
collectionElementType, collectionElementType,
annotations, attributeName, NULL_TYPE_ARGS_MAP, genericTypeArgs);
}
collection.add(element);

if (null != element) {
collection.add(element);
}
}
} catch (UnsupportedOperationException e) {

Expand Down Expand Up @@ -1505,8 +1508,7 @@ private void fillMap(MapArguments mapArguments, ManufacturingContext manufacturi

elementValue = getMapKeyOrElementValue(valueArguments, manufacturingCtx);

/* ConcurrentHashMap doesn't allow null values */
if (elementValue != null || !(map instanceof ConcurrentHashMap)) {
if (elementValue != null) {
map.put(keyValue, elementValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ public void podamShouldFillRecursivePojosWithLists() throws Exception {
podamValidationSteps.theCollectionShouldNotBeNullOrEmptyAndContainElementsOfType(recursivePojo.getChildren(), RecursivePojoWithList.class);
for (RecursivePojoWithList child : recursivePojo.getChildren()) {
podamValidationSteps.thePojoShouldBeNull(child.getRelated());
podamValidationSteps.theCollectionShouldNotBeNullOrEmpty(child.getChildren());
for (RecursivePojoWithList grandChild : child.getChildren()) {
podamValidationSteps.thePojoShouldBeNull(grandChild);
}
podamValidationSteps.theCollectionShouldBeEmpty(child.getChildren());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,8 @@ private void testMap(final Class<? extends Map> mapType) {
Map<?,?> pojo = podamInvocationSteps.whenIInvokeTheFactoryForGenericTypeWithSpecificType(
mapType, podamFactory, String.class, PodamTestInterface.class);

int mapSize;
if (ConcurrentMap.class.isAssignableFrom(mapType)) {
mapSize = 0;
} else {
DataProviderStrategy strategy = podamFactory.getStrategy();
mapSize = strategy.getNumberOfCollectionElements(PodamTestInterface.class);
}

podamValidationSteps.thePojoMustBeOfTheType(pojo, Map.class);
if (0 != mapSize) {
podamValidationSteps.theCollectionShouldNotBeNullOrEmptyAndShouldHaveExactlyTheExpectedNumberOfElements(pojo.keySet(), String.class, mapSize);
podamValidationSteps.theTwoObjectsShouldBeEqual(mapSize, pojo.values().size());
} else {
podamValidationSteps.theMapShouldBeEmpty(pojo);
}
podamValidationSteps.theMapShouldBeEmpty(pojo);
}


Expand Down

0 comments on commit 7076fed

Please sign in to comment.