@Test
  public void shouldConfigureAsMap() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat().setFieldLengths(new int[] {1, 2, 3}).setAsMap(true);

    assertTrue(dataFormat.isAsMap());
  }
  @Test
  public void shouldConfigureFieldLengthWithLengthsOnly() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat().setFieldLengths(new int[] {1, 2, 3});

    assertArrayEquals(new int[] {1, 2, 3}, dataFormat.getFieldLengths());

    dataFormat.createAndConfigureWriterSettings();
  }
  @Test
  public void shouldConfigurePadding() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat().setFieldLengths(new int[] {1, 2, 3}).setPadding('p');

    assertEquals(Character.valueOf('p'), dataFormat.getPadding());
    assertEquals('p', dataFormat.createAndConfigureWriterSettings().getFormat().getPadding());
    assertEquals('p', dataFormat.createAndConfigureParserSettings().getFormat().getPadding());
  }
  @Test
  public void shouldConfigureRecordEndsOnNewline() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat()
            .setFieldLengths(new int[] {1, 2, 3})
            .setRecordEndsOnNewline(true);

    assertTrue(dataFormat.getRecordEndsOnNewline());
    assertTrue(dataFormat.createAndConfigureParserSettings().getRecordEndsOnNewline());
  }
  @Test
  public void shouldConfigureEmptyValue() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat()
            .setFieldLengths(new int[] {1, 2, 3})
            .setEmptyValue("empty");

    assertEquals("empty", dataFormat.getEmptyValue());
    assertEquals("empty", dataFormat.createAndConfigureWriterSettings().getEmptyValue());
  }
  @Test
  public void shouldConfigureNumberOfRecordsToRead() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat()
            .setFieldLengths(new int[] {1, 2, 3})
            .setNumberOfRecordsToRead(42);

    assertEquals(Integer.valueOf(42), dataFormat.getNumberOfRecordsToRead());
    assertEquals(42, dataFormat.createAndConfigureParserSettings().getNumberOfRecordsToRead());
  }
  @Test
  public void shouldConfigureHeaderExtractionEnabled() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat()
            .setFieldLengths(new int[] {1, 2, 3})
            .setHeaderExtractionEnabled(true);

    assertTrue(dataFormat.getHeaderExtractionEnabled());
    assertTrue(dataFormat.createAndConfigureParserSettings().isHeaderExtractionEnabled());
  }
  @Test
  public void shouldConfigureIgnoreLeadingWhitespaces() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat()
            .setFieldLengths(new int[] {1, 2, 3})
            .setIgnoreLeadingWhitespaces(true);

    assertTrue(dataFormat.getIgnoreLeadingWhitespaces());
    assertTrue(dataFormat.createAndConfigureWriterSettings().getIgnoreLeadingWhitespaces());
    assertTrue(dataFormat.createAndConfigureParserSettings().getIgnoreLeadingWhitespaces());
  }
  @Test(expected = IllegalArgumentException.class)
  public void shouldNotAllowHeadersWithSameName() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat()
            .setFieldLengths(new int[] {1, 2, 3})
            .setHeaders(new String[] {"A", "B", "A"});

    assertArrayEquals(new int[] {1, 2, 3}, dataFormat.getFieldLengths());
    assertArrayEquals(new String[] {"A", "B", "A"}, dataFormat.getHeaders());

    dataFormat.createAndConfigureWriterSettings();
  }
  @Test
  public void shouldConfigureFieldLengthWithHeadersAndLengths() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat()
            .setFieldLengths(new int[] {1, 2, 3})
            .setHeaders(new String[] {"A", "B", "C"});

    assertArrayEquals(new int[] {1, 2, 3}, dataFormat.getFieldLengths());
    assertArrayEquals(new String[] {"A", "B", "C"}, dataFormat.getHeaders());

    dataFormat.createAndConfigureWriterSettings();
  }
  @Test
  public void shouldConfigureNormalizedLineSeparator() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat()
            .setFieldLengths(new int[] {1, 2, 3})
            .setNormalizedLineSeparator('n');

    assertEquals(Character.valueOf('n'), dataFormat.getNormalizedLineSeparator());
    assertEquals(
        'n', dataFormat.createAndConfigureWriterSettings().getFormat().getNormalizedNewline());
    assertEquals(
        'n', dataFormat.createAndConfigureParserSettings().getFormat().getNormalizedNewline());
  }
  @Test
  public void shouldConfigureLineSeparator() {
    UniVocityFixedWidthDataFormat dataFormat =
        new UniVocityFixedWidthDataFormat()
            .setFieldLengths(new int[] {1, 2, 3})
            .setLineSeparator("ls");

    assertEquals("ls", dataFormat.getLineSeparator());
    assertEquals(
        "ls", dataFormat.createAndConfigureWriterSettings().getFormat().getLineSeparatorString());
    assertEquals(
        "ls", dataFormat.createAndConfigureParserSettings().getFormat().getLineSeparatorString());
  }
  @Test(expected = IllegalArgumentException.class)
  public void shouldNotAllowNoFieldLengths() {
    UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat();

    dataFormat.createAndConfigureWriterSettings();
  }