### Question:
DateOptionFieldAdapter extends ValueOptionFieldAdapter<DateOption> { public static Builder builder() { return new Builder(); } DateOptionFieldAdapter(String nullFormat, String dateFormat); static Builder builder(); static final String DEFAULT_FORMAT; }### Answer:
@Test public void parse() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder().build(); checkParse(adapter, "2016-12-31", new DateOption(new Date(2016, 12, 31))); checkParse(adapter, "2017-01-01", new DateOption(new Date(2017, 1, 1))); checkParse(adapter, "2017-01-02", new DateOption(new Date(2017, 1, 2))); }
@Test public void parse_empty() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder().build(); checkMalformed(adapter, "", new DateOption()); }
@Test public void parse_invalid() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder().build(); checkMalformed(adapter, "Hello, world!", new DateOption()); }
@Test public void parse_null() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder() .withNullFormat("") .build(); checkParse(adapter, "", new DateOption()); }
@Test public void emit() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder().build(); checkEmit(adapter, new DateOption(new Date(2016, 12, 31)), "2016-12-31"); checkEmit(adapter, new DateOption(new Date(2017, 1, 1)), "2017-01-01"); checkEmit(adapter, new DateOption(new Date(2017, 1, 2)), "2017-01-02"); }
@Test public void emit_null() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder().build(); checkEmit(adapter, new DateOption(), null); }
@Test public void emit_null_format() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder() .withNullFormat("") .build(); checkEmit(adapter, new DateOption(), ""); }
@Test public void parse_format_default() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder() .withDateFormat("yyyy'x'MM'x'dd") .build(); equivalent(adapter, "2016x12x31", new DateOption(new Date(2016, 12, 31))); equivalent(adapter, "2017x01x01", new DateOption(new Date(2017, 1, 1))); equivalent(adapter, "2017x01x02", new DateOption(new Date(2017, 1, 2))); }
@Test public void parse_format_direct() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder() .withDateFormat("yyyyMMdd") .build(); equivalent(adapter, "20161231", new DateOption(new Date(2016, 12, 31))); equivalent(adapter, "20170101", new DateOption(new Date(2017, 1, 1))); equivalent(adapter, "20170102", new DateOption(new Date(2017, 1, 2))); }
@Test public void parse_format_custom() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder() .withDateFormat("yyyy -- MM -- dd") .build(); equivalent(adapter, "2016 -- 12 -- 31", new DateOption(new Date(2016, 12, 31))); equivalent(adapter, "2017 -- 01 -- 01", new DateOption(new Date(2017, 1, 1))); equivalent(adapter, "2017 -- 01 -- 02", new DateOption(new Date(2017, 1, 2))); }