1. Project Clover database Wed Nov 12 2025 05:07:35 UTC
  2. Package guru.mikelue.foxglove.annotation

File GenDataProcessor.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
14
4
1
106
53
5
0.36
3.5
4
1.25

Classes

Class Line # Actions
GenDataProcessor 11 14 0% 5 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package guru.mikelue.foxglove.annotation;
2   
3    import java.lang.reflect.AnnotatedElement;
4    import java.util.function.Supplier;
5   
6    import guru.mikelue.foxglove.TableFacet;
7   
8    /**
9    * Worker class for test framework integration.
10    */
 
11    public class GenDataProcessor {
12    private final boolean hasGenData;
13   
14    private final Object testingInstance;
15    private final AnnotatedElement annotatedElement;
16    private final Supplier<DataGenContext<TableFacet>> supplierOfDataGenContext;
17    private final String name;
18   
19    /**
20    * Creates an instance of {@link GenDataProcessor} on a tested method.
21    *
22    * @param testingInstance The instance of tested class
23    * @param annotatedElement The {@link GenData} annotated element (class or method)
24    * @param supplierOfDataGenContext The supplier of data generation context
25    * @param name The name of tested method or class
26    */
 
27  44 toggle public GenDataProcessor(
28    Object testingInstance, AnnotatedElement annotatedElement,
29    Supplier<DataGenContext<TableFacet>> supplierOfDataGenContext,
30    String name
31    ) {
32  44 var genData = annotatedElement.getAnnotation(GenData.class);
33   
34  44 this.hasGenData = (genData != null);
35  44 this.testingInstance = testingInstance;
36  44 this.annotatedElement = annotatedElement;
37  44 this.supplierOfDataGenContext = supplierOfDataGenContext;
38  44 this.name = name;
39    }
40   
41    /**
42    * Indicates whether {@link GenData} is present on tested method of current.
43    *
44    * @return true if data generation is required; false otherwise
45    */
 
46  46 toggle public boolean hasDataGenerating()
47    {
48  46 return hasGenData;
49    }
50   
51    /**
52    * Performs data generating action.
53    *
54    * @return The number of generated rows; -1 if no generation is performed
55    *
56    * @throws Exception if any error is encountered during data generation
57    */
 
58  26 toggle public int performGenerating() throws Exception
59    {
60  26 if (!hasDataGenerating()) {
61  3 return -1;
62    }
63   
64  23 var objectFactory = buildObjectFactory(
65    testingInstance,
66    annotatedElement.getAnnotation(GenData.class),
67    supplierOfDataGenContext.get(),
68    name
69    );
70   
71    /*
72    * Prepares data generator and table facets
73    */
74  23 var dataGenerator = objectFactory.getDataGenerator();
75  23 var tableFacets = objectFactory.getTableFacets();
76    // :~)
77   
78  23 return dataGenerator.generate(tableFacets);
79    }
80   
81    /**
82    * Builds the instance of {@link GenDataObjectFactory}.
83    *
84    * <p>
85    * This method may be overridden by subclasses to provide customized
86    * factory of object.
87    *
88    * @param testingInstance The instance of tested class
89    * @param genData The information of {@link GenData}
90    * @param dataGenContext The context for data generating
91    * @param name The name of tested method or class
92    *
93    * @return The instance of {@link GenDataObjectFactory}
94    */
 
95  16 toggle protected GenDataObjectFactory buildObjectFactory(
96    Object testingInstance, GenData genData,
97    DataGenContext<TableFacet> dataGenContext,
98    String name
99    ) {
100  16 return new ReflectGenDataObjectFactory(
101    testingInstance, genData,
102    dataGenContext,
103    name
104    );
105    }
106    }