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

File GeneratedValueLoaderTest.java

 

Code metrics

0
21
5
1
89
55
5
0.24
4.2
5
1

Classes

Class Line # Actions
GeneratedValueLoaderTest 18 21 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

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   
 
18    public class GeneratedValueLoaderTest extends AbstractTestBase {
19    @Mocked
20    private ResultSet mockRs;
21   
22    @Mocked
23    private ResultSetMetaData mockMeta;
24   
 
25  1 toggle public GeneratedValueLoaderTest() {}
26   
 
27  1 toggle @BeforeEach
28    void setup() {}
29   
 
30  1 toggle @AfterEach
31    void tearDown() {}
32   
33    /**
34    * Tests the conversion to tuples.
35    */
 
36  1 toggle @Test
37    void toTuples() throws SQLException
38    {
 
39  1 toggle new Expectations() {{
40  1 mockRs.getMetaData();
41  1 result = mockMeta;
42   
43    /*
44    * Mocks the meta data
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    * Mocks the data on ResultSet
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    // Rename the column
85  1 assertThat(testedRows)
86    .extracting(row -> row.getValue("zc_id3"))
87    .containsExactly(4l, 5l);
88    }
89    }