Skip to content

Commit 806f0bd

Browse files
committed
Polishing test cases for type handlers
1 parent 6083ac8 commit 806f0bd

29 files changed

+881
-62
lines changed

src/test/java/org/apache/ibatis/type/BaseTypeHandlerTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ public abstract class BaseTypeHandlerTest {
3838

3939
public abstract void shouldSetParameter() throws Exception;
4040

41-
public abstract void shouldGetResultFromResultSet() throws Exception;
41+
public abstract void shouldGetResultFromResultSetByName() throws Exception;
42+
43+
public abstract void shouldGetResultNullFromResultSetByName() throws Exception;
44+
45+
public abstract void shouldGetResultFromResultSetByPosition() throws Exception;
46+
47+
public abstract void shouldGetResultNullFromResultSetByPosition() throws Exception;
4248

4349
public abstract void shouldGetResultFromCallableStatement() throws Exception;
4450

51+
public abstract void shouldGetResultNullFromCallableStatement() throws Exception;
4552
}

src/test/java/org/apache/ibatis/type/BigDecimalTypeHandlerTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,30 @@ public void shouldSetParameter() throws Exception {
3636

3737
@Override
3838
@Test
39-
public void shouldGetResultFromResultSet() throws Exception {
39+
public void shouldGetResultFromResultSetByName() throws Exception {
4040
when(rs.getBigDecimal("column")).thenReturn(new BigDecimal(1));
4141
when(rs.wasNull()).thenReturn(false);
4242
assertEquals(new BigDecimal(1), TYPE_HANDLER.getResult(rs, "column"));
4343
}
4444

45+
@Override
46+
public void shouldGetResultNullFromResultSetByName() throws Exception {
47+
// Unnecessary
48+
}
49+
50+
@Override
51+
@Test
52+
public void shouldGetResultFromResultSetByPosition() throws Exception {
53+
when(rs.getBigDecimal(1)).thenReturn(new BigDecimal(1));
54+
when(rs.wasNull()).thenReturn(false);
55+
assertEquals(new BigDecimal(1), TYPE_HANDLER.getResult(rs, 1));
56+
}
57+
58+
@Override
59+
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
60+
// Unnecessary
61+
}
62+
4563
@Override
4664
@Test
4765
public void shouldGetResultFromCallableStatement() throws Exception {
@@ -50,4 +68,9 @@ public void shouldGetResultFromCallableStatement() throws Exception {
5068
assertEquals(new BigDecimal(1), TYPE_HANDLER.getResult(cs, 1));
5169
}
5270

71+
@Override
72+
public void shouldGetResultNullFromCallableStatement() throws Exception {
73+
// Unnecessary
74+
}
75+
5376
}

src/test/java/org/apache/ibatis/type/BigIntegerTypeHandlerTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.apache.ibatis.type;
1717

1818
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertNull;
1920
import static org.mockito.Mockito.verify;
2021
import static org.mockito.Mockito.when;
2122

@@ -37,12 +38,36 @@ public void shouldSetParameter() throws Exception {
3738

3839
@Override
3940
@Test
40-
public void shouldGetResultFromResultSet() throws Exception {
41+
public void shouldGetResultFromResultSetByName() throws Exception {
4142
when(rs.getBigDecimal("column")).thenReturn(new BigDecimal("707070656505050302797979792923232303"));
4243
when(rs.wasNull()).thenReturn(false);
4344
assertEquals(new BigInteger("707070656505050302797979792923232303"), TYPE_HANDLER.getResult(rs, "column"));
4445
}
4546

47+
@Override
48+
@Test
49+
public void shouldGetResultNullFromResultSetByName() throws Exception {
50+
when(rs.getBigDecimal("column")).thenReturn(null);
51+
when(rs.wasNull()).thenReturn(true);
52+
assertNull(TYPE_HANDLER.getResult(rs, "column"));
53+
}
54+
55+
@Override
56+
@Test
57+
public void shouldGetResultFromResultSetByPosition() throws Exception {
58+
when(rs.getBigDecimal(1)).thenReturn(new BigDecimal("707070656505050302797979792923232303"));
59+
when(rs.wasNull()).thenReturn(false);
60+
assertEquals(new BigInteger("707070656505050302797979792923232303"), TYPE_HANDLER.getResult(rs,1 ));
61+
}
62+
63+
@Override
64+
@Test
65+
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
66+
when(rs.getBigDecimal(1)).thenReturn(null);
67+
when(rs.wasNull()).thenReturn(true);
68+
assertNull(TYPE_HANDLER.getResult(rs,1 ));
69+
}
70+
4671
@Override
4772
@Test
4873
public void shouldGetResultFromCallableStatement() throws Exception {
@@ -51,4 +76,12 @@ public void shouldGetResultFromCallableStatement() throws Exception {
5176
assertEquals(new BigInteger("707070656505050302797979792923232303"), TYPE_HANDLER.getResult(cs, 1));
5277
}
5378

79+
@Override
80+
@Test
81+
public void shouldGetResultNullFromCallableStatement() throws Exception {
82+
when(cs.getBigDecimal(1)).thenReturn(null);
83+
when(cs.wasNull()).thenReturn(true);
84+
assertNull(TYPE_HANDLER.getResult(cs, 1));
85+
}
86+
5487
}

src/test/java/org/apache/ibatis/type/BlobInputStreamTypeHandlerTest.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,38 @@ public void shouldSetParameter() throws Exception {
7575

7676
@Override
7777
@Test
78-
public void shouldGetResultFromResultSet() throws Exception {
78+
public void shouldGetResultFromResultSetByName() throws Exception {
7979
InputStream in = new ByteArrayInputStream("Hello".getBytes());
8080
when(rs.getBlob("column")).thenReturn(blob);
81-
when(rs.getBlob(1)).thenReturn(blob);
8281
when(rs.wasNull()).thenReturn(false);
8382
when(blob.getBinaryStream()).thenReturn(in);
8483
assertThat(TYPE_HANDLER.getResult(rs, "column"), is(in));
85-
assertThat(TYPE_HANDLER.getResult(rs, 1), is(in));
8684

85+
}
86+
87+
@Override
88+
@Test
89+
public void shouldGetResultNullFromResultSetByName() throws Exception {
8790
when(rs.getBlob("column")).thenReturn(null);
88-
when(rs.getBlob(1)).thenReturn(null);
91+
when(rs.wasNull()).thenReturn(true);
8992
assertThat(TYPE_HANDLER.getResult(rs, "column"), nullValue());
93+
}
94+
95+
@Override
96+
@Test
97+
public void shouldGetResultFromResultSetByPosition() throws Exception {
98+
InputStream in = new ByteArrayInputStream("Hello".getBytes());
99+
when(rs.getBlob(1)).thenReturn(blob);
100+
when(rs.wasNull()).thenReturn(false);
101+
when(blob.getBinaryStream()).thenReturn(in);
102+
assertThat(TYPE_HANDLER.getResult(rs, 1), is(in));
103+
}
104+
105+
@Override
106+
@Test
107+
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
108+
when(rs.getBlob(1)).thenReturn(null);
109+
when(rs.wasNull()).thenReturn(true);
90110
assertThat(TYPE_HANDLER.getResult(rs, 1), nullValue());
91111
}
92112

@@ -98,10 +118,14 @@ public void shouldGetResultFromCallableStatement() throws Exception {
98118
when(cs.wasNull()).thenReturn(false);
99119
when(blob.getBinaryStream()).thenReturn(in);
100120
assertThat(TYPE_HANDLER.getResult(cs, 1), is(in));
121+
}
101122

123+
@Override
124+
@Test
125+
public void shouldGetResultNullFromCallableStatement() throws Exception {
102126
when(cs.getBlob(1)).thenReturn(null);
127+
when(cs.wasNull()).thenReturn(true);
103128
assertThat(TYPE_HANDLER.getResult(cs, 1), nullValue());
104-
105129
}
106130

107131
@Test

src/test/java/org/apache/ibatis/type/BlobTypeHandlerTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.apache.ibatis.type;
1717

1818
import static org.junit.Assert.assertArrayEquals;
19+
import static org.junit.Assert.assertNull;
1920
import static org.mockito.Mockito.verify;
2021
import static org.mockito.Mockito.when;
2122

@@ -42,14 +43,40 @@ public void shouldSetParameter() throws Exception {
4243

4344
@Override
4445
@Test
45-
public void shouldGetResultFromResultSet() throws Exception {
46+
public void shouldGetResultFromResultSetByName() throws Exception {
4647
when(rs.getBlob("column")).thenReturn(blob);
4748
when(rs.wasNull()).thenReturn(false);
4849
when(blob.length()).thenReturn(3l);
4950
when(blob.getBytes(1, 3)).thenReturn(new byte[] { 1, 2, 3 });
5051
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(rs, "column"));
5152
}
5253

54+
@Override
55+
@Test
56+
public void shouldGetResultNullFromResultSetByName() throws Exception {
57+
when(rs.getBlob("column")).thenReturn(null);
58+
when(rs.wasNull()).thenReturn(true);
59+
assertNull(TYPE_HANDLER.getResult(rs, "column"));
60+
}
61+
62+
@Override
63+
@Test
64+
public void shouldGetResultFromResultSetByPosition() throws Exception {
65+
when(rs.getBlob(1)).thenReturn(blob);
66+
when(rs.wasNull()).thenReturn(false);
67+
when(blob.length()).thenReturn(3l);
68+
when(blob.getBytes(1, 3)).thenReturn(new byte[] { 1, 2, 3 });
69+
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(rs, 1));
70+
}
71+
72+
@Override
73+
@Test
74+
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
75+
when(rs.getBlob(1)).thenReturn(null);
76+
when(rs.wasNull()).thenReturn(true);
77+
assertNull(TYPE_HANDLER.getResult(rs, 1));
78+
}
79+
5380
@Override
5481
@Test
5582
public void shouldGetResultFromCallableStatement() throws Exception {
@@ -60,4 +87,12 @@ public void shouldGetResultFromCallableStatement() throws Exception {
6087
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(cs, 1));
6188
}
6289

90+
@Override
91+
@Test
92+
public void shouldGetResultNullFromCallableStatement() throws Exception {
93+
when(cs.getBlob(1)).thenReturn(null);
94+
when(cs.wasNull()).thenReturn(true);
95+
assertNull(TYPE_HANDLER.getResult(cs, 1));
96+
}
97+
6398
}

src/test/java/org/apache/ibatis/type/BooleanTypeHandlerTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,30 @@ public void shouldSetParameter() throws Exception {
3434

3535
@Override
3636
@Test
37-
public void shouldGetResultFromResultSet() throws Exception {
37+
public void shouldGetResultFromResultSetByName() throws Exception {
3838
when(rs.getBoolean("column")).thenReturn(true);
3939
when(rs.wasNull()).thenReturn(false);
4040
assertEquals(true, TYPE_HANDLER.getResult(rs, "column"));
4141
}
4242

43+
@Override
44+
public void shouldGetResultNullFromResultSetByName() throws Exception {
45+
// Unnecessary
46+
}
47+
48+
@Override
49+
@Test
50+
public void shouldGetResultFromResultSetByPosition() throws Exception {
51+
when(rs.getBoolean(1)).thenReturn(true);
52+
when(rs.wasNull()).thenReturn(false);
53+
assertEquals(true, TYPE_HANDLER.getResult(rs, 1));
54+
}
55+
56+
@Override
57+
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
58+
// Unnecessary
59+
}
60+
4361
@Override
4462
@Test
4563
public void shouldGetResultFromCallableStatement() throws Exception {
@@ -48,4 +66,9 @@ public void shouldGetResultFromCallableStatement() throws Exception {
4866
assertEquals(true, TYPE_HANDLER.getResult(cs, 1));
4967
}
5068

69+
@Override
70+
public void shouldGetResultNullFromCallableStatement() throws Exception {
71+
// Unnecessary
72+
}
73+
5174
}

src/test/java/org/apache/ibatis/type/ByteArrayTypeHandlerTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,30 @@ public void shouldSetParameter() throws Exception {
3434

3535
@Override
3636
@Test
37-
public void shouldGetResultFromResultSet() throws Exception {
37+
public void shouldGetResultFromResultSetByName() throws Exception {
3838
when(rs.getBytes("column")).thenReturn(new byte[] { 1, 2, 3 });
3939
when(rs.wasNull()).thenReturn(false);
4040
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(rs, "column"));
4141
}
4242

43+
@Override
44+
public void shouldGetResultNullFromResultSetByName() throws Exception {
45+
// Unnecessary
46+
}
47+
48+
@Override
49+
@Test
50+
public void shouldGetResultFromResultSetByPosition() throws Exception {
51+
when(rs.getBytes(1)).thenReturn(new byte[] { 1, 2, 3 });
52+
when(rs.wasNull()).thenReturn(false);
53+
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(rs, 1));
54+
}
55+
56+
@Override
57+
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
58+
// Unnecessary
59+
}
60+
4361
@Override
4462
@Test
4563
public void shouldGetResultFromCallableStatement() throws Exception {
@@ -48,4 +66,9 @@ public void shouldGetResultFromCallableStatement() throws Exception {
4866
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(cs, 1));
4967
}
5068

69+
@Override
70+
public void shouldGetResultNullFromCallableStatement() throws Exception {
71+
// Unnecessary
72+
}
73+
5174
}

