@Test public void fromRaw() throws Exception { final CsvImpExColumn ldColumn = this.mockery.mock(CsvImpExColumn.class, "ldColumn"); final CsvImpExColumn ldtColumn = this.mockery.mock(CsvImpExColumn.class, "ldtColumn"); final CsvImpExTuple tuple = this.mockery.mock(CsvImpExTuple.class, "tuple"); final CsvDateValueAdapterImpl adapter = new CsvDateValueAdapterImpl(); this.mockery.checking(new Expectations() {{ oneOf(ldColumn).getContext(); will(returnValue("yyyy-MM-dd")); oneOf(ldtColumn).getContext(); will(returnValue("yyyy-MM-dd HH:mm:ss")); oneOf(ldColumn).getContext(); will(returnValue("yyyy-MM-dd")); oneOf(ldtColumn).getContext(); will(returnValue("yyyy-MM-dd HH:mm:ss")); }}); assertEquals( DateUtils.ldParseSDT("2017-06-06"), adapter.fromRaw("2017-06-06", "DATE", ldColumn, tuple) ); assertEquals( DateUtils.ldParseSDT("2017-06-06"), adapter.fromRaw("2017-06-06 15:30:17", "DATE", ldtColumn, tuple) ); assertEquals( DateUtils.ldtParseSDT("2017-06-06"), adapter.fromRaw("2017-06-06", "DATETIME", ldColumn, tuple) ); assertEquals( DateUtils.ldtParseSDT("2017-06-06 15:30:17"), adapter.fromRaw("2017-06-06 15:30:17", "DATETIME", ldtColumn, tuple) ); this.mockery.assertIsSatisfied(); }
@Override public Object fromRaw(final Object rawValue, final String requiredType, final CsvImpExColumn csvImpExColumn, final CsvImpExTuple tuple) { final String pattern = csvImpExColumn.getContext(); if (rawValue != null) { if (StringUtils.isNotBlank(pattern)) { return "DATE".equalsIgnoreCase(requiredType) ? DateUtils.ldParse((String) rawValue, pattern) : DateUtils.ldtParse((String) rawValue, pattern); } return "DATE".equalsIgnoreCase(requiredType) ? DateUtils.ldParse((String) rawValue, "yyyy-MM-dd") : DateUtils.ldtParse((String) rawValue, "yyyy-MM-dd HH:mm:ss"); } return null; }
CsvDateValueAdapterImpl implements CsvValueAdapter { @Override public Object fromRaw(final Object rawValue, final String requiredType, final CsvImpExColumn csvImpExColumn, final CsvImpExTuple tuple) { final String pattern = csvImpExColumn.getContext(); if (rawValue != null) { if (StringUtils.isNotBlank(pattern)) { return "DATE".equalsIgnoreCase(requiredType) ? DateUtils.ldParse((String) rawValue, pattern) : DateUtils.ldtParse((String) rawValue, pattern); } return "DATE".equalsIgnoreCase(requiredType) ? DateUtils.ldParse((String) rawValue, "yyyy-MM-dd") : DateUtils.ldtParse((String) rawValue, "yyyy-MM-dd HH:mm:ss"); } return null; } }
CsvDateValueAdapterImpl implements CsvValueAdapter { @Override public Object fromRaw(final Object rawValue, final String requiredType, final CsvImpExColumn csvImpExColumn, final CsvImpExTuple tuple) { final String pattern = csvImpExColumn.getContext(); if (rawValue != null) { if (StringUtils.isNotBlank(pattern)) { return "DATE".equalsIgnoreCase(requiredType) ? DateUtils.ldParse((String) rawValue, pattern) : DateUtils.ldtParse((String) rawValue, pattern); } return "DATE".equalsIgnoreCase(requiredType) ? DateUtils.ldParse((String) rawValue, "yyyy-MM-dd") : DateUtils.ldtParse((String) rawValue, "yyyy-MM-dd HH:mm:ss"); } return null; }  }
CsvDateValueAdapterImpl implements CsvValueAdapter { @Override public Object fromRaw(final Object rawValue, final String requiredType, final CsvImpExColumn csvImpExColumn, final CsvImpExTuple tuple) { final String pattern = csvImpExColumn.getContext(); if (rawValue != null) { if (StringUtils.isNotBlank(pattern)) { return "DATE".equalsIgnoreCase(requiredType) ? DateUtils.ldParse((String) rawValue, pattern) : DateUtils.ldtParse((String) rawValue, pattern); } return "DATE".equalsIgnoreCase(requiredType) ? DateUtils.ldParse((String) rawValue, "yyyy-MM-dd") : DateUtils.ldtParse((String) rawValue, "yyyy-MM-dd HH:mm:ss"); } return null; }  @Override Object fromRaw(final Object rawValue, final String requiredType, final CsvImpExColumn csvImpExColumn, final CsvImpExTuple tuple); }
CsvDateValueAdapterImpl implements CsvValueAdapter { @Override public Object fromRaw(final Object rawValue, final String requiredType, final CsvImpExColumn csvImpExColumn, final CsvImpExTuple tuple) { final String pattern = csvImpExColumn.getContext(); if (rawValue != null) { if (StringUtils.isNotBlank(pattern)) { return "DATE".equalsIgnoreCase(requiredType) ? DateUtils.ldParse((String) rawValue, pattern) : DateUtils.ldtParse((String) rawValue, pattern); } return "DATE".equalsIgnoreCase(requiredType) ? DateUtils.ldParse((String) rawValue, "yyyy-MM-dd") : DateUtils.ldtParse((String) rawValue, "yyyy-MM-dd HH:mm:ss"); } return null; }  @Override Object fromRaw(final Object rawValue, final String requiredType, final CsvImpExColumn csvImpExColumn, final CsvImpExTuple tuple);  }