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

File DefaultSettingTest.java

 

Code metrics

14
30
10
1
255
204
17
0.57
3
10
1.7

Classes

Class Line # Actions
DefaultSettingTest 21 30 0% 17 0
1.0100%
 

Contributing tests

This file is covered by 54 tests. .

Source view

1    package guru.mikelue.foxglove.setting;
2   
3    import java.math.BigDecimal;
4    import java.sql.JDBCType;
5    import java.time.temporal.Temporal;
6    import java.util.function.Consumer;
7    import java.util.function.Supplier;
8   
9    import org.assertj.core.api.InstanceOfAssertFactories;
10    import org.junit.jupiter.api.AfterEach;
11    import org.junit.jupiter.api.BeforeEach;
12    import org.junit.jupiter.params.ParameterizedTest;
13    import org.junit.jupiter.params.provider.CsvSource;
14    import org.junit.jupiter.params.provider.EnumSource;
15   
16    import guru.mikelue.misc.testlib.AbstractTestBase;
17   
18    import static guru.mikelue.foxglove.ColumnMetaTestUtils.newColumnMeta;
19    import static org.assertj.core.api.Assertions.assertThat;
20   
 
21    public class DefaultSettingTest extends AbstractTestBase {
 
22  54 toggle public DefaultSettingTest() {}
23   
 
24  54 toggle @BeforeEach
25    void setup() {}
26   
 
27  54 toggle @AfterEach
28    void tearDown() {}
29   
30    private final static int timesForSpecValue = 64;
31   
32    /**
33    * Tests the generators with min value of zero.
34    */
 
35  7 toggle @ParameterizedTest
36    @EnumSource(
37    value=JDBCType.class,
38    names={ "TINYINT", "SMALLINT", "INTEGER", "BIGINT", "FLOAT", "REAL", "DOUBLE" }
39    )
40    void atLeastZero(JDBCType jdbcType)
41    {
42  7 var sampleColumnMeta = newColumnMeta(
43    "cl_any", jdbcType
44    );
45   
46  7 var testedSupplierOpt = DefaultSetting.instance()
47    .<Number>resolveSupplier(sampleColumnMeta);
48   
49  7 Consumer<Number> validator = value -> {
50  448 assertThat(value.longValue())
51    .isGreaterThanOrEqualTo(0L);
52    };
53   
54  455 for (int i = 0; i < timesForSpecValue; ++i) {
55  448 assertThat(testedSupplierOpt)
56    .isPresent()
57    .get().extracting(Supplier::get)
58    .satisfies(validator);
59    }
60    }
61   
62    /**
63    * Tests the generators for types of characters.
64    */
 
65  24 toggle @ParameterizedTest
66    @CsvSource({
67    "CHAR,3,3,3",
68    "CHAR,8,8,8",
69    "CHAR,10,8,10",
70    "CHAR,32,8,32",
71    "CHAR,100,32,128",
72    "CHAR,256,32,128",
73    "VARCHAR,4,4,4",
74    "VARCHAR,8,8,8",
75    "VARCHAR,20,8,20",
76    "VARCHAR,32,8,32",
77    "VARCHAR,100,32,128",
78    "VARCHAR,256,32,128",
79    "NCHAR,5,5,5",
80    "NCHAR,8,8,8",
81    "NCHAR,25,8,25",
82    "NCHAR,32,8,32",
83    "NCHAR,100,32,128",
84    "NCHAR,256,32,128",
85    "NVARCHAR,6,6,6",
86    "NVARCHAR,8,8,8",
87    "NVARCHAR,30,8,30",
88    "NVARCHAR,32,8,32",
89    "NVARCHAR,100,32,128",
90    "NVARCHAR,256,32,128",
91    })
92    void chars(
93    JDBCType jdbcType, int size,
94    int expectedMinSize, int expectedMaxSize
95    ) {
96  24 var sampleColumnMeta = newColumnMeta(
97    "cl_any", jdbcType, size
98    );
99   
100  24 var testedSupplierOpt = DefaultSetting.instance()
101    .<String>resolveSupplier(sampleColumnMeta);
102   
103  1560 for (int i = 0; i < timesForSpecValue; ++i) {
104  1536 assertThat(testedSupplierOpt)
105    .isPresent()
106    .get().extracting(Supplier::get, InstanceOfAssertFactories.STRING)
107    .hasSizeBetween(expectedMinSize, expectedMaxSize);
108    }
109    }
110   
111    /**
112    * Tests the generators for types of large text.
113    */
 
114  4 toggle @ParameterizedTest
115    @EnumSource(
116    value=JDBCType.class,
117    names={ "LONGVARCHAR", "CLOB", "LONGNVARCHAR", "NCLOB" }
118    )
119    void largeText(JDBCType jdbcType)
120    {
121  4 var sampleColumnMeta = newColumnMeta(
122    "cl_any", jdbcType
123    );
124   
125  4 var testedSupplierOpt = DefaultSetting.instance()
126    .<String>resolveSupplier(sampleColumnMeta);
127   
128  260 for (int i = 0; i < timesForSpecValue; ++i) {
129  256 assertThat(testedSupplierOpt)
130    .isPresent()
131    .get().extracting(Supplier::get, InstanceOfAssertFactories.STRING)
132    .hasSizeBetween(1024, 2048);
133    }
134    }
135   
136    /**
137    * Tests the binary types.
138    */
 
139  8 toggle @ParameterizedTest
140    @CsvSource({
141    "BINARY,12,12,12",
142    "BINARY,16,16,16",
143    "BINARY,64,16,64",
144    "BINARY,512,16,256",
145    "VARBINARY,12,12,12",
146    "VARBINARY,16,16,16",
147    "VARBINARY,64,16,64",
148    "VARBINARY,512,16,256",
149    })
150    void binary(
151    JDBCType jdbcType, int size,
152    int expectedMinSize, int expectedMaxSize
153    ) {
154  8 var sampleColumnMeta = newColumnMeta(
155    "cl_any", jdbcType, size
156    );
157   
158  8 var testedSupplierOpt = DefaultSetting.instance()
159    .<byte[]>resolveSupplier(sampleColumnMeta);
160   
161  520 for (int i = 0; i < timesForSpecValue; ++i) {
162  512 assertThat(testedSupplierOpt)
163    .isPresent()
164    .get().extracting(Supplier::get, InstanceOfAssertFactories.BYTE_ARRAY)
165    .hasSizeBetween(expectedMinSize, expectedMaxSize);
166    }
167    }
168   
169    /**
170    * Tests the generators for types of large binary.
171    */
 
172  2 toggle @ParameterizedTest
173    @EnumSource(
174    value=JDBCType.class,
175    names={ "LONGVARBINARY", "BLOB" }
176    )
177    void largeBinary(
178    JDBCType jdbcType
179    ) {
180  2 var sampleColumnMeta = newColumnMeta(
181    "cl_any", jdbcType
182    );
183   
184  2 var testedSupplierOpt = DefaultSetting.instance()
185    .<byte[]>resolveSupplier(sampleColumnMeta);
186   
187  130 for (int i = 0; i < timesForSpecValue; ++i) {
188  128 assertThat(testedSupplierOpt)
189    .isPresent()
190    .get().extracting(Supplier::get, InstanceOfAssertFactories.BYTE_ARRAY)
191    .hasSizeBetween(1024, 2048);
192    }
193    }
194   
195    /**
196    * Tests the {@link BigDecimal} generator.
197    */
 
198  4 toggle @ParameterizedTest
199    @CsvSource(
200    value={
201    "DECIMAL,4,2,-99.99,99.99",
202    "NUMERIC,4,2,-99.99,99.99",
203    "DECIMAL,4,0,-9999,9999",
204    "NUMERIC,4,0,-9999,9999",
205    }
206    )
207    void bigDecimal(
208    JDBCType jdbcType,
209    int size, int decimalDigits,
210    BigDecimal expectedMin, BigDecimal expectedMax
211    ) {
212  4 var sampleColumnMeta = newColumnMeta(
213    "cl_any", jdbcType, size, decimalDigits
214    );
215   
216  4 var testedSupplierOpt = DefaultSetting.instance()
217    .<BigDecimal>resolveSupplier(sampleColumnMeta);
218   
219  260 for (int i = 0; i < timesForSpecValue; ++i) {
220  256 assertThat(testedSupplierOpt)
221    .isPresent()
222    .get().extracting(Supplier::get, InstanceOfAssertFactories.BIG_DECIMAL)
223    .isBetween(expectedMin, expectedMax);
224    }
225    }
226   
227    /**
228    * Tests the temporal generator.
229    */
 
230  5 toggle @ParameterizedTest
231    @EnumSource(
232    value=JDBCType.class,
233    names={
234    "DATE", "TIMESTAMP", "TIMESTAMP_WITH_TIMEZONE",
235    "TIME", "TIME_WITH_TIMEZONE",
236    }
237    )
238    void temporalTypes(JDBCType jdbcType)
239    {
240  5 var sampleColumnMeta = newColumnMeta(
241    "cl_any", jdbcType
242    );
243   
244  5 var testedSupplierOpt = DefaultSetting.instance()
245    .<Temporal>resolveSupplier(sampleColumnMeta);
246   
247  325 for (int i = 0; i < timesForSpecValue; ++i) {
248  320 assertThat(testedSupplierOpt)
249    .isPresent()
250    .get().extracting(Supplier::get, InstanceOfAssertFactories.TEMPORAL)
251    .isInstanceOf(Temporal.class)
252    .isNotNull();
253    }
254    }
255    }