为了账号安全,请及时绑定邮箱和手机立即绑定

怎么用Junit写这个断言

怎么用Junit写这个断言

慕运维3810164 2017-05-10 10:19:42
public class Nextday {            //第一个 public static Date nextDay(Date d) {     Date dd = new Date(d.getMonth().getCurrentPos(), d.getDay().getCurrentPos(), d.getYear().getCurrentPos());         dd.increment();         return dd;     } } public class Date {  // 第二个 private Day d; private Month m; private Year y; public Date(int pMonth, int pDay, int pYear) { y = new Year(pYear); m = new Month(pMonth, y); d = new Day(pDay, m); } public void increment() { if (!d.increment()) { if (!m.increment()) { y.increment(); m.setMonth(1, y); } d.setDay(1, m); } } public void printDate() { System.out.println(m.getMonth() + "/" + d.getDay() + "/" + y.getYear()); } public Day getDay() { return d; } public Month getMonth() { return m; } public Year getYear() { return y; } public boolean equals(Object o) { if (o instanceof Date) { if (this.y.equals(((Date) o).y) && this.m.equals(((Date) o).m) && this.d.equals(((Date) o).d)) return true; } return false; } public String toString() { return (m.getMonth() + "/" + d.getDay() + "/" + y.getYear()); } }
查看完整描述

2 回答

?
慕桂英9052184

TA贡献1条经验 获得超0个赞

package net.mooctest;

import static org.junit.Assert.*;

import org.junit.Test;

public class NextdayTest {

 @Test
 public void test() {
  Nextday n = new Nextday();
        Date d = new Date(2,28,2008);
        Date expectedDate = new Date(2,29,2008);
        assertEquals(expectedDate,n.nextDay(d));
 }

}

这是我写的。

查看完整回答
反对 回复 2019-09-08
?
botao555

TA贡献48条经验 获得超46个赞

慕课网有Junit的课程,你看下吧

http://www.imooc.com/learn/356

查看完整回答
反对 回复 2017-05-11
  • 2 回答
  • 1 关注
  • 2771 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信