@Test public void GetLatestServiceRunWhenTableIsEmpty() { ServiceRunProvider.ServiceRun latest = ServiceRunProvider.LatestRun(myDb); assertEquals("dummy id", 0, latest.getId()); assertEquals("received", 0, latest.getNumReceived()); assertEquals("triggered", 0, latest.getNumTriggered()); }
@Test public void TestRecordWhenStartStoppingTheService() { // ...when the service starts long id = ServiceRunProvider.InsertAtServiceStart(myDb); // end of service ServiceRunProvider.UpdateAtServiceStop(myDb, id, 2, 1); // service starts again id = ServiceRunProvider.InsertAtServiceStart(myDb); // 2nd end of service ServiceRunProvider.UpdateAtServiceStop(myDb, id, 3, 1); ServiceRunProvider.ServiceRun latest = ServiceRunProvider.LatestRun(myDb); // tests assertEquals("There should be two records", 2, latest.getId()); assertEquals("Total of 3 calls received", 3, latest.getNumReceived()); assertEquals("Total of 1 event triggered", 1, latest.getNumTriggered()); }
@Test public void GetLatestServiceRunWhenTableIsNotEmpty() { Calendar cal = Calendar.getInstance(Locale.getDefault()); Date start = cal.getTime(); cal.add(Calendar.HOUR, 1); Date end = cal.getTime(); ServiceRunProvider.InsertRow(myDb, new ServiceRunProvider.ServiceRun(-1, start, end, 2, 1)); cal.add(Calendar.HOUR, 1); start = cal.getTime(); cal.add(Calendar.HOUR, 1); end = cal.getTime(); ServiceRunProvider.InsertRow(myDb, new ServiceRunProvider.ServiceRun(-1, start, end, 4, 1)); ServiceRunProvider.ServiceRun latest = ServiceRunProvider.LatestRun(myDb); assertEquals("id", 2, latest.getId()); assertEquals("received", 4, latest.getNumReceived()); assertEquals("triggered", 1, latest.getNumTriggered()); }