@Test
public void testUpdateExistingTimesheet() throws JSONException {

	getResults
			.put("ts_sebastian_2014_07",
					"{\"_id\":\"ts_sebastian_2014_07\",\"_rev\":\"2-1983e046a14377c433c08711fbb57b28\", \"other\": 88,\"entries\":[{\"dayInMonth\":1,\"project\":\"P1\",\"hours\":\"2:31\"},{\"dayInMonth\":2,\"project\":\"P1\",\"hours\":\"1:11\"},{\"dayInMonth\":2,\"project\":\"P2\",\"hours\":\"2:22\"},{\"dayInMonth\":2,\"project\":\"P2\",\"hours\":\"3:33\"},{\"dayInMonth\":14,\"project\":\"P1\",\"hours\":\"1:00\"}]}");
	putResults.put("ts_sebastian_2014_07", "{\"ok\": true, \"id\": \"ts_sebastian_2014_07\", \"rev\": \"3-123456789\"}");
	TimesheetCouch ts = new TimesheetCouch("ts_sebastian_2014_07", "2-1983e046a14377c433c08711fbb57b28");
	// add some test data in that order
	{
		TimesheetDay emptyDay = new TimesheetDay();
		emptyDay.setDay(2);
		ts.addDay(emptyDay);
	}
	{
		TimesheetDay dayWithOne = new TimesheetDay();
		dayWithOne.setDay(3);
		{
			TimesheetDayEntry normalEntry = new TimesheetDayEntry();
			normalEntry.setProject(new Project("bla"));
			normalEntry.setHours("1:30");
			dayWithOne.addEntry(normalEntry);
		}
		ts.addDay(dayWithOne);
	}
	{
		TimesheetDay dayWithSeveral = new TimesheetDay();
		dayWithSeveral.setDay(14);
		{
			TimesheetDayEntry oneMinuteEntry = new TimesheetDayEntry();
			oneMinuteEntry.setProject(new Project("bla"));
			oneMinuteEntry.setHours("00:01");
			dayWithSeveral.addEntry(oneMinuteEntry);
		}
		{
			TimesheetDayEntry oneHourEntry = new TimesheetDayEntry();
			oneHourEntry.setProject(new Project("blup"));
			oneHourEntry.setHours("01:00");
			dayWithSeveral.addEntry(oneHourEntry);
		}
		{
			TimesheetDayEntry noProjectEntry = new TimesheetDayEntry();
			noProjectEntry.setProject(null);
			noProjectEntry.setHours("01:00");
			dayWithSeveral.addEntry(noProjectEntry);
		}
		{
			TimesheetDayEntry noTimeEntry = new TimesheetDayEntry();
			noTimeEntry.setProject(new Project("blup"));
			noTimeEntry.setHours(null);
			dayWithSeveral.addEntry(noTimeEntry);
		}
		{
			TimesheetDayEntry zeroTimeEntry = new TimesheetDayEntry();
			zeroTimeEntry.setProject(new Project("blup"));
			zeroTimeEntry.setHours("0:00");
			dayWithSeveral.addEntry(zeroTimeEntry);
		}
		ts.addDay(dayWithSeveral);
	}
	Timesheet res = timesheetService.updateExistingTimesheet(ts, context);
	assertEquals(1, getUrls.size());
	assertEquals(1, putUrls.size());
	assertEquals(1, putContents.size());
	assertEquals(TimesheetCouch.class, res.getClass());
	assertEquals("ts_sebastian_2014_07", ((TimesheetCouch) res).getCouchId());
	assertEquals("3-123456789", ((TimesheetCouch) res).getCouchRev());
	// validate what is in the data sent:
	JSONObject sentObj = new JSONObject(putContents.get(0));
	assertEquals("ts_sebastian_2014_07", sentObj.getString("_id"));
	assertEquals("2-1983e046a14377c433c08711fbb57b28", sentObj.getString("_rev"));
	assertEquals(88, sentObj.getInt("other"));
	JSONArray sentEntries = sentObj.getJSONArray("entries");
	assertNotNull(sentEntries);
	assertEquals(3, sentEntries.length());
	assertEquals(3, sentEntries.getJSONObject(0).getInt("dayInMonth"));
	assertEquals("bla", sentEntries.getJSONObject(0).getString("project"));
	assertEquals("1:30", sentEntries.getJSONObject(0).getString("hours"));
	assertEquals(14, sentEntries.getJSONObject(1).getInt("dayInMonth"));
	assertEquals("bla", sentEntries.getJSONObject(1).getString("project"));
	assertEquals("00:01", sentEntries.getJSONObject(1).getString("hours"));
	assertEquals(14, sentEntries.getJSONObject(2).getInt("dayInMonth"));
	assertEquals("blup", sentEntries.getJSONObject(2).getString("project"));
	assertEquals("01:00", sentEntries.getJSONObject(2).getString("hours"));
}