| 1 |
|
package guru.mikelue.foxglove.jdbc; |
| 2 |
|
|
| 3 |
|
import java.sql.ResultSet; |
| 4 |
|
import java.sql.ResultSetMetaData; |
| 5 |
|
import java.sql.SQLException; |
| 6 |
|
|
| 7 |
|
import org.junit.jupiter.api.AfterEach; |
| 8 |
|
import org.junit.jupiter.api.BeforeEach; |
| 9 |
|
import org.junit.jupiter.api.Test; |
| 10 |
|
|
| 11 |
|
import guru.mikelue.misc.testlib.AbstractTestBase; |
| 12 |
|
|
| 13 |
|
import mockit.Expectations; |
| 14 |
|
import mockit.Mocked; |
| 15 |
|
|
| 16 |
|
import static org.assertj.core.api.Assertions.assertThat; |
| 17 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 5 |
Complexity Density: 0.24 |
|
| 18 |
|
public class GeneratedValueLoaderTest extends AbstractTestBase { |
| 19 |
|
@Mocked |
| 20 |
|
private ResultSet mockRs; |
| 21 |
|
|
| 22 |
|
@Mocked |
| 23 |
|
private ResultSetMetaData mockMeta; |
| 24 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 25 |
1 |
public GeneratedValueLoaderTest() {}... |
| 26 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 27 |
1 |
@BeforeEach... |
| 28 |
|
void setup() {} |
| 29 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 30 |
1 |
@AfterEach... |
| 31 |
|
void tearDown() {} |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 36 |
1 |
@Test... |
| 37 |
|
void toTuples() throws SQLException |
| 38 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
|
| 39 |
1 |
new Expectations() {{... |
| 40 |
1 |
mockRs.getMetaData(); |
| 41 |
1 |
result = mockMeta; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
1 |
mockMeta.getColumnCount(); |
| 47 |
1 |
result = 2; |
| 48 |
|
|
| 49 |
1 |
mockMeta.getColumnName(anyInt); |
| 50 |
1 |
returns("zc_id", "zc_id2"); |
| 51 |
|
|
| 52 |
1 |
mockMeta.getColumnType(anyInt); |
| 53 |
1 |
returns(4, 12); |
| 54 |
|
|
| 55 |
1 |
mockMeta.getColumnTypeName(anyInt); |
| 56 |
1 |
returns("INT", "VARCHAR"); |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
1 |
mockRs.next(); |
| 63 |
1 |
returns(true, true, false); |
| 64 |
|
|
| 65 |
1 |
mockRs.getObject(1); |
| 66 |
1 |
returns(1, 2); |
| 67 |
|
|
| 68 |
1 |
mockRs.getObject(2); |
| 69 |
1 |
returns(4l, 5l); |
| 70 |
|
|
| 71 |
|
}}; |
| 72 |
|
|
| 73 |
1 |
var testedRows = new GeneratedValueLoader( |
| 74 |
|
new String[] { "zc_id", "zc_id3" } |
| 75 |
|
).toTuples(mockRs); |
| 76 |
|
|
| 77 |
1 |
assertThat(testedRows) |
| 78 |
|
.hasSize(2); |
| 79 |
|
|
| 80 |
1 |
assertThat(testedRows) |
| 81 |
|
.extracting(row -> row.getValue("zc_id")) |
| 82 |
|
.containsExactly(1, 2); |
| 83 |
|
|
| 84 |
|
|
| 85 |
1 |
assertThat(testedRows) |
| 86 |
|
.extracting(row -> row.getValue("zc_id3")) |
| 87 |
|
.containsExactly(4l, 5l); |
| 88 |
|
} |
| 89 |
|
} |