public void testSpentTime() { String str = "TEST1"; Date earlyDate = new Date(111, 1, 1); Date lateDate = new Date(111, 1, 2); // 正常系 Work work = new Work(1, str, earlyDate, lateDate); assertTrue(work.getSpentTime() == 1 * 24 * 60 * 60 * 1000); Date earlyDate2 = new Date(111, 1, 0); Date lateDate2 = new Date(111, 1, 10); work = new Work(1, str, earlyDate2, lateDate2); assertTrue(work.getSpentTime() == 10 * 24 * 60 * 60 * 1000); }
public void testConstructor() { String str = "TEST1"; Date earlyDate = new Date(111, 1, 1); Date lateDate = new Date(111, 1, 2); long msecOfDay = 24 * 60 * 60 * 1000; // 正常系(String, Date, Date) Work work = new Work(str, earlyDate, lateDate); assertTrue(work.getWorkNo() == Work.INVALID_NO); assertTrue(work.getName() == str); assertTrue(work.getStartDate() == earlyDate); assertTrue(work.getEndDate() == lateDate); assertTrue(work.getSpentTime() == msecOfDay); // 異常系(String, Date, Date) try { work = new Work(null, earlyDate, lateDate); assertTrue(false); } catch (NullPointerException e) { } try { work = new Work(str, null, lateDate); assertTrue(false); } catch (NullPointerException e) { } try { work = new Work(str, lateDate, null); assertTrue(false); } catch (NullPointerException e) { } try { work = new Work(str, lateDate, earlyDate); assertTrue(false); } catch (IllegalArgumentException e) { } try { work = new Work(str, earlyDate, earlyDate); assertTrue(false); } catch (IllegalArgumentException e) { } // 正常系(int, String, Date, Date) work = new Work(1, str, earlyDate, lateDate); assertTrue(work.getWorkNo() == 1); assertTrue(work.getName() == str); assertTrue(work.getStartDate() == earlyDate); assertTrue(work.getEndDate() == lateDate); assertTrue(work.getSpentTime() == msecOfDay); work = new Work(Integer.MAX_VALUE, str, earlyDate, lateDate); assertTrue(work.getWorkNo() == Integer.MAX_VALUE); assertTrue(work.getName() == str); assertTrue(work.getStartDate() == earlyDate); assertTrue(work.getEndDate() == lateDate); assertTrue(work.getSpentTime() == msecOfDay); work = new Work(-1, str, earlyDate, lateDate); assertTrue(work.getWorkNo() == -1); assertTrue(work.getName() == str); assertTrue(work.getStartDate() == earlyDate); assertTrue(work.getEndDate() == lateDate); assertTrue(work.getSpentTime() == msecOfDay); work = new Work(Integer.MIN_VALUE, str, earlyDate, lateDate); assertTrue(work.getWorkNo() == Integer.MIN_VALUE); assertTrue(work.getName() == str); assertTrue(work.getStartDate() == earlyDate); assertTrue(work.getEndDate() == lateDate); assertTrue(work.getSpentTime() == msecOfDay); // 異常系(int, String, Date, Date) try { work = new Work(1, null, earlyDate, lateDate); assertTrue(false); } catch (NullPointerException e) { } try { work = new Work(1, str, null, lateDate); assertTrue(false); } catch (NullPointerException e) { } try { work = new Work(1, str, lateDate, null); assertTrue(false); } catch (NullPointerException e) { } try { work = new Work(1, str, lateDate, earlyDate); assertTrue(false); } catch (IllegalArgumentException e) { } try { work = new Work(1, str, earlyDate, earlyDate); assertTrue(false); } catch (IllegalArgumentException e) { } }