src/test/java/org/apache/ibatis/type/ByteTypeHandlerTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,30 @@ public void shouldSetParameter() throws Exception {
3434

3535
@Override
3636
@Test
37-
public void shouldGetResultFromResultSet() throws Exception {
37+
public void shouldGetResultFromResultSetByName() throws Exception {
3838
when(rs.getByte("column")).thenReturn((byte) 100);
3939
when(rs.wasNull()).thenReturn(false);
4040
assertEquals(new Byte((byte) 100), TYPE_HANDLER.getResult(rs, "column"));
4141
}
4242

43+
@Override
44+
public void shouldGetResultNullFromResultSetByName() throws Exception {
45+
// Unnecessary
46+
}
47+
48+
@Override
49+
@Test
50+
public void shouldGetResultFromResultSetByPosition() throws Exception {
51+
when(rs.getByte(1)).thenReturn((byte) 100);
52+
when(rs.wasNull()).thenReturn(false);
53+
assertEquals(new Byte((byte) 100), TYPE_HANDLER.getResult(rs, 1));
54+
}
55+
56+
@Override
57+
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
58+
// Unnecessary
59+
}
60+
4361
@Override
4462
@Test
4563
public void shouldGetResultFromCallableStatement() throws Exception {
@@ -48,4 +66,9 @@ public void shouldGetResultFromCallableStatement() throws Exception {
4866
assertEquals(new Byte((byte) 100), TYPE_HANDLER.getResult(cs, 1));
4967
}
5068

69+
@Override
70+
public void shouldGetResultNullFromCallableStatement() throws Exception {
71+
// Unnecessary
72+
}
73+
5174
}

0 commit comments

Comments
 (0)