!780 修复Issue #I5OSFC(更友好提示),完善Zodiac单元测试

Merge pull request !780 from Husky/v6-dev
This commit is contained in:
Looly 2022-08-30 13:48:16 +00:00 committed by Gitee
commit 26d550dbab
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 67 additions and 1 deletions

View File

@ -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());
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -44,7 +44,9 @@ public class MapSheetReader extends AbstractSheetReader<List<Map<String, Object>
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);// 读取结束行包含

View File

@ -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<Map<String, Object>> read = reader.read(1,2,2);
for (Map<String, Object> map : read) {
Console.log(map);
}
//超出lastIndex 抛出相应提示startRowIndex row index 4 is greater than last row index 2.
//而非:Illegal Capacity: -1
try {
final List<Map<String, Object>> readGreaterIndex = reader.read(1,4,4);
} catch (Exception e) {
Console.log(e.toString());
}
}
}

Binary file not shown.