| 1 |
|
package guru.mikelue.foxglove.annotation; |
| 2 |
|
|
| 3 |
|
import java.util.ArrayList; |
| 4 |
|
import java.util.List; |
| 5 |
|
|
| 6 |
|
import guru.mikelue.foxglove.DataGenerator; |
| 7 |
|
import guru.mikelue.foxglove.TableFacet; |
| 8 |
|
import guru.mikelue.foxglove.functional.DataGeneratorProvider; |
| 9 |
|
import guru.mikelue.foxglove.functional.TableFacetsProvider; |
| 10 |
|
|
| 11 |
|
|
| 12 |
|
@link |
| 13 |
|
|
| |
|
| 95.6% |
Uncovered Elements: 2 (45) |
Complexity: 8 |
Complexity Density: 0.25 |
|
| 14 |
|
public class ReflectGenDataObjectFactory implements GenDataObjectFactory { |
| 15 |
|
private final static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ReflectGenDataObjectFactory.class); |
| 16 |
|
|
| 17 |
|
private final Object testingInstance; |
| 18 |
|
private final DataGenContext<TableFacet> dataGenContext; |
| 19 |
|
private final GenDataInspector genDataInspector; |
| 20 |
|
private final String nameOfTestedObject; |
| 21 |
|
|
| 22 |
|
|
| 23 |
|
@link |
| 24 |
|
|
| 25 |
|
@param |
| 26 |
|
@param@link |
| 27 |
|
@param |
| 28 |
|
@param |
| 29 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 30 |
22 |
public ReflectGenDataObjectFactory(... |
| 31 |
|
Object testingInstance, |
| 32 |
|
GenData genData, DataGenContext<TableFacet> dataGenContext, |
| 33 |
|
String name |
| 34 |
|
) { |
| 35 |
22 |
this.genDataInspector = GenDataInspector.of(genData); |
| 36 |
22 |
this.testingInstance = testingInstance; |
| 37 |
22 |
this.dataGenContext = dataGenContext; |
| 38 |
22 |
this.nameOfTestedObject = name; |
| 39 |
|
} |
| 40 |
|
|
| |
|
| 94.1% |
Uncovered Elements: 1 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 41 |
19 |
@Override... |
| 42 |
|
public DataGenerator<TableFacet> getDataGenerator() throws Exception |
| 43 |
|
{ |
| 44 |
19 |
var targetClass = testingInstance.getClass(); |
| 45 |
|
|
| 46 |
19 |
if (genDataInspector.useDefaultDataGenerator()) { |
| 47 |
13 |
logger.debug("Using default DataGenerator for: {}", nameOfTestedObject); |
| 48 |
|
|
| 49 |
13 |
return dataGenContext.getDefaultDataGenerator(testingInstance) |
| 50 |
|
.orElseThrow(() -> new IllegalStateException( |
| 51 |
|
"Default DataGenerator is not configured in class: " + targetClass.getSimpleName() |
| 52 |
|
)); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
6 |
var genData = genDataInspector.genData(); |
| 56 |
|
|
| 57 |
6 |
if (genData.generatorName().isEmpty()) { |
| 58 |
3 |
if (logger.isDebugEnabled()) { |
| 59 |
3 |
logger.debug("Using specified DataGenerator provider class[{}] for: {}", |
| 60 |
|
genData.generator(), nameOfTestedObject); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
3 |
@SuppressWarnings("unchecked") |
| 64 |
|
var typeOfProvider = (Class<DataGeneratorProvider<TableFacet>>)genData.generator(); |
| 65 |
3 |
return dataGenContext.getTypedDataGenerator( |
| 66 |
|
typeOfProvider, testingInstance |
| 67 |
|
); |
| 68 |
|
} |
| 69 |
|
|
| 70 |
3 |
return dataGenContext.getNamedDataGenerator( |
| 71 |
|
genData.generatorName(), testingInstance |
| 72 |
|
); |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 3 |
Complexity Density: 0.18 |
|
| 75 |
19 |
@Override... |
| 76 |
|
@SuppressWarnings("unchecked") |
| 77 |
|
public List<TableFacet> getTableFacets() throws Exception |
| 78 |
|
{ |
| 79 |
19 |
var targetClass = testingInstance.getClass(); |
| 80 |
|
|
| 81 |
19 |
if (genDataInspector.useDefaultTableFacets()) { |
| 82 |
4 |
logger.debug("Using default table facets for: {}", nameOfTestedObject); |
| 83 |
|
|
| 84 |
4 |
return dataGenContext.getDefaultTableFacets(testingInstance) |
| 85 |
|
.orElseThrow(() -> new IllegalStateException( |
| 86 |
|
"Default TableFacets is not configured in class: " + targetClass.getSimpleName() |
| 87 |
|
)); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
15 |
var tableFacets = new ArrayList<TableFacet>(genDataInspector.numberOfTableFacets()); |
| 91 |
15 |
var genData = genDataInspector.genData(); |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
15 |
if (logger.isDebugEnabled()) { |
| 98 |
15 |
logger.debug("TableFacets config: [value() #{}]. [facets() #{}]. [facetsNames() #{}]. for: {}", |
| 99 |
|
genData.value().length, genData.facets().length, |
| 100 |
|
genData.facetsNames().length, |
| 101 |
|
nameOfTestedObject |
| 102 |
|
); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
15 |
for (var facetProviderClass: genData.value()) { |
| 106 |
4 |
var typedProviderClass = (Class<TableFacetsProvider<TableFacet>>)facetProviderClass; |
| 107 |
4 |
tableFacets.addAll( |
| 108 |
|
dataGenContext.getTypedTableFacets(typedProviderClass, testingInstance) |
| 109 |
|
); |
| 110 |
|
} |
| 111 |
15 |
for (var facetProviderClass: genData.facets()) { |
| 112 |
4 |
var typedProviderClass = (Class<TableFacetsProvider<TableFacet>>)facetProviderClass; |
| 113 |
4 |
tableFacets.addAll( |
| 114 |
|
dataGenContext.getTypedTableFacets(typedProviderClass, testingInstance) |
| 115 |
|
); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
15 |
for (var facetName: genDataInspector.genData().facetsNames()) { |
| 123 |
14 |
tableFacets.addAll( |
| 124 |
|
dataGenContext.getNamedTableFacets(facetName, testingInstance) |
| 125 |
|
); |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
|
| 129 |
15 |
return tableFacets; |
| 130 |
|
} |
| 131 |
|
} |