Skip to content

Commit

Permalink
If manufacturer fails to produce an object, check other manufacturers…
Browse files Browse the repository at this point in the history
…. Proper fix for Issue #234
  • Loading branch information
daivanov committed Feb 7, 2017
1 parent 79be6f8 commit f5ef93d
Showing 1 changed file with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ public AbstractRandomDataProviderStrategy(int nbrOfCollectionElements) {
typeManufacturers.put(Type.class, typeManufacturer);

TypeManufacturer<?> collectionManufacturer = new CollectionTypeManufacturerImpl();
typeManufacturers.put(Set.class, collectionManufacturer);
typeManufacturers.put(List.class, collectionManufacturer);
typeManufacturers.put(Collection.class, collectionManufacturer);

TypeManufacturer<?> mapManufacturer = new MapTypeManufacturerImpl();
Expand Down Expand Up @@ -386,38 +384,38 @@ public <T> T getTypeValue(AttributeMetadata attributeMetadata,

Deque<Class<?>> types = new ArrayDeque<Class<?>>();
types.add(pojoType);
TypeManufacturer<?> manufacturer = null;
while (null == manufacturer && !types.isEmpty()) {
while (!types.isEmpty()) {

Class<?> type = types.remove();
manufacturer = typeManufacturers.get(type);
if (null == manufacturer) {
for (Class<?> iface : type.getInterfaces()) {
types.add(iface);
}
type = type.getSuperclass();
if (null != type) {
types.add(type);
TypeManufacturer<?> manufacturer = typeManufacturers.get(type);
if (null != manufacturer) {
try {
@SuppressWarnings("unchecked")
T tmp = (T) manufacturer.getType(this, attributeMetadata,
genericTypesArgumentsMap);
if (null != tmp) {
log(attributeMetadata);
return tmp;
} else {
LOG.debug("{} cannot manufacture {}", manufacturer, pojoType);
}
} catch (Exception e) {
throw new PodamMockeryException(
"Unable to instantiate " + pojoType, e);
}
}
}

if (null == manufacturer) {
LOG.debug("Failed to find manufacturer for type {}", pojoType);
return null;
for (Class<?> iface : type.getInterfaces()) {
types.add(iface);
}
type = type.getSuperclass();
if (null != type) {
types.add(type);
}
}

log(attributeMetadata);

try {
@SuppressWarnings("unchecked")
T tmp = (T) manufacturer.getType(this, attributeMetadata,
genericTypesArgumentsMap);
return tmp;
} catch (Exception e) {
throw new PodamMockeryException(
"Unable to instantiate " + pojoType, e);
}
LOG.debug("Failed to find suitable manufacturer for type {}", pojoType);
return null;
}

/**
Expand Down

0 comments on commit f5ef93d

Please sign in to comment.