use of org.motechproject.commons.date.model.Time in project motech by motech.
the class InstanceServiceTest method testUpdateCreate.
private void testUpdateCreate(boolean edit) throws ClassNotFoundException {
final DateTime dtValue = DateUtil.now();
mockSampleFields();
mockDataService();
mockEntity();
when(motechDataService.retrieve("id", INSTANCE_ID)).thenReturn(new TestSample());
List<FieldRecord> fieldRecords = asList(FieldTestHelper.fieldRecord("strField", String.class.getName(), "", "this is a test"), FieldTestHelper.fieldRecord("intField", Integer.class.getName(), "", 16), FieldTestHelper.fieldRecord("timeField", Time.class.getName(), "", "10:17"), FieldTestHelper.fieldRecord("dtField", DateTime.class.getName(), "", dtValue));
Long id = (edit) ? INSTANCE_ID : null;
EntityRecord record = new EntityRecord(id, ENTITY_ID, fieldRecords);
MDSClassLoader.getInstance().loadClass(TestSample.class.getName());
instanceService.saveInstance(record);
ArgumentCaptor<TestSample> captor = ArgumentCaptor.forClass(TestSample.class);
if (edit) {
verify(motechDataService).update(captor.capture());
} else {
verify(motechDataService).create(captor.capture());
}
TestSample sample = captor.getValue();
assertEquals("this is a test", sample.getStrField());
assertEquals(Integer.valueOf(16), sample.getIntField());
assertEquals(new Time(10, 17), sample.getTimeField());
assertEquals(dtValue, sample.getDtField());
}
Aggregations