@Test public void shouldTrimAndParseFieldsWithSpaces() throws Exception { String orderNumberWithSpaces = " 11 "; String productCodeWithSpaces = " P111 "; String replacedProductCodeWithSpaces = " P151 "; String quantityShippedWithSpaces = " 22 "; String costWithSpaces = "21 "; String packedDateWithSpaces = " 10/10/2013 "; String shippedDateWithSpaces = "10/12/2013"; ShipmentLineItemDTO dto = new ShipmentLineItemDTO(orderNumberWithSpaces, productCodeWithSpaces, replacedProductCodeWithSpaces, quantityShippedWithSpaces, costWithSpaces, packedDateWithSpaces, shippedDateWithSpaces); ShipmentLineItem lineItem = new ShipmentLineItemTransformer().transform(dto, "MM/dd/yyyy", "MM/dd/yyyy", new Date()); assertThat(lineItem.getProductCode(), is("P111")); assertThat(lineItem.getQuantityShipped(), is(22)); assertThat(lineItem.getOrderId(), is(11L)); assertThat(lineItem.getPackedDate().toString(), is("Thu Oct 10 00:00:00 IST 2013")); assertThat(lineItem.getShippedDate().toString(), is("Sat Oct 12 00:00:00 IST 2013")); assertThat(lineItem.getCost().toString(), is("21")); assertThat(lineItem.getReplacedProductCode(), is("P151")); }
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);  }