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)) { if (rawValue instanceof Instant) { return DateUtils.format((Instant) rawValue, pattern); } else if (rawValue instanceof LocalDateTime) { return DateUtils.format((LocalDateTime) rawValue, pattern); } else if (rawValue instanceof LocalDate) { return DateUtils.format((LocalDate) rawValue, pattern); } else if (rawValue instanceof ZonedDateTime) { return DateUtils.format((ZonedDateTime) rawValue, pattern); } LOG.warn("Unsupported value {} of type {} is set for DATE converter", rawValue, rawValue.getClass()); } return rawValue.toString(); } return null; }  @Override Object fromRaw(final Object rawValue, final String requiredType, final CsvImpExColumn csvImpExColumn, final CsvImpExTuple tuple);  }
@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 CsvImpExColumn zdtColumn = this.mockery.mock(CsvImpExColumn.class, "zdtColumn"); final CsvImpExColumn iColumn = this.mockery.mock(CsvImpExColumn.class, "iColumn"); 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(zdtColumn).getContext(); will(returnValue("yyyy-MM-dd HH:mm:ss")); oneOf(iColumn).getContext(); will(returnValue("yyyy-MM-dd HH:mm:ss")); }}); assertEquals( "2017-06-06", adapter.fromRaw(DateUtils.ldParseSDT("2017-06-06"), "DATE", ldColumn, tuple) ); assertEquals( "2017-06-06 15:30:17", adapter.fromRaw(DateUtils.ldtParseSDT("2017-06-06 15:30:17"), "DATE", ldtColumn, tuple) ); assertEquals( "2017-06-06 15:30:17", adapter.fromRaw(DateUtils.zdtParseSDT("2017-06-06 15:30:17"), "DATE", zdtColumn, tuple) ); assertEquals( "2017-06-06 15:30:17", adapter.fromRaw(DateUtils.iParseSDT("2017-06-06 15:30:17"), "DATE", iColumn, tuple) ); this.mockery.assertIsSatisfied(); }