Add Calendar related tests (WIP)
This commit is contained in:
parent
bc4503c8bf
commit
fae116d1bd
|
@ -85,18 +85,18 @@ public class CalendarReceiver extends BroadcastReceiver {
|
||||||
public CalendarReceiver(GBDevice gbDevice) {
|
public CalendarReceiver(GBDevice gbDevice) {
|
||||||
LOG.info("Created calendar receiver.");
|
LOG.info("Created calendar receiver.");
|
||||||
mGBDevice = gbDevice;
|
mGBDevice = gbDevice;
|
||||||
syncCalendar();
|
onReceive(GBApplication.getContext(), new Intent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
LOG.info("got calendar changed broadcast");
|
LOG.info("got calendar changed broadcast");
|
||||||
syncCalendar();
|
List<CalendarEvents.CalendarEvent> eventList = (new CalendarEvents()).getCalendarEventList(GBApplication.getContext());
|
||||||
|
syncCalendar(eventList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void syncCalendar() {
|
public void syncCalendar(List<CalendarEvents.CalendarEvent> eventList) {
|
||||||
LOG.info("Syncing with calendar.");
|
LOG.info("Syncing with calendar.");
|
||||||
List<CalendarEvents.CalendarEvent> eventList = (new CalendarEvents()).getCalendarEventList(GBApplication.getContext());
|
|
||||||
Hashtable<Long, CalendarEvents.CalendarEvent> eventTable = new Hashtable<>();
|
Hashtable<Long, CalendarEvents.CalendarEvent> eventTable = new Hashtable<>();
|
||||||
|
|
||||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||||
|
|
|
@ -2,22 +2,53 @@ package nodomain.freeyourgadget.gadgetbridge.test;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.CalendarSyncStateDao;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.CalendarReceiver;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents;
|
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEvents;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
public class CalendarEventTest extends TestBase {
|
public class CalendarEventTest extends TestBase {
|
||||||
private static final long BEGIN = 1;
|
private static final long BEGIN = 1;
|
||||||
private static final long END = 2;
|
private static final long END = 2;
|
||||||
private static final long ID_1 = 100;
|
private static final long ID_1 = 100;
|
||||||
|
private static final long ID_2 = 101;
|
||||||
|
private static final String CALNAME_1 = "cal1";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHashCode() {
|
public void testHashCode() {
|
||||||
CalendarEvents.CalendarEvent c1 = new CalendarEvents.CalendarEvent(BEGIN, END, ID_1, "something", null, null, null, false);
|
CalendarEvents.CalendarEvent c1 = new CalendarEvents.CalendarEvent(BEGIN, END, ID_1, "something", null, null, CALNAME_1, false);
|
||||||
CalendarEvents.CalendarEvent c2 = new CalendarEvents.CalendarEvent(BEGIN, END, ID_1, "something", null, null, null, false);
|
CalendarEvents.CalendarEvent c2 = new CalendarEvents.CalendarEvent(BEGIN, END, ID_1, null, "something", null, CALNAME_1, false);
|
||||||
CalendarEvents.CalendarEvent c3 = new CalendarEvents.CalendarEvent(BEGIN, END, ID_1, "something", null, null, null, false);
|
CalendarEvents.CalendarEvent c3 = new CalendarEvents.CalendarEvent(BEGIN, END, ID_1, null, null, "something", CALNAME_1, false);
|
||||||
|
|
||||||
|
assertEquals(c1.hashCode(), c1.hashCode());
|
||||||
assertNotEquals(c1.hashCode(), c2.hashCode());
|
assertNotEquals(c1.hashCode(), c2.hashCode());
|
||||||
assertNotEquals(c2.hashCode(), c3.hashCode());
|
assertNotEquals(c2.hashCode(), c3.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSync() {
|
||||||
|
List<CalendarEvents.CalendarEvent> eventList = new ArrayList<>();
|
||||||
|
eventList.add(new CalendarEvents.CalendarEvent(BEGIN, END, ID_1, null, "something", null, CALNAME_1, false));
|
||||||
|
|
||||||
|
GBDevice dummyGBDevice = createDummyGDevice("00:00:01:00:03");
|
||||||
|
dummyGBDevice.setState(GBDevice.State.INITIALIZED);
|
||||||
|
// Device device = DBHelper.getDevice(dummyGBDevice, daoSession);
|
||||||
|
CalendarReceiver testCR = new CalendarReceiver(dummyGBDevice);
|
||||||
|
|
||||||
|
testCR.syncCalendar(eventList);
|
||||||
|
|
||||||
|
eventList.add(new CalendarEvents.CalendarEvent(BEGIN, END, ID_2, null, "something", null, CALNAME_1, false));
|
||||||
|
testCR.syncCalendar(eventList);
|
||||||
|
|
||||||
|
CalendarSyncStateDao calendarSyncStateDao = daoSession.getCalendarSyncStateDao();
|
||||||
|
assertEquals(2, calendarSyncStateDao.count());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue