@Override public void write(StoreInfo object) throws IOException { emitter.emit(object.getStoreCodeOption()); emitter.emit(object.getStoreNameOption()); emitter.endRecord(); } @Override
@Override public void write(CategorySummary object) throws IOException { emitter.emit(object.getCategoryCodeOption()); emitter.emit(object.getAmountTotalOption()); emitter.emit(object.getSellingPriceTotalOption()); emitter.endRecord(); } @Override
private void assertRestorable(ValueOption<?> option) { CsvConfiguration conf = createConfiguration(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try (CsvEmitter emitter = new CsvEmitter(buffer, testName.getMethodName(), conf)) { emit(emitter, option); emitter.endRecord(); emitter.close(); try (CsvParser parser = new CsvParser( new ByteArrayInputStream(buffer.toByteArray()), testName.getMethodName(), conf)) { assertThat(parser.next(), is(true)); ValueOption<?> copy = option.getClass().newInstance(); fill(parser, copy); parser.endRecord(); assertThat(parser.next(), is(false)); assertThat(copy, is((Object) option)); } } catch (Exception e) { throw new AssertionError(e); } }
@Override public void write(ErrorRecord object) throws IOException { emitter.emit(object.getFileNameOption()); emitter.emit(object.getSalesDateTimeOption()); emitter.emit(object.getStoreCodeOption()); emitter.emit(object.getItemCodeOption()); emitter.emit(object.getMessageOption()); emitter.endRecord(); } @Override
@Override public void write(SalesDetail object) throws IOException { emitter.emit(object.getSalesDateTimeOption()); emitter.emit(object.getStoreCodeOption()); emitter.emit(object.getItemCodeOption()); emitter.emit(object.getAmountOption()); emitter.emit(object.getUnitSellingPriceOption()); emitter.emit(object.getSellingPriceOption()); emitter.endRecord(); } @Override
/** * test for multiple records in file. * @throws Exception if failed */ @Test public void multi_records() throws Exception { try (CsvEmitter emitter = createEmitter()) { emitter.emit(new StringOption("a")); emitter.endRecord(); emitter.emit(new StringOption("b")); emitter.endRecord(); emitter.emit(new StringOption("c")); emitter.endRecord(); } try (CsvParser parser = createParser()) { assertThat(parser.next(), is(true)); assertThat(fill(parser, new StringOption()), is(new StringOption("a"))); parser.endRecord(); assertThat(parser.next(), is(true)); assertThat(fill(parser, new StringOption()), is(new StringOption("b"))); parser.endRecord(); assertThat(parser.next(), is(true)); assertThat(fill(parser, new StringOption()), is(new StringOption("c"))); parser.endRecord(); assertThat(parser.next(), is(false)); } }
/** * has malformed header. * @throws Exception if failed */ @Test public void with_malformed_header() throws Exception { headers = Arrays.asList("\"malformed,\r\nheader\"", ""); try (CsvEmitter emitter = createEmitter()) { emitter.emit(new StringOption("a")); emitter.emit(new StringOption("b")); emitter.endRecord(); } // directly read a header headers = Arrays.asList(); try (CsvParser parser = createParser()) { assertThat(parser.next(), is(true)); assertThat(fill(parser, new StringOption()), is(new StringOption("\"malformed,\r\nheader\""))); assertThat(fill(parser, new StringOption()), is(new StringOption())); parser.endRecord(); assertThat(parser.next(), is(true)); assertThat(fill(parser, new StringOption()), is(new StringOption("a"))); assertThat(fill(parser, new StringOption()), is(new StringOption("b"))); parser.endRecord(); assertThat(parser.next(), is(false)); } }
/** * has header. * @throws Exception if failed */ @Test public void with_header() throws Exception { headers = Arrays.asList("key", "value"); try (CsvEmitter emitter = createEmitter()) { emitter.emit(new StringOption("a")); emitter.emit(new StringOption("b")); emitter.endRecord(); } // directly read a header headers = Arrays.asList(); try (CsvParser parser = createParser()) { assertThat(parser.next(), is(true)); assertThat(fill(parser, new StringOption()), is(new StringOption("key"))); assertThat(fill(parser, new StringOption()), is(new StringOption("value"))); parser.endRecord(); assertThat(parser.next(), is(true)); assertThat(fill(parser, new StringOption()), is(new StringOption("a"))); assertThat(fill(parser, new StringOption()), is(new StringOption("b"))); parser.endRecord(); assertThat(parser.next(), is(false)); } }
/** * Simple stress test for {@link Date} type. * @throws Exception if failed */ @Test public void stress_date() throws Exception { int count = 5000000; try (CsvEmitter emitter = new CsvEmitter(new VoidOutputStream(), "testing", createConfiguration())) { DateOption value = new DateOption(new Date(1999, 12, 31)); for (int i = 0; i < count; i++) { emitter.emit(value); emitter.endRecord(); } } }
/** * Simple stress test for {@link DateTime} type. * @throws Exception if failed */ @Test public void stress_datetime() throws Exception { int count = 5000000; try (CsvEmitter emitter = new CsvEmitter(new VoidOutputStream(), "testing", createConfiguration())) { DateTimeOption value = new DateTimeOption(new DateTime(1999, 12, 31, 1, 23, 45)); for (int i = 0; i < count; i++) { emitter.emit(value); emitter.endRecord(); } } } }
@Override public void write(ItemInfo object) throws IOException { emitter.emit(object.getItemCodeOption()); emitter.emit(object.getItemNameOption()); emitter.emit(object.getDepartmentCodeOption()); emitter.emit(object.getDepartmentNameOption()); emitter.emit(object.getCategoryCodeOption()); emitter.emit(object.getCategoryNameOption()); emitter.emit(object.getUnitSellingPriceOption()); emitter.emit(object.getRegisteredDateOption()); emitter.emit(object.getBeginDateOption()); emitter.emit(object.getEndDateOption()); emitter.endRecord(); } @Override
/** * test for multiple cells in record. * @throws Exception if failed */ @Test public void multi_cells() throws Exception { try (CsvEmitter emitter = createEmitter()) { emitter.emit(new StringOption("a")); emitter.emit(new StringOption("b")); emitter.emit(new StringOption("c")); emitter.endRecord(); } try (CsvParser parser = createParser()) { assertThat(parser.next(), is(true)); assertThat(fill(parser, new StringOption()), is(new StringOption("a"))); assertThat(fill(parser, new StringOption()), is(new StringOption("b"))); assertThat(fill(parser, new StringOption()), is(new StringOption("c"))); parser.endRecord(); assertThat(parser.next(), is(false)); } }
emitter.emit(new StringOption("a-2")); emitter.emit(new StringOption("a-3")); emitter.endRecord(); emitter.emit(new StringOption("b-1")); emitter.emit(new StringOption("b-2")); emitter.emit(new StringOption("b-3")); emitter.endRecord(); emitter.emit(new StringOption("c-1")); emitter.emit(new StringOption("c-2")); emitter.emit(new StringOption("c-3")); emitter.endRecord();