com.hltech.pact.gen.domain.pact.EnumStringManufacturer   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getType(DataProviderStrategy,AttributeMetadata,Map) 0 12 1
1
package com.hltech.pact.gen.domain.pact;
2
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import uk.co.jemos.podam.api.AttributeMetadata;
5
import uk.co.jemos.podam.api.DataProviderStrategy;
6
import uk.co.jemos.podam.typeManufacturers.StringTypeManufacturerImpl;
7
8
import java.lang.annotation.Annotation;
9
import java.lang.reflect.Type;
10
import java.util.Map;
11
import java.util.Optional;
12
13
public class EnumStringManufacturer extends StringTypeManufacturerImpl {
14
15
    @Override
16
    public String getType(DataProviderStrategy strategy,
17
                          AttributeMetadata attributeMetadata,
18
                          Map<String, Type> genericTypesArgumentsMap) {
19
20
        Optional<Annotation> jsonPropertyAnnotation = attributeMetadata.getAttributeAnnotations().stream()
21
            .filter(annotation -> annotation.annotationType().equals(JsonProperty.class))
22
            .findAny();
23
24
        return jsonPropertyAnnotation.filter(annotation -> !((JsonProperty) annotation).defaultValue().isEmpty())
25
            .map(annotation -> ((JsonProperty) annotation).defaultValue())
26
            .orElseGet(() -> super.getType(strategy, attributeMetadata, genericTypesArgumentsMap));
27
    }
28
}
29