/** * test for decimal values. * @throws Exception if failed */ @Test public void decimal_values_quote() throws Exception { quote.add(0); assertRestorable(new DecimalOption(decimal("0"))); assertRestorable(new DecimalOption(decimal("-100"))); assertRestorable(new DecimalOption(decimal("1"))); assertRestorable(new DecimalOption(decimal("-1"))); }
/** * emit - scientific. */ @Test public void emit_default_style() { DecimalOptionFieldAdapter adapter = DecimalOptionFieldAdapter.builder().build(); checkEmit(adapter, new DecimalOption(new BigDecimal(BigInteger.valueOf(12), -10)), "1.2E+11"); }
/** * test for initial state. */ @Test public void init() { DecimalOption option = new DecimalOption(); assertThat(option.isNull(), is(true)); }
/** * emit - plain. */ @Test public void emit_plain() { DecimalOptionFieldAdapter adapter = DecimalOptionFieldAdapter.builder() .withOutputStyle(OutputStyle.PLAIN) .build(); checkEmit(adapter, new DecimalOption(new BigDecimal(BigInteger.valueOf(12), -10)), "120000000000"); }
/** * emit - engineering. */ @Test public void emit_engineering() { DecimalOptionFieldAdapter adapter = DecimalOptionFieldAdapter.builder() .withOutputStyle(OutputStyle.ENGINEERING) .build(); checkEmit(adapter, new DecimalOption(new BigDecimal(BigInteger.valueOf(12), -10)), "120E+9"); }
/** * test for Writable w/ null. */ @Test public void writeNull() { DecimalOption option = new DecimalOption(); DecimalOption restored = restore(option); assertThat(restored.isNull(), is(true)); }
/** * emit. */ @Test public void emit() { DecimalOptionFieldAdapter adapter = DecimalOptionFieldAdapter.builder().build(); checkEmit(adapter, new DecimalOption(d("0")), "0"); checkEmit(adapter, new DecimalOption(d("12345.67890")), "12345.67890"); }
/** * parse. */ @Test public void parse() { DecimalOptionFieldAdapter adapter = DecimalOptionFieldAdapter.builder().build(); checkParse(adapter, 0, new DecimalOption(d("0"))); checkParse(adapter, "12345.67890", new DecimalOption(d("12345.67890"))); }
/** * decimal placeholder. * @throws Exception if failed */ @Test public void placeholder_decimal() throws Exception { Mock mock = new Mock(spec(DECIMAL, "0000")); mock.setMock(new DecimalOption(BigDecimal.valueOf(1))); assertThat(mock.apply(), is("0001")); }
/** * parse - malformed. */ @Test public void parse_malform() { DecimalOptionFieldAdapter adapter = DecimalOptionFieldAdapter.builder().build(); checkMalformed(adapter, "Hello, world!", new DecimalOption()); }
/** * emit - null. */ @Test public void emit_null() { DecimalOptionFieldAdapter adapter = DecimalOptionFieldAdapter.builder().build(); checkEmit(adapter, new DecimalOption(), null); }
/** * parse - empty. */ @Test public void parse_empty() { DecimalOptionFieldAdapter adapter = DecimalOptionFieldAdapter.builder().build(); checkMalformed(adapter, "", new DecimalOption()); }
/** * test for or w/ null. */ @Test public void or() { DecimalOption option = new DecimalOption(); assertThat(option.or(decimal(30)), is(decimal(30))); assertThat(option.isNull(), is(true)); }
/** * test for Writable w/ max. */ @Test public void write_max() { DecimalOption option = new DecimalOption(); option.modify(decimal(Long.MAX_VALUE).add(decimal(Long.MAX_VALUE))); DecimalOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for Writable w/ min. */ @Test public void write_min() { DecimalOption option = new DecimalOption(); option.modify(decimal(Long.MIN_VALUE).add(decimal(Long.MAX_VALUE))); DecimalOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for get. */ @Test public void get() { DecimalOption option = new DecimalOption(); option.modify(decimal(100)); assertThat(option.get(), is(decimal(100))); assertThat(option.isNull(), is(false)); }
/** * emit - null. */ @Test public void emit_null_formatted() { DecimalOptionFieldAdapter adapter = DecimalOptionFieldAdapter.builder() .withNullFormat("") .build(); checkEmit(adapter, new DecimalOption(), ""); }
/** * test for or w/ present value. */ @Test public void orNotNull() { DecimalOption option = new DecimalOption(); option.modify(decimal(100)); assertThat(option.or(decimal(30)), is(decimal(100))); }
/** * test for Writable. */ @Test public void write() { DecimalOption option = new DecimalOption(); option.modify(decimal("3.14")); DecimalOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * parse - empty. */ @Test public void parse_null() { DecimalOptionFieldAdapter adapter = DecimalOptionFieldAdapter.builder() .withNullFormat("") .build(); checkParse(adapter, "", new DecimalOption()); }