add unit test of TodoItem

This commit is contained in:
hlq07 2018-05-09 23:53:08 +08:00
parent e4ea3fbb02
commit 5c7b8f6c05
1 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,62 @@
package org.cutem.cutecalendar.model;
import org.cutem.cutecalendar.util.CalendarUtil;
import org.junit.Test;
import java.util.Calendar;
import static org.junit.Assert.*;
public class TodoItemTest {
@Test
public void testConstruction() {
Calendar cal = CalendarUtil.roundToMinute(Calendar.getInstance());
long id = 1;
String title = "hello";
Calendar[] whole = CalendarUtil.getWholeDayPeriod(cal);
int type = TodoItem.OTHERS;
new TodoItem(id, title, whole[0], whole[1], type);
boolean ok = false;
cal = whole[0];
whole[0] = whole[1];
whole[1] = cal;
try {
new TodoItem(id, title, whole[0], whole[1], type);
} catch (IllegalArgumentException e) {
ok = true;
}
assertTrue(ok);
}
@Test
public void equalsAndHashCode() {
Calendar cal = CalendarUtil.roundToMinute(Calendar.getInstance());
String title = "hello";
Calendar[] whole = CalendarUtil.getWholeDayPeriod(cal);
int type = TodoItem.OTHERS;
TodoItem item1 = new TodoItem(1L, title, whole[0], whole[1], type);
TodoItem item2 = new TodoItem(2L, title, whole[0], whole[1], type);
TodoItem item3 = new TodoItem(1L, title, whole[0], whole[1], type);
Object item4 = new Object();
assertNotEquals(item1, item2);
assertEquals(item1, item3);
assertNotEquals(item1, item4);
System.out.println(item1.hashCode());
System.out.println(item2.hashCode());
System.out.println(item3.hashCode());
System.out.println(item4.hashCode());
assertNotEquals(item1.hashCode(), item2.hashCode());
assertEquals(item1.hashCode(), item3.hashCode());
assertNotEquals(item1.hashCode(), item4.hashCode());
}
}