Skip to content

Commit

Permalink
Merge pull request #647 from kazuki43zoo/polish-typehandler-tests
Browse files Browse the repository at this point in the history
Polishing test cases for type handlers
  • Loading branch information
emacarron committed Apr 21, 2016
2 parents 6083ac8 + 806f0bd commit be0aed3
Show file tree
Hide file tree
Showing 29 changed files with 881 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ public abstract class BaseTypeHandlerTest {

public abstract void shouldSetParameter() throws Exception;

public abstract void shouldGetResultFromResultSet() throws Exception;
public abstract void shouldGetResultFromResultSetByName() throws Exception;

public abstract void shouldGetResultNullFromResultSetByName() throws Exception;

public abstract void shouldGetResultFromResultSetByPosition() throws Exception;

public abstract void shouldGetResultNullFromResultSetByPosition() throws Exception;

public abstract void shouldGetResultFromCallableStatement() throws Exception;

public abstract void shouldGetResultNullFromCallableStatement() throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,30 @@ public void shouldSetParameter() throws Exception {

@Override
@Test
public void shouldGetResultFromResultSet() throws Exception {
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getBigDecimal("column")).thenReturn(new BigDecimal(1));
when(rs.wasNull()).thenReturn(false);
assertEquals(new BigDecimal(1), TYPE_HANDLER.getResult(rs, "column"));
}

@Override
public void shouldGetResultNullFromResultSetByName() throws Exception {
// Unnecessary
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getBigDecimal(1)).thenReturn(new BigDecimal(1));
when(rs.wasNull()).thenReturn(false);
assertEquals(new BigDecimal(1), TYPE_HANDLER.getResult(rs, 1));
}

@Override
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
// Unnecessary
}

@Override
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
Expand All @@ -50,4 +68,9 @@ public void shouldGetResultFromCallableStatement() throws Exception {
assertEquals(new BigDecimal(1), TYPE_HANDLER.getResult(cs, 1));
}

@Override
public void shouldGetResultNullFromCallableStatement() throws Exception {
// Unnecessary
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.apache.ibatis.type;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

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

@Override
@Test
public void shouldGetResultFromResultSet() throws Exception {
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getBigDecimal("column")).thenReturn(new BigDecimal("707070656505050302797979792923232303"));
when(rs.wasNull()).thenReturn(false);
assertEquals(new BigInteger("707070656505050302797979792923232303"), TYPE_HANDLER.getResult(rs, "column"));
}

@Override
@Test
public void shouldGetResultNullFromResultSetByName() throws Exception {
when(rs.getBigDecimal("column")).thenReturn(null);
when(rs.wasNull()).thenReturn(true);
assertNull(TYPE_HANDLER.getResult(rs, "column"));
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getBigDecimal(1)).thenReturn(new BigDecimal("707070656505050302797979792923232303"));
when(rs.wasNull()).thenReturn(false);
assertEquals(new BigInteger("707070656505050302797979792923232303"), TYPE_HANDLER.getResult(rs,1 ));
}

@Override
@Test
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
when(rs.getBigDecimal(1)).thenReturn(null);
when(rs.wasNull()).thenReturn(true);
assertNull(TYPE_HANDLER.getResult(rs,1 ));
}

@Override
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
Expand All @@ -51,4 +76,12 @@ public void shouldGetResultFromCallableStatement() throws Exception {
assertEquals(new BigInteger("707070656505050302797979792923232303"), TYPE_HANDLER.getResult(cs, 1));
}

@Override
@Test
public void shouldGetResultNullFromCallableStatement() throws Exception {
when(cs.getBigDecimal(1)).thenReturn(null);
when(cs.wasNull()).thenReturn(true);
assertNull(TYPE_HANDLER.getResult(cs, 1));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,38 @@ public void shouldSetParameter() throws Exception {

@Override
@Test
public void shouldGetResultFromResultSet() throws Exception {
public void shouldGetResultFromResultSetByName() throws Exception {
InputStream in = new ByteArrayInputStream("Hello".getBytes());
when(rs.getBlob("column")).thenReturn(blob);
when(rs.getBlob(1)).thenReturn(blob);
when(rs.wasNull()).thenReturn(false);
when(blob.getBinaryStream()).thenReturn(in);
assertThat(TYPE_HANDLER.getResult(rs, "column"), is(in));
assertThat(TYPE_HANDLER.getResult(rs, 1), is(in));

}

@Override
@Test
public void shouldGetResultNullFromResultSetByName() throws Exception {
when(rs.getBlob("column")).thenReturn(null);
when(rs.getBlob(1)).thenReturn(null);
when(rs.wasNull()).thenReturn(true);
assertThat(TYPE_HANDLER.getResult(rs, "column"), nullValue());
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
InputStream in = new ByteArrayInputStream("Hello".getBytes());
when(rs.getBlob(1)).thenReturn(blob);
when(rs.wasNull()).thenReturn(false);
when(blob.getBinaryStream()).thenReturn(in);
assertThat(TYPE_HANDLER.getResult(rs, 1), is(in));
}

@Override
@Test
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
when(rs.getBlob(1)).thenReturn(null);
when(rs.wasNull()).thenReturn(true);
assertThat(TYPE_HANDLER.getResult(rs, 1), nullValue());
}

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

@Override
@Test
public void shouldGetResultNullFromCallableStatement() throws Exception {
when(cs.getBlob(1)).thenReturn(null);
when(cs.wasNull()).thenReturn(true);
assertThat(TYPE_HANDLER.getResult(cs, 1), nullValue());

}

@Test
Expand Down
37 changes: 36 additions & 1 deletion src/test/java/org/apache/ibatis/type/BlobTypeHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.apache.ibatis.type;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

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

@Override
@Test
public void shouldGetResultFromResultSet() throws Exception {
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getBlob("column")).thenReturn(blob);
when(rs.wasNull()).thenReturn(false);
when(blob.length()).thenReturn(3l);
when(blob.getBytes(1, 3)).thenReturn(new byte[] { 1, 2, 3 });
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(rs, "column"));
}

