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

File KeySupplierOfIntTest.java

 

Code metrics

2
13
9
1
120
94
10
0.77
1.44
9
1.11

Classes

Class Line # Actions
KeySupplierOfIntTest 18 13 0% 10 0
1.0100%
 

Contributing tests

This file is covered by 7 tests. .

Source view

1    package guru.mikelue.foxglove.jdbc;
2   
3    import java.util.ArrayList;
4    import java.util.stream.Stream;
5   
6    import org.junit.jupiter.api.AfterEach;
7    import org.junit.jupiter.api.BeforeEach;
8    import org.junit.jupiter.api.Test;
9    import org.junit.jupiter.params.ParameterizedTest;
10    import org.junit.jupiter.params.provider.Arguments;
11    import org.junit.jupiter.params.provider.MethodSource;
12   
13    import guru.mikelue.misc.testlib.AbstractTestBase;
14   
15    import static org.assertj.core.api.Assertions.assertThat;
16    import static org.junit.jupiter.params.provider.Arguments.arguments;
17   
 
18    public class KeySupplierOfIntTest extends AbstractTestBase {
 
19  7 toggle public KeySupplierOfIntTest() {}
20   
 
21  7 toggle @BeforeEach
22    void setup() {}
23   
 
24  7 toggle @AfterEach
25    void tearDown() {}
26   
27    /**
28    * Tests the generation by domain.
29    */
 
30  1 toggle @Test
31    void byDomain()
32    {
33  1 var expectedValues = new Long[] {
34    10L, 20L, 15L, 25L, 50L
35    };
36   
37  1 var testedSupplier = KeySupplierOfInt.of(
38    Stream.of(expectedValues).mapToLong(Long::longValue)
39    .toArray()
40    );
41   
42  1 assertGeneratedValue(testedSupplier, expectedValues);
43    }
44   
45    /**
46    * Tests the generation of integer keys.
47    */
 
48  3 toggle @ParameterizedTest
49    @MethodSource
50    void byLimit(
51    long start, int limit, int step,
52    Long[] expectedValues
53    ) {
54  3 var testedSupplier = KeySupplierOfInt.byLimit(start, limit, step);
55  3 assertGeneratedValue(testedSupplier, expectedValues);
56    }
57   
 
58  1 toggle static Arguments[] byLimit()
59    {
60  1 return new Arguments[] {
61    arguments( // normal case(ascending)
62    1, 5, 1,
63    new Long[] {1L, 2L, 3L, 4L, 5L}
64    ),
65    arguments( // step case
66    1, 5, 3,
67    new Long[] {1L, 4L, 7L, 10L, 13L}
68    ),
69    arguments( // descending case
70    5, 5, -1,
71    new Long[] {5L, 4L, 3L, 2L, 1L}
72    ),
73    };
74    }
75   
76    /**
77    * Tests the constructor by range.
78    */
 
79  3 toggle @ParameterizedTest
80    @MethodSource
81    void byRange(
82    long start, long end, int step,
83    Long[] expectedValues
84    ) {
85  3 var testedSupplier = KeySupplierOfInt.byRange(start, end, step);
86  3 assertGeneratedValue(testedSupplier, expectedValues);
87    }
88   
 
89  1 toggle static Arguments[] byRange()
90    {
91  1 return new Arguments[] {
92    arguments( // normal case(ascending)
93    1, 6, 1,
94    new Long[] {1L, 2L, 3L, 4L, 5L}
95    ),
96    arguments( // step case
97    1, 16, 3,
98    new Long[] {1L, 4L, 7L, 10L, 13L}
99    ),
100    arguments( // descending case
101    5, 0, -1,
102    new Long[] {5L, 4L, 3L, 2L, 1L}
103    ),
104    };
105    }
106   
 
107  7 toggle private static void assertGeneratedValue(
108    KeySupplierOfInt testedSupplier,
109    Long[] expectedValues
110    ) {
111  7 var testedValues = new ArrayList<Long>(expectedValues.length);
112   
113  42 for (int i = 0; i < expectedValues.length; i++) {
114  35 testedValues.add(testedSupplier.get());
115    }
116   
117  7 assertThat(testedValues)
118    .containsExactly(expectedValues);
119    }
120    }