怎么用Junit写这个断言

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


慕运维3810164
浏览 2783回答 2
2回答

慕桂英9052184

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)); }}这是我写的。

botao555

慕课网有Junit的课程,你看下吧http://www.imooc.com/learn/356
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
测试