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

File ColumnFromStepImplTest.java

 

Code metrics

0
22
7
1
171
109
7
0.32
3.14
7
1

Classes

Class Line # Actions
ColumnFromStepImplTest 16 22 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    package guru.mikelue.foxglove.jdbc;
2   
3    import java.util.function.Consumer;
4    import java.util.function.Supplier;
5    import java.util.stream.IntStream;
6   
7    import org.apache.commons.lang3.mutable.MutableObject;
8    import org.junit.jupiter.api.AfterEach;
9    import org.junit.jupiter.api.BeforeEach;
10    import org.junit.jupiter.api.Test;
11   
12    import guru.mikelue.misc.testlib.AbstractTestBase;
13   
14    import static org.assertj.core.api.Assertions.assertThat;
15   
 
16    public class ColumnFromStepImplTest extends AbstractTestBase {
 
17  3 toggle public ColumnFromStepImplTest() {}
18   
 
19  3 toggle @BeforeEach
20    void setup() {}
21   
 
22  3 toggle @AfterEach
23    void tearDown() {}
24   
25    /**
26    * Tests the supplier by round-robin strategy.
27    */
 
28  1 toggle @Test
29    void roundRobin()
30    {
31    /*
32    * Prepares tested step
33    */
34  1 var supplierHolder = new MutableObject<Supplier<?>>();
35  1 var parentTable = prepareStep(
36    "pt_source", supplierHolder,
37    step -> step.roundRobin()
38    );
39    // :~)
40   
41    /*
42    * Prepares data of parent
43    */
44  1 TombTestUtils.setupTomb(
45    parentTable.getValueTomb(), "pt_source",
46    "Value-1", "Value-2", "Value-3"
47    );
48    // :~)
49   
50  1 @SuppressWarnings("unchecked")
51    var testedSupplier = (Supplier<String>)supplierHolder.get();
52   
53  1 assertThat(
54    IntStream.range(0, 4)
55    .mapToObj(i -> testedSupplier.get())
56    )
57    .containsExactly(
58    "Value-1", "Value-2", "Value-3", "Value-1"
59    );
60    }
61   
62    /**
63    * Tests the supplier by random strategy.
64    */
 
65  1 toggle @Test
66    void random()
67    {
68    /*
69    * Prepares tested step
70    */
71  1 var supplierHolder = new MutableObject<Supplier<?>>();
72  1 var parentTable = prepareStep(
73    "pt_source", supplierHolder,
74    step -> step.random()
75    );
76    // :~)
77   
78    /*
79    * Prepares data of parent
80    */
81  1 var sampleValues = IntStream.range(0, 10)
82    .mapToObj(i -> "Value-" + (i + 1))
83    .toArray(String[]::new);
84   
85  1 TombTestUtils.setupTomb(
86    parentTable.getValueTomb(), "pt_source",
87    sampleValues
88    );
89    // :~)
90   
91  1 @SuppressWarnings("unchecked")
92    var testedSupplier = (Supplier<String>)supplierHolder.get();
93   
94  1 assertThat(
95    IntStream.range(0, 50)
96    .mapToObj(i -> testedSupplier.get())
97    )
98    .containsAnyOf(sampleValues)
99    .doesNotContainSequence(sampleValues);
100    }
101   
102    /**
103    * Tests the transforming of domain values.
104    */
 
105  1 toggle @Test
106    void transformDomain()
107    {
108    /*
109    * Prepares tested step
110    */
111  1 var supplierHolder = new MutableObject<Supplier<?>>();
112  1 var parentTable = ColumnFromStepImplTest.<Integer>prepareStep(
113    "pt_source", supplierHolder,
114    step -> step
115    .transformDomain(
116    /*
117    * Converts the integer domain to string domain
118    */
119    domainStream -> domainStream
120    .map(i -> "Transformed-" + (i + 1))
121    // :~)
122    )
123    .roundRobin()
124    );
125    // :~)
126   
127    /*
128    * Prepares data of parent
129    */
130  1 var sampleValues = IntStream.range(0, 3)
131    .boxed()
132    .toArray(Integer[]::new);
133   
134  1 TombTestUtils.setupTomb(
135    parentTable.getValueTomb(), "pt_source",
136    sampleValues
137    );
138    // :~)
139   
140  1 @SuppressWarnings("unchecked")
141    var testedSupplier = (Supplier<String>)supplierHolder.get();
142   
143  1 assertThat(
144    IntStream.range(0, 3)
145    .mapToObj(i -> testedSupplier.get())
146    )
147    .containsExactly(
148    "Transformed-1", "Transformed-2", "Transformed-3"
149    );
150    }
151   
 
152  3 toggle private static <T> JdbcTableFacet prepareStep(
153    String columnName,
154    MutableObject<Supplier<?>> supplierHolder,
155    Consumer<ColumnFromStepImpl<T>> stepCustomizer
156    ) {
157  3 var parentTable = JdbcTableFacet.builder("sample_parent_table")
158    .build();
159  3 parentTable.getValueTomb().keepColumn(columnName);
160   
161  3 var step = new ColumnFromStepImpl<T>(
162    JdbcTableFacet.builder("sample_child_table"),
163    parentTable, columnName,
164    supplierHolder::setValue
165    );
166   
167  3 stepCustomizer.accept(step);
168   
169  3 return parentTable;
170    }
171    }