@Test public void shouldCreateLineItemWithAllMandatoryAndGivenOptionalFields() throws Exception { ShipmentLineItemDTO dto = dtoWithMandatoryFields(); dto.setCost("3333.33"); ShipmentLineItem lineItem = transformer.transform(dto, SIMPLE_DATE_FORMAT, SIMPLE_DATE_FORMAT, new Date()); assertThat(lineItem.getProductCode(), is("P123")); assertThat(lineItem.getQuantityShipped(), is(1234)); assertThat(lineItem.getOrderId(), is(111L)); assertThat(lineItem.getCost().toString(), is("3333.33")); dto = dtoWithMandatoryFields(); dto.setPackedDate("01/01/2011"); lineItem = transformer.transform(dto, SIMPLE_DATE_FORMAT, SIMPLE_DATE_FORMAT, new Date()); assertThat(lineItem.getPackedDate().toString(), is("Sat Jan 01 00:00:00 IST 2011")); dto = dtoWithMandatoryFields(); dto.setShippedDate("01/01/2012"); lineItem = transformer.transform(dto, SIMPLE_DATE_FORMAT, SIMPLE_DATE_FORMAT, new Date()); assertThat(lineItem.getShippedDate().toString(), is("Sun Jan 01 00:00:00 IST 2012")); }
public ShipmentLineItem transform(ShipmentLineItemDTO shipmentLineItemDTO, String packedDateFormat, String shippedDateFormat, Date creationDate) throws DataException { shipmentLineItemDTO.checkMandatoryFields(); ShipmentLineItem lineItem = new ShipmentLineItem(); try { setMandatoryFields(lineItem, shipmentLineItemDTO); setOptionalFields(lineItem, shipmentLineItemDTO, packedDateFormat, shippedDateFormat, creationDate); } catch (DataException e) { throw e; } catch (Exception e) { throw new DataException("wrong.data.type"); } return lineItem; }
ShipmentLineItemTransformer extends LineItemTransformer { public ShipmentLineItem transform(ShipmentLineItemDTO shipmentLineItemDTO, String packedDateFormat, String shippedDateFormat, Date creationDate) throws DataException { shipmentLineItemDTO.checkMandatoryFields(); ShipmentLineItem lineItem = new ShipmentLineItem(); try { setMandatoryFields(lineItem, shipmentLineItemDTO); setOptionalFields(lineItem, shipmentLineItemDTO, packedDateFormat, shippedDateFormat, creationDate); } catch (DataException e) { throw e; } catch (Exception e) { throw new DataException("wrong.data.type"); } return lineItem; } }
ShipmentLineItemTransformer extends LineItemTransformer { public ShipmentLineItem transform(ShipmentLineItemDTO shipmentLineItemDTO, String packedDateFormat, String shippedDateFormat, Date creationDate) throws DataException { shipmentLineItemDTO.checkMandatoryFields(); ShipmentLineItem lineItem = new ShipmentLineItem(); try { setMandatoryFields(lineItem, shipmentLineItemDTO); setOptionalFields(lineItem, shipmentLineItemDTO, packedDateFormat, shippedDateFormat, creationDate); } catch (DataException e) { throw e; } catch (Exception e) { throw new DataException("wrong.data.type"); } return lineItem; }  }
ShipmentLineItemTransformer extends LineItemTransformer { public ShipmentLineItem transform(ShipmentLineItemDTO shipmentLineItemDTO, String packedDateFormat, String shippedDateFormat, Date creationDate) throws DataException { shipmentLineItemDTO.checkMandatoryFields(); ShipmentLineItem lineItem = new ShipmentLineItem(); try { setMandatoryFields(lineItem, shipmentLineItemDTO); setOptionalFields(lineItem, shipmentLineItemDTO, packedDateFormat, shippedDateFormat, creationDate); } catch (DataException e) { throw e; } catch (Exception e) { throw new DataException("wrong.data.type"); } return lineItem; }  ShipmentLineItem transform(ShipmentLineItemDTO shipmentLineItemDTO,
                                    String packedDateFormat,
                                    String shippedDateFormat,
                                    Date creationDate); }
ShipmentLineItemTransformer extends LineItemTransformer { public ShipmentLineItem transform(ShipmentLineItemDTO shipmentLineItemDTO, String packedDateFormat, String shippedDateFormat, Date creationDate) throws DataException { shipmentLineItemDTO.checkMandatoryFields(); ShipmentLineItem lineItem = new ShipmentLineItem(); try { setMandatoryFields(lineItem, shipmentLineItemDTO); setOptionalFields(lineItem, shipmentLineItemDTO, packedDateFormat, shippedDateFormat, creationDate); } catch (DataException e) { throw e; } catch (Exception e) { throw new DataException("wrong.data.type"); } return lineItem; }  ShipmentLineItem transform(ShipmentLineItemDTO shipmentLineItemDTO,
                                    String packedDateFormat,
                                    String shippedDateFormat,
                                    Date creationDate);  }