Skip to content

Commit

Permalink
Merge pull request #3385 from harawata/3332-followup-assert-date-class
Browse files Browse the repository at this point in the history
Avoid java.sql.Date vs. java.util.Date mixup
  • Loading branch information
harawata authored Jan 5, 2025
2 parents 5fa5e1a + 16e3142 commit 7939f2a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
15 changes: 11 additions & 4 deletions src/test/java/org/apache/ibatis/type/DateOnlyTypeHandlerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -42,7 +43,9 @@ public void shouldSetParameter() throws Exception {
@Test
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getDate("column")).thenReturn(SQL_DATE);
assertEquals(DATE, TYPE_HANDLER.getResult(rs, "column"));
Date actual = TYPE_HANDLER.getResult(rs, "column");
assertEquals(DATE, actual);
assertSame(DATE.getClass(), actual.getClass());
verify(rs, never()).wasNull();
}

Expand All @@ -58,7 +61,9 @@ public void shouldGetResultNullFromResultSetByName() throws Exception {
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getDate(1)).thenReturn(SQL_DATE);
assertEquals(DATE, TYPE_HANDLER.getResult(rs, 1));
Date actual = TYPE_HANDLER.getResult(rs, 1);
assertEquals(DATE, actual);
assertSame(DATE.getClass(), actual.getClass());
verify(rs, never()).wasNull();
}

Expand All @@ -74,7 +79,9 @@ public void shouldGetResultNullFromResultSetByPosition() throws Exception {
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
when(cs.getDate(1)).thenReturn(SQL_DATE);
assertEquals(DATE, TYPE_HANDLER.getResult(cs, 1));
Date actual = TYPE_HANDLER.getResult(cs, 1);
assertEquals(DATE, actual);
assertSame(DATE.getClass(), actual.getClass());
verify(cs, never()).wasNull();
}

Expand Down
15 changes: 11 additions & 4 deletions src/test/java/org/apache/ibatis/type/DateTypeHandlerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2024 the original author or authors.
* Copyright 2009-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -43,7 +44,9 @@ public void shouldSetParameter() throws Exception {
@Test
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getTimestamp("column")).thenReturn(TIMESTAMP);
assertEquals(DATE, TYPE_HANDLER.getResult(rs, "column"));
Date actual = TYPE_HANDLER.getResult(rs, "column");
assertEquals(DATE, actual);
assertSame(DATE.getClass(), actual.getClass());
verify(rs, never()).wasNull();
}

Expand All @@ -59,7 +62,9 @@ public void shouldGetResultNullFromResultSetByName() throws Exception {
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getTimestamp(1)).thenReturn(TIMESTAMP);
assertEquals(DATE, TYPE_HANDLER.getResult(rs, 1));
Date actual = TYPE_HANDLER.getResult(rs, 1);
assertEquals(DATE, actual);
assertSame(DATE.getClass(), actual.getClass());
verify(rs, never()).wasNull();
}

Expand All @@ -75,7 +80,9 @@ public void shouldGetResultNullFromResultSetByPosition() throws Exception {
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
when(cs.getTimestamp(1)).thenReturn(TIMESTAMP);
assertEquals(DATE, TYPE_HANDLER.getResult(cs, 1));
Date actual = TYPE_HANDLER.getResult(cs, 1);
assertEquals(DATE, actual);
assertSame(DATE.getClass(), actual.getClass());
verify(cs, never()).wasNull();
}

Expand Down
15 changes: 11 additions & 4 deletions src/test/java/org/apache/ibatis/type/TimeOnlyTypeHandlerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2024 the original author or authors.
* Copyright 2009-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -43,7 +44,9 @@ public void shouldSetParameter() throws Exception {
@Test
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getTime("column")).thenReturn(SQL_TIME);
assertEquals(DATE, TYPE_HANDLER.getResult(rs, "column"));
Date actual = TYPE_HANDLER.getResult(rs, "column");
assertEquals(DATE, actual);
assertSame(DATE.getClass(), actual.getClass());
verify(rs, never()).wasNull();
}

Expand All @@ -59,7 +62,9 @@ public void shouldGetResultNullFromResultSetByName() throws Exception {
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getTime(1)).thenReturn(SQL_TIME);
assertEquals(DATE, TYPE_HANDLER.getResult(rs, 1));
Date actual = TYPE_HANDLER.getResult(rs, 1);
assertEquals(DATE, actual);
assertSame(DATE.getClass(), actual.getClass());
verify(rs, never()).wasNull();
}

Expand All @@ -75,7 +80,9 @@ public void shouldGetResultNullFromResultSetByPosition() throws Exception {
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
when(cs.getTime(1)).thenReturn(SQL_TIME);
assertEquals(DATE, TYPE_HANDLER.getResult(cs, 1));
Date actual = TYPE_HANDLER.getResult(cs, 1);
assertEquals(DATE, actual);
assertSame(DATE.getClass(), actual.getClass());
verify(cs, never()).wasNull();
}

Expand Down

0 comments on commit 7939f2a

Please sign in to comment.