diff --git a/hutool-core/src/test/java/cn/hutool/core/date/WeekTest.java b/hutool-core/src/test/java/cn/hutool/core/date/WeekTest.java index 26f9f95c7..90d158bf8 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/WeekTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/WeekTest.java @@ -4,6 +4,7 @@ import org.junit.Assert; import org.junit.Test; import java.time.DayOfWeek; +import java.util.Calendar; public class WeekTest { @@ -46,6 +47,9 @@ public class WeekTest { Assert.assertEquals(Week.THURSDAY, Week.of(DayOfWeek.THURSDAY)); Assert.assertEquals(Week.FRIDAY, Week.of(DayOfWeek.FRIDAY)); Assert.assertEquals(Week.SATURDAY, Week.of(DayOfWeek.SATURDAY)); + Assert.assertEquals(Week.SATURDAY, Week.of(Calendar.SATURDAY)); + Assert.assertNull(Week.of(10)); + Assert.assertNull(Week.of(-1)); } @Test @@ -58,4 +62,17 @@ public class WeekTest { Assert.assertEquals(DayOfWeek.SATURDAY, Week.SATURDAY.toJdkDayOfWeek()); Assert.assertEquals(DayOfWeek.SUNDAY, Week.SUNDAY.toJdkDayOfWeek()); } + + @Test + public void toChineseTest(){ + Assert.assertEquals("周一",Week.MONDAY.toChinese("周")); + Assert.assertEquals("星期一",Week.MONDAY.toChinese("星期")); + Assert.assertEquals("星期二",Week.TUESDAY.toChinese("星期")); + Assert.assertEquals("星期三",Week.WEDNESDAY.toChinese("星期")); + Assert.assertEquals("星期四",Week.THURSDAY.toChinese("星期")); + Assert.assertEquals("星期五",Week.FRIDAY.toChinese("星期")); + Assert.assertEquals("星期六",Week.SATURDAY.toChinese("星期")); + Assert.assertEquals("星期日",Week.SUNDAY.toChinese("星期")); + Assert.assertEquals("星期一",Week.MONDAY.toChinese()); + } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/ZodiacTest.java b/hutool-core/src/test/java/cn/hutool/core/date/ZodiacTest.java index dac1329c3..bbe1eac5c 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/ZodiacTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/ZodiacTest.java @@ -3,6 +3,9 @@ package cn.hutool.core.date; import org.junit.Assert; import org.junit.Test; +import java.util.Calendar; +import java.util.Date; + public class ZodiacTest { @Test @@ -10,6 +13,11 @@ public class ZodiacTest { Assert.assertEquals("摩羯座", Zodiac.getZodiac(Month.JANUARY, 19)); Assert.assertEquals("水瓶座", Zodiac.getZodiac(Month.JANUARY, 20)); Assert.assertEquals("巨蟹座", Zodiac.getZodiac(6, 17)); + Calendar calendar = Calendar.getInstance(); + calendar.set(2022, Calendar.JULY, 17); + Assert.assertEquals("巨蟹座", Zodiac.getZodiac(calendar.getTime())); + Assert.assertEquals("巨蟹座", Zodiac.getZodiac(calendar)); + Assert.assertNull(Zodiac.getZodiac((Calendar) null)); } @Test @@ -17,5 +25,11 @@ public class ZodiacTest { Assert.assertEquals("狗", Zodiac.getChineseZodiac(1994)); Assert.assertEquals("狗", Zodiac.getChineseZodiac(2018)); Assert.assertEquals("猪", Zodiac.getChineseZodiac(2019)); + Calendar calendar = Calendar.getInstance(); + calendar.set(2022, Calendar.JULY, 17); + Assert.assertEquals("虎", Zodiac.getChineseZodiac(calendar.getTime())); + Assert.assertEquals("虎", Zodiac.getChineseZodiac(calendar)); + Assert.assertNull(Zodiac.getChineseZodiac(1899)); + Assert.assertNull(Zodiac.getChineseZodiac((Calendar) null)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/ZoneUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/date/ZoneUtilTest.java new file mode 100644 index 000000000..c9a3f14ea --- /dev/null +++ b/hutool-core/src/test/java/cn/hutool/core/date/ZoneUtilTest.java @@ -0,0 +1,16 @@ +package cn.hutool.core.date; + +import org.junit.Assert; +import org.junit.Test; + +import java.time.ZoneId; +import java.util.TimeZone; + +public class ZoneUtilTest { + + @Test + public void test() { + Assert.assertEquals(ZoneId.systemDefault(), ZoneUtil.toZoneId(null)); + Assert.assertEquals(TimeZone.getDefault(), ZoneUtil.toTimeZone(null)); + } +} diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/reader/MapSheetReader.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/reader/MapSheetReader.java index 9a0f65d9f..ec8a2fc00 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/reader/MapSheetReader.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/reader/MapSheetReader.java @@ -44,7 +44,9 @@ public class MapSheetReader extends AbstractSheetReader if (headerRowIndex < firstRowNum) { throw new IndexOutOfBoundsException(StrUtil.format("Header row index {} is lower than first row index {}.", headerRowIndex, firstRowNum)); } else if (headerRowIndex > lastRowNum) { - throw new IndexOutOfBoundsException(StrUtil.format("Header row index {} is greater than last row index {}.", headerRowIndex, firstRowNum)); + throw new IndexOutOfBoundsException(StrUtil.format("Header row index {} is greater than last row index {}.", headerRowIndex, lastRowNum)); + } else if (startRowIndex > lastRowNum) { + throw new IndexOutOfBoundsException(StrUtil.format("startRowIndex row index {} is greater than last row index {}.", startRowIndex, lastRowNum)); } final int startRowIndex = Math.max(this.startRowIndex, firstRowNum);// 读取起始行(包含) final int endRowIndex = Math.min(this.endRowIndex, lastRowNum);// 读取结束行(包含) diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java index b50218aac..f88e2e236 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java @@ -251,4 +251,21 @@ public class ExcelReadTest { final ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("read_row_npe.xlsx")); reader.readColumn(0, 1); } + + @Test + public void readIssueTest() { + //https://gitee.com/dromara/hutool/issues/I5OSFC + final ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("read.xlsx")); + final List> read = reader.read(1,2,2); + for (Map map : read) { + Console.log(map); + } + //超出lastIndex 抛出相应提示:startRowIndex row index 4 is greater than last row index 2. + //而非:Illegal Capacity: -1 + try { + final List> readGreaterIndex = reader.read(1,4,4); + } catch (Exception e) { + Console.log(e.toString()); + } + } } diff --git a/hutool-poi/src/test/resources/read.xlsx b/hutool-poi/src/test/resources/read.xlsx new file mode 100644 index 000000000..10eda0923 Binary files /dev/null and b/hutool-poi/src/test/resources/read.xlsx differ