From 16e3142033922632e566112546446c31d186277a Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Sun, 5 Jan 2025 12:11:54 +0900 Subject: [PATCH] Avoid java.sql.Date vs. java.util.Date mixup Follow up on #3332 --- .../ibatis/type/DateOnlyTypeHandlerTest.java | 15 +++++++++++---- .../apache/ibatis/type/DateTypeHandlerTest.java | 15 +++++++++++---- .../ibatis/type/TimeOnlyTypeHandlerTest.java | 15 +++++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/apache/ibatis/type/DateOnlyTypeHandlerTest.java b/src/test/java/org/apache/ibatis/type/DateOnlyTypeHandlerTest.java index 181f1b367c5..ab33b9daa0d 100644 --- a/src/test/java/org/apache/ibatis/type/DateOnlyTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/type/DateOnlyTypeHandlerTest.java @@ -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. @@ -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; @@ -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(); } @@ -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(); } @@ -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(); } diff --git a/src/test/java/org/apache/ibatis/type/DateTypeHandlerTest.java b/src/test/java/org/apache/ibatis/type/DateTypeHandlerTest.java index 180d5806dcf..73713dc64e4 100644 --- a/src/test/java/org/apache/ibatis/type/DateTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/type/DateTypeHandlerTest.java @@ -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. @@ -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; @@ -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(); } @@ -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(); } @@ -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(); } diff --git a/src/test/java/org/apache/ibatis/type/TimeOnlyTypeHandlerTest.java b/src/test/java/org/apache/ibatis/type/TimeOnlyTypeHandlerTest.java index 773ea56f792..2527ff52521 100644 --- a/src/test/java/org/apache/ibatis/type/TimeOnlyTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/type/TimeOnlyTypeHandlerTest.java @@ -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. @@ -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; @@ -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(); } @@ -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(); } @@ -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(); }