@Override protected ValueOption<?> newObject() { return new DateOption(); }
/** * test for initial state. */ @Test public void init() { DateOption option = new DateOption(); assertThat(option.isNull(), is(true)); }
/** * test for date values. * @throws Exception if failed */ @Test public void date_values_direct() throws Exception { dateFormat = "yyyyMMdd"; assertRestorable(new DateOption(new Date(2011, 3, 31))); assertRestorable(new DateOption(new Date(1971, 4, 1))); assertRestorable(new DateOption()); }
/** * test for compare w/ null. */ @Test public void compareNull() { DateOption a = new DateOption(); DateOption b = new DateOption(); DateOption c = new DateOption(); a.modify(date(0)); assertThat(compare(a, b), greaterThan(0)); assertThat(compare(b, a), lessThan(0)); assertThat(compare(b, c), is(0)); }
/** * test for set elapsed days. */ @Test public void setInt() { DateOption option = new DateOption(); option.modify(500); assertThat(option.isNull(), is(false)); assertThat(option.get().getElapsedDays(), is(500)); }
/** * parse - invalid. */ @Test public void parse_invalid() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder().build(); checkMalformed(adapter, "Hello, world!", new DateOption()); }
/** * emit - null. */ @Test public void emit_null() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder().build(); checkEmit(adapter, new DateOption(), null); }
/** * parse - empty. */ @Test public void parse_empty() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder().build(); checkMalformed(adapter, "", new DateOption()); }
/** * emit. */ @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 for date type. */ @Test public void string() { DateOption option = new DateOption(); option.modify(date(999)); assertThat(option.isNull(), is(false)); assertThat(option.get(), is(date(999))); }
/** * parse w/ custom format - direct. */ @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))); }
/** * parse w/ custom format - default. */ @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 for Writable w/ 0. */ @Test public void writable_zero() { DateOption option = new DateOption(); option.modify(date(0)); DateOption restored = restore(option); assertThat(option.get(), is(restored.get())); }
/** * date placeholder. * @throws Exception if failed */ @Test public void placeholder_date_null() throws Exception { Mock mock = new Mock(spec(DATE, "yyyy/MM/dd")); mock.setMock(new DateOption()); mock.apply(); // no error }
/** * test for Writable w/ max value. */ @Test public void writable_max() { DateOption option = new DateOption(); option.modify(date(Integer.MAX_VALUE)); DateOption restored = restore(option); assertThat(option.get(), is(restored.get())); }
/** * parse - null. */ @Test public void parse_null() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder() .withNullFormat("") .build(); checkParse(adapter, "", new DateOption()); }
/** * emit - null w/ format. */ @Test public void emit_null_format() { DateOptionFieldAdapter adapter = DateOptionFieldAdapter.builder() .withNullFormat("") .build(); checkEmit(adapter, new DateOption(), ""); }
/** * test for Writable. */ @Test public void writable() { DateOption option = new DateOption(); option.modify(date(100)); DateOption restored = restore(option); assertThat(option.get(), is(restored.get())); }
/** * date placeholder. * @throws Exception if failed */ @Test public void placeholder_date() throws Exception { Mock mock = new Mock(spec(DATE, "yyyy/MM/dd")); mock.setMock(new DateOption(new Date(2012, 2, 3))); assertThat(mock.apply(), is("2012/02/03")); }
/** * test for or w/ date type. */ @Test public void stringOr() { DateOption option = new DateOption(); assertThat(option.or(date(200)), is(date(200))); assertThat(option.isNull(), is(true)); option.modify(date(300)); assertThat(option.or(date(400)), is(date(300))); }