@Test public void startStopTimeEntry() throws Exception { TimeEntry current = jToggl.getCurrentTimeEntry(); Assert.assertNull(current); TimeEntry timeEntry = new TimeEntry(); timeEntry.setWorkspace(workspace); timeEntry.setProject(project); timeEntry.setDescription("ABCD"); timeEntry.setCreated_with("JToggl Unit Test"); TimeEntry te = jToggl.startTimeEntry(timeEntry); try { Assert.assertNotNull(te.getId()); // created Assert.assertTrue(te.getDuration() < 0); // running current = jToggl.getCurrentTimeEntry(); Assert.assertNotNull(current); Assert.assertEquals(current.getId(), te.getId()); Thread.sleep(2000); TimeEntry stoppedTe = jToggl.stopTimeEntry(te); Assert.assertEquals(te.getId(), stoppedTe.getId()); Assert.assertTrue(stoppedTe.toJSONString(), stoppedTe.getDuration() > 1); // stopped current = jToggl.getCurrentTimeEntry(); Assert.assertNull(current); } finally { jToggl.destroyTimeEntry(te.getId()); } }
private static TimeEntry createTimeEntry() throws Exception { TimeEntry entry = new TimeEntry(); entry.setDuration(480); entry.setBillable(true); ZoneId tz = TimeZone.getTimeZone("Europe/Moscow").toZoneId(); ZonedDateTime start = ZonedDateTime.of(2011, 10, 15, 8, 0, 0, 0, tz); entry.setStart(start); ZonedDateTime stop = ZonedDateTime.of(2011, 10, 15, 16, 0, 0, 0, tz); entry.setStop(stop); entry.setDescription("From JUnit Test"); entry.setCreated_with("JUnit"); entry = jToggl.createTimeEntry(entry); Assert.assertNotNull(entry); return entry; }