@Override
@Test
public void shouldGetResultNullFromResultSetByName() throws Exception {
when(rs.getBlob("column")).thenReturn(null);
when(rs.wasNull()).thenReturn(true);
assertNull(TYPE_HANDLER.getResult(rs, "column"));
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getBlob(1)).thenReturn(blob);
when(rs.wasNull()).thenReturn(false);
when(blob.length()).thenReturn(3l);
when(blob.getBytes(1, 3)).thenReturn(new byte[] { 1, 2, 3 });
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(rs, 1));
}

@Override
@Test
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
when(rs.getBlob(1)).thenReturn(null);
when(rs.wasNull()).thenReturn(true);
assertNull(TYPE_HANDLER.getResult(rs, 1));
}

@Override
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
Expand All @@ -60,4 +87,12 @@ public void shouldGetResultFromCallableStatement() throws Exception {
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(cs, 1));
}

@Override
@Test
public void shouldGetResultNullFromCallableStatement() throws Exception {
when(cs.getBlob(1)).thenReturn(null);
when(cs.wasNull()).thenReturn(true);
assertNull(TYPE_HANDLER.getResult(cs, 1));
}

}
25 changes: 24 additions & 1 deletion src/test/java/org/apache/ibatis/type/BooleanTypeHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,30 @@ public void shouldSetParameter() throws Exception {

@Override
@Test
public void shouldGetResultFromResultSet() throws Exception {
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getBoolean("column")).thenReturn(true);
when(rs.wasNull()).thenReturn(false);
assertEquals(true, TYPE_HANDLER.getResult(rs, "column"));
}

@Override
public void shouldGetResultNullFromResultSetByName() throws Exception {
// Unnecessary
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getBoolean(1)).thenReturn(true);
when(rs.wasNull()).thenReturn(false);
assertEquals(true, TYPE_HANDLER.getResult(rs, 1));
}

@Override
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
// Unnecessary
}

@Override
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
Expand All @@ -48,4 +66,9 @@ public void shouldGetResultFromCallableStatement() throws Exception {
assertEquals(true, TYPE_HANDLER.getResult(cs, 1));
}

@Override
public void shouldGetResultNullFromCallableStatement() throws Exception {
// Unnecessary
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,30 @@ public void shouldSetParameter() throws Exception {

@Override
@Test
public void shouldGetResultFromResultSet() throws Exception {
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getBytes("column")).thenReturn(new byte[] { 1, 2, 3 });
when(rs.wasNull()).thenReturn(false);
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(rs, "column"));
}

@Override
public void shouldGetResultNullFromResultSetByName() throws Exception {
// Unnecessary
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getBytes(1)).thenReturn(new byte[] { 1, 2, 3 });
when(rs.wasNull()).thenReturn(false);
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(rs, 1));
}

@Override
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
// Unnecessary
}

@Override
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
Expand All @@ -48,4 +66,9 @@ public void shouldGetResultFromCallableStatement() throws Exception {
assertArrayEquals(new byte[] { 1, 2, 3 }, TYPE_HANDLER.getResult(cs, 1));
}

@Override
public void shouldGetResultNullFromCallableStatement() throws Exception {
// Unnecessary
}

}
25 changes: 24 additions & 1 deletion src/test/java/org/apache/ibatis/type/ByteTypeHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,30 @@ public void shouldSetParameter() throws Exception {

@Override
@Test
public void shouldGetResultFromResultSet() throws Exception {
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getByte("column")).thenReturn((byte) 100);
when(rs.wasNull()).thenReturn(false);
assertEquals(new Byte((byte) 100), TYPE_HANDLER.getResult(rs, "column"));
}

@Override
public void shouldGetResultNullFromResultSetByName() throws Exception {
// Unnecessary
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getByte(1)).thenReturn((byte) 100);
when(rs.wasNull()).thenReturn(false);
assertEquals(new Byte((byte) 100), TYPE_HANDLER.getResult(rs, 1));
}

@Override
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
// Unnecessary
}

@Override
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
Expand All @@ -48,4 +66,9 @@ public void shouldGetResultFromCallableStatement() throws Exception {
assertEquals(new Byte((byte) 100), TYPE_HANDLER.getResult(cs, 1));
}

@Override
public void shouldGetResultNullFromCallableStatement() throws Exception {
// Unnecessary
}

}
Loading

0 comments on commit be0aed3

Please sign in to comment.