public class CalendarTest {
@Test
public void testCalender() {
new MockCalendar(1,2,3);
Calendar c = Calendar.getInstance();
int day = c.get(Calendar.HOUR_OF_DAY);
Assert.assertEquals(day, 2);
}
public static class MockCalendar extends MockUp<Calendar> {
private int hour;
private int minute;
private int day;
public MockCalendar(int day, int hour, int minute) {
this.hour = hour;
this.minute = minute;
this.day = day;
}
@Mock
protected void $init() {}
@Mock
public static Calendar getInstance() {
return new GregorianCalendar(1970,1,1);
}
@Mock
public int get(int id) {
if (id == Calendar.HOUR_OF_DAY) {
return hour;
}
if (id == Calendar.DAY_OF_WEEK) {
return day;
}
if (id == Calendar.MINUTE) {
return minute;
}
return -1;
}
}
}
}
you can enhance the get logic to do stuff.