| 1 |
|
package guru.mikelue.foxglove.annotation; |
| 2 |
|
|
| 3 |
|
import java.util.List; |
| 4 |
|
import java.util.Optional; |
| 5 |
|
import java.util.function.BiConsumer; |
| 6 |
|
import java.util.stream.Stream; |
| 7 |
|
|
| 8 |
|
import org.junit.jupiter.api.AfterEach; |
| 9 |
|
import org.junit.jupiter.api.BeforeEach; |
| 10 |
|
import org.junit.jupiter.params.ParameterizedTest; |
| 11 |
|
import org.junit.jupiter.params.provider.Arguments; |
| 12 |
|
import org.junit.jupiter.params.provider.MethodSource; |
| 13 |
|
|
| 14 |
|
import guru.mikelue.misc.testlib.AbstractTestBase; |
| 15 |
|
|
| 16 |
|
import guru.mikelue.foxglove.DataGenerator; |
| 17 |
|
import guru.mikelue.foxglove.TableFacet; |
| 18 |
|
import guru.mikelue.foxglove.functional.DataGeneratorProvider; |
| 19 |
|
import guru.mikelue.foxglove.functional.TableFacetProvider; |
| 20 |
|
import guru.mikelue.foxglove.functional.TableFacetsProvider; |
| 21 |
|
import guru.mikelue.foxglove.setting.DataSettingInfo; |
| 22 |
|
import mockit.Expectations; |
| 23 |
|
import mockit.Mocked; |
| 24 |
|
|
| 25 |
|
import static java.util.Collections.emptyList; |
| 26 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (71) |
Complexity: 18 |
Complexity Density: 0.35 |
|
| 27 |
|
public class ReflectGenDataObjectFactoryTest extends AbstractTestBase { |
| 28 |
|
@Mocked |
| 29 |
|
private GenData mockGenData; |
| 30 |
|
|
| 31 |
|
@Mocked |
| 32 |
|
private DataGenContext<TableFacet> mockDataGenContext; |
| 33 |
|
|
| 34 |
|
private static DataGenerator<TableFacet> fakeDataGenerator = new FakeDataGenerator(); |
| 35 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 36 |
6 |
public ReflectGenDataObjectFactoryTest() {}... |
| 37 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 38 |
6 |
@BeforeEach... |
| 39 |
|
void setup() {} |
| 40 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 41 |
6 |
@AfterEach... |
| 42 |
|
void tearDown() {} |
| 43 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
4-
|
|
| 44 |
3 |
@ParameterizedTest... |
| 45 |
|
@MethodSource |
| 46 |
|
void getDataGenerator( |
| 47 |
|
String generatorName, Class<? extends DataGeneratorProvider<TableFacet>> providerClass, |
| 48 |
|
BiConsumer<DataGenContext<TableFacet>, Object> verifyFunction |
| 49 |
|
) throws Exception { |
| 50 |
3 |
var currentObject = this; |
| 51 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 52 |
3 |
new Expectations() {{... |
| 53 |
3 |
mockGenData.generatorName(); |
| 54 |
3 |
result = generatorName; |
| 55 |
|
|
| 56 |
3 |
mockGenData.generator(); |
| 57 |
3 |
result = providerClass; |
| 58 |
|
}}; |
| 59 |
|
|
| 60 |
3 |
verifyFunction.accept(mockDataGenContext, currentObject); |
| 61 |
|
|
| 62 |
3 |
if (!generatorName.isEmpty()) { |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 63 |
1 |
new Expectations() {{... |
| 64 |
1 |
mockDataGenContext.getNamedDataGenerator( |
| 65 |
|
generatorName, currentObject |
| 66 |
|
); |
| 67 |
1 |
result = fakeDataGenerator; |
| 68 |
1 |
times = 1; |
| 69 |
|
}}; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
3 |
if (!GenData.FallbackDataGeneratorProvider.class.equals(providerClass)) { |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 73 |
1 |
new Expectations() {{... |
| 74 |
1 |
mockDataGenContext.getTypedDataGenerator( |
| 75 |
|
providerClass, currentObject |
| 76 |
|
); |
| 77 |
1 |
result = fakeDataGenerator; |
| 78 |
1 |
times = 1; |
| 79 |
|
}}; |
| 80 |
|
} |
| 81 |
|
|
| 82 |
3 |
newTestedFactory().getDataGenerator(); |
| 83 |
|
} |
| 84 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
| 85 |
|
class FakeDataGeneratorProvider implements DataGeneratorProvider<TableFacet> { |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 86 |
0 |
@Override... |
| 87 |
|
public DataGenerator<TableFacet> get() |
| 88 |
|
{ |
| 89 |
0 |
return fakeDataGenerator; |
| 90 |
|
} |
| 91 |
|
} |
| 92 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 93 |
1 |
static Stream<Arguments> getDataGenerator()... |
| 94 |
|
{ |
| 95 |
|
record TestCase( |
| 96 |
|
String generatorName, |
| 97 |
|
Class<? extends DataGeneratorProvider<TableFacet>> providerClass, |
| 98 |
|
BiConsumer<DataGenContext<TableFacet>, Object> verifyFunction |
| 99 |
|
) {} |
| 100 |
|
|
| 101 |
1 |
return Stream.<TestCase>of( |
| 102 |
|
|
| 103 |
|
new TestCase( |
| 104 |
|
"", GenData.FallbackDataGeneratorProvider.class, |
| 105 |
|
(context, obj) -> { |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 106 |
1 |
new Expectations() {{... |
| 107 |
1 |
context.getDefaultDataGenerator(obj); |
| 108 |
1 |
result = Optional.of(fakeDataGenerator); |
| 109 |
1 |
times = 1; |
| 110 |
|
}}; |
| 111 |
|
} |
| 112 |
|
), |
| 113 |
|
|
| 114 |
|
new TestCase( |
| 115 |
|
"", FakeDataGeneratorProvider.class, |
| 116 |
|
(context, obj) -> {} |
| 117 |
|
), |
| 118 |
|
|
| 119 |
|
new TestCase( |
| 120 |
|
"fakeName", GenData.FallbackDataGeneratorProvider.class, |
| 121 |
|
(context, obj) -> {} |
| 122 |
|
) |
| 123 |
|
) |
| 124 |
|
.map(testCase -> Arguments.of( |
| 125 |
|
testCase.generatorName, |
| 126 |
|
testCase.providerClass, |
| 127 |
|
testCase.verifyFunction |
| 128 |
|
)); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
|
| 132 |
|
@link |
| 133 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
4-
|
|
| 134 |
3 |
@ParameterizedTest... |
| 135 |
|
@MethodSource |
| 136 |
|
void getTableFacets( |
| 137 |
|
Class<? extends TableFacetsProvider<TableFacet>>[] providers, |
| 138 |
|
String[] names, |
| 139 |
|
BiConsumer<DataGenContext<TableFacet>, Object> verifyFunction |
| 140 |
|
) throws Exception { |
| 141 |
3 |
var currentObject = this; |
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 146 |
3 |
new Expectations() {{... |
| 147 |
3 |
mockGenData.generatorName(); |
| 148 |
3 |
result = ""; |
| 149 |
|
|
| 150 |
3 |
mockGenData.value(); |
| 151 |
3 |
result = providers; |
| 152 |
|
|
| 153 |
3 |
mockGenData.facets(); |
| 154 |
3 |
result = providers; |
| 155 |
|
|
| 156 |
3 |
mockGenData.facetsNames(); |
| 157 |
3 |
result = names; |
| 158 |
|
}}; |
| 159 |
|
|
| 160 |
3 |
for (var providerClass: providers) { |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 161 |
2 |
new Expectations() {{... |
| 162 |
2 |
mockDataGenContext.getTypedTableFacets( |
| 163 |
|
providerClass, currentObject |
| 164 |
|
); |
| 165 |
2 |
result = emptyList(); |
| 166 |
2 |
times = 2; |
| 167 |
|
}}; |
| 168 |
|
} |
| 169 |
|
|
| 170 |
3 |
for (var name: names) { |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 171 |
2 |
new Expectations() {{... |
| 172 |
2 |
mockDataGenContext.getNamedTableFacets( |
| 173 |
|
name, currentObject |
| 174 |
|
); |
| 175 |
2 |
result = emptyList(); |
| 176 |
2 |
times = 1; |
| 177 |
|
}}; |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
|
| 181 |
3 |
verifyFunction.accept(mockDataGenContext, currentObject); |
| 182 |
|
|
| 183 |
3 |
newTestedFactory().getTableFacets(); |
| 184 |
|
} |
| 185 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
| 186 |
|
class FakeTableFacetsProvider_1 implements TableFacetProvider<TableFacet> { |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 187 |
0 |
@Override... |
| 188 |
|
public TableFacet getOne() |
| 189 |
|
{ |
| 190 |
0 |
return null; |
| 191 |
|
} |
| 192 |
|
} |
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
| 193 |
|
class FakeTableFacetsProvider_2 implements TableFacetProvider<TableFacet> { |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 194 |
0 |
@Override... |
| 195 |
|
public TableFacet getOne() |
| 196 |
|
{ |
| 197 |
0 |
return null; |
| 198 |
|
} |
| 199 |
|
} |
| 200 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 201 |
1 |
static Stream<Arguments> getTableFacets()... |
| 202 |
|
{ |
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 203 |
|
record TestCase( |
| 204 |
|
Class<?>[] providers, |
| 205 |
|
String[] names, |
| 206 |
|
BiConsumer<DataGenContext<TableFacet>, Object> verifyFunction |
| 207 |
|
) {} |
| 208 |
|
|
| 209 |
1 |
return Stream.<TestCase>of( |
| 210 |
|
|
| 211 |
|
new TestCase( |
| 212 |
|
new Class<?>[0], new String[0], |
| 213 |
|
(context, obj) -> { |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 214 |
1 |
new Expectations() {{... |
| 215 |
1 |
context.getDefaultTableFacets(obj); |
| 216 |
1 |
result = Optional.of(emptyList()); |
| 217 |
1 |
times = 1; |
| 218 |
|
}}; |
| 219 |
|
} |
| 220 |
|
), |
| 221 |
|
|
| 222 |
|
new TestCase( |
| 223 |
|
new Class<?>[] { FakeTableFacetsProvider_1.class, FakeTableFacetsProvider_2.class }, |
| 224 |
|
new String[0], |
| 225 |
|
(context, obj) -> {} |
| 226 |
|
), |
| 227 |
|
|
| 228 |
|
new TestCase( |
| 229 |
|
new Class<?>[0], |
| 230 |
|
new String[] { "fakeName1", "fakeName2" }, |
| 231 |
|
(context, obj) -> {} |
| 232 |
|
) |
| 233 |
|
) |
| 234 |
|
.map(testCase -> Arguments.of( |
| 235 |
|
testCase.providers, |
| 236 |
|
testCase.names, |
| 237 |
|
testCase.verifyFunction |
| 238 |
|
)); |
| 239 |
|
} |
| 240 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 241 |
6 |
private ReflectGenDataObjectFactory newTestedFactory()... |
| 242 |
|
{ |
| 243 |
6 |
return new ReflectGenDataObjectFactory( |
| 244 |
|
this, |
| 245 |
|
mockGenData, mockDataGenContext, |
| 246 |
|
"Test-Main" |
| 247 |
|
); |
| 248 |
|
} |
| 249 |
|
} |
| 250 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 251 |
|
class FakeDataGenerator implements DataGenerator<TableFacet> { |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 252 |
0 |
@Override... |
| 253 |
|
public DataGenerator<TableFacet> withSetting(DataSettingInfo setting) |
| 254 |
|
{ |
| 255 |
0 |
throw new UnsupportedOperationException("Unimplemented method 'withSetting'"); |
| 256 |
|
} |
| 257 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 258 |
0 |
@Override... |
| 259 |
|
public int generate(List<TableFacet> tables) |
| 260 |
|
{ |
| 261 |
0 |
throw new UnsupportedOperationException("Unimplemented method 'generate'"); |
| 262 |
|
} |
| 263 |
|
} |