日期:2014-05-20 浏览次数:20876 次
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 String getDate(){ return m.getMonth() + "/" + d.getDay() + "/" + y.getYear(); } }
import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.Collection; import nextdate.Date; import org.junit.Test; import org.junit.runner.JUnitCore; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class DateTest { private static String expected; private static int target; /** * 构造函数 * @param expected * 期望的测试结果,对应参数集中的第一个参数 * @param target * 测试数据,对应参数集中的第二个参数 */ public DateTest(String expected, int target) { this.expected = expected; this.target = target; } @Parameters public static Collection dates() { //问题就在这个静态方法,里边调用外部类,去static Date date0 = new Date(6, 15, 2000); //又不行,该怎么修改??? Date date1 = new Date(2, 29, 2000); Date date2 = new Date(2, 28, 2001); Date date3 = new Date(3, 30, 2000); Date date4 = new Date(4, 30, 2000); date0.increment(); date1.increment(); date2.increment(); date3.increment(); date4.increment(); return Arrays.asList(new Object[][] { { "6/16/2000", date0.getDate()}, { "3/1/2000", date1.getDate() }, { "2/29/2000", date2.getDate() }, { "3/31/2000", date3.getDate() }, { "5/1/2000", date4.getDate()}, }); } @Test public void increment() { assertEquals(expected,target); } public static void main(String[] args) { JUnitCore.main(new String[] { "DateTest" }); } }